A traditional implementation of an absolute-difference function comprises a difference circuit followed by an absolute-value circuit; the entire circuit requires at least three op amps. The design problem is complicated in single-supply-only systems, which usually require an artificial ground, typically one-half of the supply. The circuit in Figure 1 takes the absolute value of the difference of two voltages using only two single-supply, ground-referenced op amps. The circuit is designed for dc or low-speed operation.

Figure 1. |
Using single-supply, ground-referenced op amps, this circuit accomplishesan absolute-difference function. |

For the case where V_{1} > V_{2}, IC_{1A} is disabled because diode D_{1} is off. IC_{1B} and its associated resistors form a classic difference circuit where

For the case where V_{2} > V_{1}, diode D_{1} conducts, producing the composite amplifier system made up of both IC_{1A} and IC_{1B}, where

Using these two equations, the overall function of the circuit for V_{1} and V_{2} greater than zero is as follows:

The circuit was built and tested with R_{1} = 0 Ω and R_{2} = 20 kΩ. For V_{2} > V_{1}, the composite amplifier system has poor phase margin and is unstable. Thus, the circuit compensates the loop with the dominant pole formed by R_{3} and C_{1}. At a gain of 22 and a desired response time of about 300 μsec (the 10 to 90% rise time when V_{2} becomes 0.1 V greater than V_{1}), values of R_{3} = 56 kΩ and C_{1} = 850 pF produced the best empirical results. R_{3} and C_{1} will vary, depending on the required speed of the response and the closed-loop gain.

Also, when V_{2} > V_{1}, the output of IC_{1A} becomes a function of the factor 2V_{2} – V_{1}. Thus, IC_{1A }may saturate for large values of V_{2}. The factor’s upper limit is as follows, where V_{SAT} is the saturation voltage for IC_{1A}:

For the LM2902 operating from 5 V, V_{SAT} is approximately 3.5 V. This last equation also implicitly sets a common-mode voltage (V_{CM}) limitation. You can see this limitation by setting V_{1} = V_{2} = V_{CM} and allowing the factor (2V_{2} – V_{1}) to reduce to V_{CM}.