# Comparator - get the difference between inputs?

Is there any way to have a comparator (say LM339) output the difference between its +V and -V ?? For example, if +V is 6.3 volts and -V is 5 volts, how to get a 1.3 volts signal? Put another way, I guess it could be how to substract the -V from the +V voltage.. This is probably simple, any ideas?

• Not with a 339 - output is an open collector. Jun 6, 2013 at 6:45

A difference amplifier will do what you want, but it has a potentially serious problem. The input impedances are not well defined, or matched. Referencing Jay's circuit, the input impedance of the noninverting side is $R_1+R_f$. That is as close to a defined input impedance as we get with this topology. Since there is negative feedback, the inverting pin will track the noninverting pin. What would normally be a virtual ground is now varying based on $V_+$, and with it the input impedance of the inverting side.

If this issue is a problem for your application, a better option would be an instrumentation amplifier.

$V_{out}=(1+\dfrac{2R_1}{R_{gain}})(\dfrac{R_3}{R_2})(V_2-V_1)$

The inputs are buffered and have matched input impedances, equal to the op amp input impedance. You can either build one yourself, or buy an IC. An IC solution will ultimately have better performance, especially in common mode rejection.

• An excellent point. I overlooked the virtual grounding issue in exchange for a simpler implementation. Instrumentation amplifiers are definitely the better pick for a circuit where input impedance is critical. Jun 6, 2013 at 5:57
• You guys are impressive! The +V is the output from a lm358 opamp, in my application. The reference voltage is from a voltage divider. Jun 6, 2013 at 6:16
• I have used an Analog Componets AD627 Instrumentation amplifier for this type of application Jun 6, 2013 at 6:21

Comparators won't do quite what you want, but take a look at a differential amplifier. It's a circuit that amplifies a difference between two signals. If you just want the raw difference, you can set up for unity gain, which will not "scale" the signals. You'll still have to cleverly pick your resistors for a common-mode gain term that won't greatly impact your overall result, but that's not terribly hard. Take circuit for example; as long as $\frac{Rf}{Ri}$ is close to 1, the raw difference between the two signals will be accurately represented.

There also the technique using a switched capacitor: -

In this example it's measuring the differential voltage across a strain gauge bridge and making it single ended for the ADC.

In principle, if you didn't need fast measurements you could use a relay to apply the cap to the source and you'd get really good isolation AND the ability to measure voltages that are far-removed from earth, limited by the contact voltage rating of the relay.