TExcelTAD
Home › Analog Electronics: Diodes, Transistors & Op-Amps › Summing and Difference Amplifiers

Summing and Difference Amplifiers

Two everyday jobs: add a DC offset to a sensor signal so that it fits an ADC's input range, and measure the current into a load by the tiny voltage across a shunt resistor that sits a few volts above ground. The first needs an amplifier that adds voltages, the second one that subtracts them and ignores what they have in common. Both are the inverting amplifier of The Ideal Op-Amp with more resistors, and both are analysed with the same two golden rules. The difference amplifier adds a new idea: its accuracy depends on how well four resistors are matched, measured by the common-mode rejection ratio.

summing: vout = -Rf (v1/R1 + v2/R2 + v3/R3) difference: vout = (R2/R1)(v2 - v1) - + v1 R1 10k v2 R2 10k v3 R3 10k Rf 10 kOhm out - + v1 R1 10 kOhm R2 100 kOhm out v2 R3 10 kOhm R4 100 kOhm

The summing amplifier

The inverting input is a virtual ground, so each input drives its own current vk/Rkv_k/R_k into it, independently of the others. All of those currents leave through RfR_f:

vout=−Rf(v1R1+v2R2+v3R3)v_\text{out} = -R_f \left( \frac{v_1}{R_1} + \frac{v_2}{R_2} + \frac{v_3}{R_3} \right)

With equal resistors it is an inverting adder, vout=−(v1+v2+v3)v_\text{out} = -(v_1 + v_2 + v_3); with different resistors it is a weighted sum. Because the summing node is held at 0 V0\ \text{V}, the inputs do not interact: turning up one channel of an audio mixer does not change the level of another, which is exactly what a passive resistor network cannot do.

Two details matter in a real design. Each source sees an input resistance of RkR_k to ground. And the op-amp's noise gain is 1+Rf/(R1∥R2∥R3)1 + R_f/(R_1 \parallel R_2 \parallel R_3), larger than any single channel's gain, so a summer with many inputs has less bandwidth and amplifies the op-amp's offset more than its signal gains suggest (Real Op-Amps: DC Errors).

A DAC from a summer

Give the inputs binary weights, RR, 2R2R, 4R4R, 8R8R, and drive them from logic outputs that are either 00 or VrefV_\text{ref}: the output becomes proportional to the binary number. With Vref=5 VV_\text{ref} = 5\ \text{V}, R=10 kΩR = 10\ \text{k}\Omega and Rf=5 kΩR_f = 5\ \text{k}\Omega:

vout=−RfVrefR(b3+b22+b14+b08)=−2.5 V⋅N8v_\text{out} = -\frac{R_f V_\text{ref}}{R}\left(b_3 + \frac{b_2}{2} + \frac{b_1}{4} + \frac{b_0}{8}\right) = -2.5\ \text{V} \cdot \frac{N}{8}

so one LSB is 0.3125 V0.3125\ \text{V} and code 1111 gives −4.6875 V-4.6875\ \text{V}. Real DACs avoid the wide spread of resistor values (an 8-bit version would need a 128:1 ratio matched to better than 0.4 %) with the R-2R ladder, and are covered with the converters in the chip track.

The difference amplifier

Feed one signal into the inverting side and the other through a divider R3R_3, R4R_4 into the non-inverting side. By superposition (Linearity and Superposition):

vout=v2R4R3+R4(1+R2R1)−v1R2R1v_\text{out} = v_2 \frac{R_4}{R_3 + R_4}\left(1 + \frac{R_2}{R_1}\right) - v_1 \frac{R_2}{R_1}

If the ratios match, R4/R3=R2/R1=GR_4/R_3 = R_2/R_1 = G, the first term becomes Gv2G v_2 and

vout=G (v2−v1)v_\text{out} = G\,(v_2 - v_1)

Write the inputs as a differential part vd=v2−v1v_d = v_2 - v_1 and a common-mode part vcm=(v1+v2)/2v_{cm} = (v_1 + v_2)/2. An ideal difference amplifier has differential gain Ad=GA_d = G and common-mode gain Acm=0A_{cm} = 0. Their ratio is the common-mode rejection ratio, CMRR=∣Ad/Acm∣\text{CMRR} = \lvert A_d / A_{cm} \rvert, usually quoted in dB.

Matching sets the CMRR

With resistors of tolerance tt, the worst case (two resistors high, two low in the most unfavourable pattern) gives approximately

CMRRworst≈1+G4t\text{CMRR}_\text{worst} \approx \frac{1 + G}{4t}

For G=1G = 1 and 1 % resistors that is only 5050 (34 dB34\ \text{dB}); 0.1 % resistors give 54 dB54\ \text{dB}. That is why precision difference amplifiers come as one chip with laser-trimmed resistors on the same die, and why the instrumentation amplifier exists. The two inputs also see different resistances, R1R_1 and R3+R4R_3 + R_4, so a source resistance in series with either input upsets the ratio just like a resistor error: drive a difference amplifier from low-impedance sources.

Worked example: high-side current sense

Given: a load draws 1 A1\ \text{A} from a 5 V5\ \text{V} rail through a 0.1 Ω0.1\ \Omega shunt, so v2=5.000 Vv_2 = 5.000\ \text{V} (supply side), v1=4.900 Vv_1 = 4.900\ \text{V} (load side). A difference amplifier with R1=R3=10 kΩR_1 = R_3 = 10\ \text{k}\Omega, R2=R4=100 kΩR_2 = R_4 = 100\ \text{k}\Omega on ±12 V\pm 12\ \text{V}.

Find: the ideal output, the voltage at the op-amp inputs, and the worst-case error with 1 % and 0.1 % resistors.

Solve:

vout=10⋅(5.000−4.900) V=1.000 Vv+=v2R4R3+R4=5 V⋅100110=4.545 V=v−CMRR1 %≈110.04=275,Acm≈10275=0.036,Δvout≈0.036⋅4.95 V=0.18 VCMRR0.1 %≈2750,Δvout≈0.018 V\begin{aligned} v_\text{out} &= 10 \cdot (5.000 - 4.900)\ \text{V} = 1.000\ \text{V} \\ v_+ &= v_2 \frac{R_4}{R_3 + R_4} = 5\ \text{V} \cdot \frac{100}{110} = 4.545\ \text{V} = v_- \\ \text{CMRR}_{1\,\%} &\approx \frac{11}{0.04} = 275, \quad A_{cm} \approx \frac{10}{275} = 0.036, \quad \Delta v_\text{out} \approx 0.036 \cdot 4.95\ \text{V} = 0.18\ \text{V} \\ \text{CMRR}_{0.1\,\%} &\approx 2750, \quad \Delta v_\text{out} \approx 0.018\ \text{V} \end{aligned}

Check: the op-amp inputs sit at 4.5 V4.5\ \text{V}, inside the input range of an op-amp on ±12 V\pm 12\ \text{V}, but not of a 5 V5\ \text{V} single-supply part unless its input range reaches the rail. With 1 % resistors the reading can be off by up to about 17 % (the exact worst case, computed below, is 165 mV165\ \text{mV}): the 5 V5\ \text{V} common mode is fifty times the 0.1 V0.1\ \text{V} signal, and the mismatch lets a fraction of it through.

In Python: worst case and Monte Carlo

python · try it yourself
import itertools
import numpy as np

def vout(R1, R2, R3, R4, v1, v2):
    return v2 * R4 / (R3 + R4) * (1 + R2 / R1) - v1 * R2 / R1

nom = np.array([10e3, 100e3, 10e3, 100e3])
print(f"ideal: {vout(*nom, 4.9, 5.0):.4f} V")
for t in [0.01, 0.001]:
    worst = max(abs(vout(*(nom * (1 + t * np.array(s))), 4.9, 5.0) - 1.0)
                for s in itertools.product([-1, 1], repeat=4))
    rng = np.random.default_rng(1)
    R = nom * (1 + rng.uniform(-t, t, size=(20000, 4)))
    err = vout(R[:, 0], R[:, 1], R[:, 2], R[:, 3], 4.9, 5.0) - 1.0
    print(f"t = {t*100:.1f} %: worst {worst*1e3:6.1f} mV, "
          f"Monte Carlo 99th percentile {np.percentile(abs(err), 99)*1e3:6.1f} mV")
ideal: 1.0000 V
t = 1.0 %: worst  165.0 mV, Monte Carlo 99th percentile  114.4 mV
t = 0.1 %: worst   16.2 mV, Monte Carlo 99th percentile   11.4 mV

The exact worst case, 165 mV165\ \text{mV}, is a little below the estimate 0.18 V0.18\ \text{V}: that is the common-mode feedthrough alone (pure 4.95 V4.95\ \text{V} common mode gives 183 mV183\ \text{mV} worst case), and in the same resistor pattern the change of the differential term partly offsets it. It is rare, but one build in a hundred is still off by more than 110 mV110\ \text{mV}. Notice that the error is almost all common-mode feedthrough, not gain error.

Cross-check with SPICE: one resistor off by 1 %

The deck builds two copies of the current-sense amplifier with the op-amp macro-model written for this course, one with matched resistors and one with R4=99 kΩR_4 = 99\ \text{k}\Omega, and drives both inputs with the shunt voltages, then with 5 V5\ \text{V} on both inputs (pure common mode).

bash · try it yourself
cat > diff.cir <<'EOF'
* difference amplifier, G = 10: matched and R4 1 % low
.subckt OA inp inn out
G1 0 n1 inp inn 1m
R1 n1 0 100meg
C1 n1 0 159.2p
E1 out 0 n1 0 1
.ends
V2 a 0 5.0
V1 b 0 4.9
* matched
R1 b n1 10k
R2 n1 o1 100k
R3 a p1 10k
R4 p1 0 100k
X1 p1 n1 o1 OA
* R4 one percent low
R1b b n2 10k
R2b n2 o2 100k
R3b a p2 10k
R4b p2 0 99k
X2 p2 n2 o2 OA
.control
op
print v(o1) v(o2)
alter V1 dc=5.0
op
print v(o1) v(o2)
.endc
.end
EOF
ngspice -b diff.cir 2>&1 | grep -E '^v\('
v(o1) = 9.998900e-01
v(o2) = 9.540235e-01
v(o1) = 0.000000e+00
v(o2) = -4.58665e-02

One resistor 1 % low changes the 1 V reading by about 46 mV46\ \text{mV}, and 5 V5\ \text{V} of pure common mode produces about −46 mV-46\ \text{mV}: a CMRR of 10/0.0092≈109010/0.0092 \approx 1090, or 61 dB61\ \text{dB} for this particular error.

Interactive: a 4-bit summing DAC

The op-amp is the controlled source E1 out 0 0 n 1meg (gain 10610^6, no rails), since ee-netlist has no op-amp element. Each slider is one bit: 00 or 5 V5\ \text{V}. The weights 1010, 2020, 4040, 80 kΩ80\ \text{k}\Omega are the resistors.

node voltages (to ground 0)b35.000 Vb20 Vb15.000 Vb05.000 Vn3.437 uVout-3.437 VnetlistV3 b3 0 5V2 b2 0 0V1 b1 0 5V0 b0 0 5R3 b3 n 10kR2 b2 n 20kR1 b1 n 40kR0 b0 n 80kRf n out 5kE1 out 0 0 n 1megelement currents (node 1 to node 2 through it)V3b3>0-500 uAV2b2>0172 pAV1b1>0-125 uAV0b0>0-62.5 uAR3b3>n500 uAR2b2>n-172 pAR1b1>n125 uAR0b0>n62.5 uARfn>out687 uAE1out>0687 uA

At the default code 1011 (eleven) the lab shows V(out)=−3.437 VV(\text{out}) = -3.437\ \text{V}, which is −11×0.3125 V-11 \times 0.3125\ \text{V}, and I(Rf)=687.5 μAI(R_f) = 687.5\ \mu\text{A}, the sum of the four bit currents.

Guided lab: offset adder and CMRR measurement

Hand calculation. (a) A summer with R1=R2=Rf=10 kΩR_1 = R_2 = R_f = 10\ \text{k}\Omega adds a 1 V1\ \text{V} peak sine and a −1.5 V-1.5\ \text{V} DC level: the output is an inverted sine centred on +1.5 V+1.5\ \text{V}, from 0.50.5 to 2.5 V2.5\ \text{V}. (b) A difference amplifier with G=1G = 1 (four 10 kΩ10\ \text{k}\Omega, 1 %) and both inputs tied to a 2 V2\ \text{V} peak sine: worst case CMRR=2/0.04=50\text{CMRR} = 2/0.04 = 50, so ∣vout∣≤2 V/50=40 mV\lvert v_\text{out} \rvert \le 2\ \text{V}/50 = 40\ \text{mV} peak.

Simulation. The Python Monte Carlo and the SPICE deck above; change the resistor values in the deck to your measured ones.

