analog to digital signal/The comparator/03. Two inputs, one answer
The comparator · 03 of 11

Two inputs, one answer

A comparator takes two voltages and says which is higher, in about a microsecond, to within a few millivolts. On the TK29 one voltage is the block in IN and the other is the knob. The answer is one bit, and it throws away how far apart the two were.

Higher or lower

Two inputs, one answer
Input, from the IN block0.90 V
Knob, the threshold1.20 V
Input
0.90 V
Knob
1.20 V
DIG
LOW
The input, 0.90 V, is lower than the knob's 1.20 V, so the comparator holds DIG LOW. It says nothing about how much lower. For that, read ANA.

A comparator has a plus input and a minus input. When plus is higher than minus, its output is HIGH; when minus is higher, LOW. With the slide switch at H, the block's voltage is on plus and the knob's on minus, so DIG is HIGH while the input is above the knob. Drag either slider past the other and the answer flips.

That is all it does. It does not say by how much. An input 10 mV above the knob and one 1.5 V above it give the same HIGH, and that is the trade: software never has to decide, and never gets to know.

How sure, and how fast

ON's datasheet for the LM393 gives an input offset of 1 mV typical and 5 mV at most. That is the chip's own error: within 5 mV of the knob, the answer could go either way. For a threshold you set by eye with a screwdriver, it is far smaller than anything you will notice.

It answers in about 1.3 µs, typical, for a small change. That is fast enough to follow anything a sensor block does, and fast enough to follow its noise as well, which is what makes DIG flicker when the input sits right at the threshold. Chatter and hysteresis is about that.

The inputs draw almost nothing: 25 nA, typical, flowing out of each input. The block's voltage is not loaded by being compared, and it arrives on ANA exactly as the comparator sees it.

What the knob is

The knob is a 10 kΩ trimmer with one end on VCC and the other on GND. Its middle leg slides between them, so it gives any voltage from 0 V to VCC: a voltage divider you turn with a screwdriver.

Because it divides VCC, the threshold is a share of VCC, not a fixed voltage. Halfway round is about 1.65 V from 3V3 and about 2.5 V from 5V. And it only works in the lower part of its travel, which the input range explains.

When it does not work

DIG changes, but not where I expected on the knob.

The knob sets a voltage, not a position on the sensor's scale. The same turn gives a different threshold from 3V3 and from 5V, and a sensor's voltage for the same light or sound differs from part to part. Set it by putting the sensor where you want it to switch and turning until the LED changes.

The input and the knob look equal and DIG keeps changing.

Within about 5 mV of each other, the LM393's own offset decides, and any noise on the input decides it again a moment later. The comparator answers in about a microsecond, so it follows every wobble. That is chatter, and it has its own article.

Does reading ANA disturb the comparison?

No. The comparator's inputs draw tens of nanoamps, and an analog pin being read draws very little more. Both see the same voltage from the block.

Where this goes next

The switch that decides which way round the answer comes out.

H and L

Edit this page — content/books/analog-to-digital-signal/two-inputs-one-answer.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Analog to Digital Signal

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum