# how to convert the difference in voltages into a digital signal

How can I convert the differences between two voltages into a digital signal? ie. if sensor 1 V > sensor 2 V there is a digital one, but if sensor 2 V >= Sensor 1 V, there is a digital 0. I understand that there are methods of converting a single analog signal into a digital signal, but my understanding of a digital signal is that it must always be either high or low. if you convert both into a digital signal, then wouldn't it be impossible to compare them. Or rather, so long as eithers analog voltage is always greater than zero, then wouldn't a converter always convert the voltages to digital 1s?

The classic method of comparing two analog signals is to use an analog comparator. simulate this circuit – Schematic created using CircuitLab

This is an op-amp like device that produces a high on the output if the Plus pin is at a higher voltage than the voltage on the Minus pin. (Some, like an LM339, require a pull-up on the output to attain the required logic high level.)

However, there is an issue with comparators in that >= requirement. Comparators have a minimum offset error between the two pins so = is a bit of a relative term that can be problematic if the signals you are comparing are frequently at or near the same voltage. Even if the offset can be tuned out, if the signals are equal, the output is undefined, or can actually oscillate.

For such conditions is it more prudent to digitize the signals into a digital byte or word using an analog to digital convertor and compare those values mathematically. However, in that instance you have to remember there is a minimum step size in the digitization, so again "equals" is really a relative number ( = +- Half a step).

More often, the requirement is "I want a HIGH if Signal A goes higher than signal B, but I don't want it to go LOW again till signal A goes lower than say .1V Below signal B." This is called hysteresis and can easily be created by adding positive hysteresis feedback to the op-amp circuit.

For very small signals it gets more difficult. In order to provide reasonable accuracy some amplification of the original signals is sometimes warranted to give you a signal scale that is sufficiently high to reduce the effects of the inherent errors and offsets in the system. In some situations it is better to subtract the signals in an analog circuit before amplification to ensure both signals are treated equally.

An analog comparator will compare two analog voltages, A and B, and give a digital output - a "1" if A is greater than B, or a "0" if B is greater than A.

If you are just looking for a single bit representing if one signal is higher or lower than another, you would probably be best off using a comparator.

But you can also convert both analog signals into digital values, and then compare them mathematically, i.e. check if one value is greater or less than the other. That can be done with discrete logic, but typically it would be done with a microcontroller. So for example, a small simple MCU can take both voltages into to ADC pins, and convert and compare them in firmware.

No, if the voltage is greater than zero, it doesn't necessarily imply a digital 1 output. It will depend on the reference voltages for the converter, number of bits, etc.