What you would measure. Build both on a breadboard with a general-purpose op-amp on a ±12 V\pm 12\ \text{V} current-limited split supply (about 50 mA50\ \text{mA} limit) with 100 nF100\ \text{nF} decoupling at the pins. Make the −1.5 V-1.5\ \text{V} from a 10 kΩ10\ \text{k}\Omega potentiometer between the rails, buffered or not (its source resistance adds to R2R_2; measure it). For (a) expect the output centred within about ±50 mV\pm 50\ \text{mV} of 1.5 V1.5\ \text{V}. For (b) the output is a small sine, typically a few to 40 mV40\ \text{mV} peak with random 1 % resistors: measure it with the scope at high sensitivity and compute CMRR=20log⁡10(G⋅vcm/vout)\text{CMRR} = 20 \log_{10}(G \cdot v_{cm} / v_\text{out}). Then measure the four resistors with a DMM (resolution 1 Ω1\ \Omega on 10 kΩ10\ \text{k}\Omega, i.e. 0.01 %), predict the CMRR from the formula and compare. Swap two resistors to see the CMRR improve or worsen.

Hazards and safe setup. Low voltage only, current-limited supply, inputs kept within the supply rails. When sensing a real load current, the shunt and its wiring must be rated for the current: a 0.1 Ω0.1\ \Omega shunt at 1 A1\ \text{A} dissipates 0.1 W0.1\ \text{W}, but at 5 A5\ \text{A} it is 2.5 W2.5\ \text{W} and gets hot.

Pitfalls

  • Driving the difference amplifier from a source resistance. 1 kΩ1\ \text{k}\Omega of source resistance in series with R1=10 kΩR_1 = 10\ \text{k}\Omega is a 10 % ratio error.
  • Assuming the inputs are at ground. In a difference amplifier the op-amp inputs sit at v2R4/(R3+R4)v_2 R_4/(R_3 + R_4), which must be inside the op-amp's input common-mode range.
  • Forgetting the noise gain of a summer. Ten inputs of gain 1 give a noise gain of 11.
  • Expecting precise subtraction from 5 % or 1 % resistors. Matching, not absolute accuracy, sets the CMRR.

Practice

  1. Design a summer that outputs −(2v1+0.5v2)-(2v_1 + 0.5 v_2) with Rf=20 kΩR_f = 20\ \text{k}\Omega.
  2. A difference amplifier with G=1G = 1 uses 0.1 % resistors. What is the worst-case CMRR in dB?
  3. With matched resistors (G=10G = 10), what is voutv_\text{out} for v2=2.05 Vv_2 = 2.05\ \text{V}, v1=2.00 Vv_1 = 2.00\ \text{V}?
Answer
  1. R1=Rf/2=10 kΩR_1 = R_f/2 = 10\ \text{k}\Omega, R2=Rf/0.5=40 kΩR_2 = R_f/0.5 = 40\ \text{k}\Omega (E24: 39 kΩ+1 kΩ39\ \text{k}\Omega + 1\ \text{k}\Omega).
  2. (1+1)/(4⋅0.001)=500(1 + 1)/(4 \cdot 0.001) = 500, 20log⁡10500=54 dB20\log_{10} 500 = 54\ \text{dB}.
  3. 10⋅0.05 V=0.50 V10 \cdot 0.05\ \text{V} = 0.50\ \text{V}; the 2 V2\ \text{V} common mode is rejected.

Test yourself

A summer has R1=R2=10 kΩR_1 = R_2 = 10\ \text{k}\Omega and Rf=20 kΩR_f = 20\ \text{k}\Omega, with v1=0.3 Vv_1 = 0.3\ \text{V} and v2=−0.1 Vv_2 = -0.1\ \text{V}. The output is…

  1. +0.4 V+0.4\ \text{V}
  2. −0.4 V-0.4\ \text{V}
  3. −0.8 V-0.8\ \text{V}
  4. +0.8 V+0.8\ \text{V}

Why do the inputs of an inverting summer not interact?

  1. Each input has its own op-amp
  2. The summing node is a virtual ground, so each input current depends only on its own voltage
  3. The resistors are matched
  4. The feedback is positive

The CMRR of a four-resistor difference amplifier is mainly limited by…

  1. the op-amp's slew rate
  2. the matching of the resistor ratios R2/R1R_2/R_1 and R4/R3R_4/R_3
  3. the supply voltage
  4. the absolute value of R1R_1

In the high-side current-sense example (G=10G = 10, v2=5 Vv_2 = 5\ \text{V}), the op-amp's inputs sit at about…

  1. 0 V0\ \text{V}
  2. 0.45 V0.45\ \text{V}
  3. 4.5 V4.5\ \text{V}
  4. 5 V5\ \text{V}