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.
The summing amplifier
The inverting input is a virtual ground, so each input drives its own current into it, independently of the others. All of those currents leave through :
With equal resistors it is an inverting adder, ; with different resistors it is a weighted sum. Because the summing node is held at , 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 to ground. And the op-amp's noise gain is , 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, , , , , and drive them from logic outputs that are either or : the output becomes proportional to the binary number. With , and :
so one LSB is and code 1111 gives . 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 , into the non-inverting side. By superposition (Linearity and Superposition):
If the ratios match, , the first term becomes and
Write the inputs as a differential part and a common-mode part . An ideal difference amplifier has differential gain and common-mode gain . Their ratio is the common-mode rejection ratio, , usually quoted in dB.
Matching sets the CMRR
With resistors of tolerance , the worst case (two resistors high, two low in the most unfavourable pattern) gives approximately
For and 1 % resistors that is only (); 0.1 % resistors give . 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, and , 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 from a rail through a shunt, so (supply side), (load side). A difference amplifier with , on .
Find: the ideal output, the voltage at the op-amp inputs, and the worst-case error with 1 % and 0.1 % resistors.
Solve:
Check: the op-amp inputs sit at , inside the input range of an op-amp on , but not of a 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 ): the common mode is fifty times the signal, and the mismatch lets a fraction of it through.
In Python: worst case and Monte Carlo
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, , is a little below the estimate : that is the common-mode feedthrough alone (pure common mode gives 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 . 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 , and drives both inputs with the shunt voltages, then with on both inputs (pure common mode).
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 , and of pure common mode produces about : a CMRR of , or for this particular error.
Interactive: a 4-bit summing DAC
The op-amp is the controlled source E1 out 0 0 n 1meg (gain , no rails), since ee-netlist has no op-amp element. Each slider is one bit: or . The weights , , , are the resistors.
At the default code 1011 (eleven) the lab shows , which is , and , the sum of the four bit currents.
Guided lab: offset adder and CMRR measurement
Hand calculation. (a) A summer with adds a peak sine and a DC level: the output is an inverted sine centred on , from to . (b) A difference amplifier with (four , 1 %) and both inputs tied to a peak sine: worst case , so 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 current-limited split supply (about limit) with decoupling at the pins. Make the from a potentiometer between the rails, buffered or not (its source resistance adds to ; measure it). For (a) expect the output centred within about of . For (b) the output is a small sine, typically a few to peak with random 1 % resistors: measure it with the scope at high sensitivity and compute . Then measure the four resistors with a DMM (resolution on , 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 shunt at dissipates , but at it is and gets hot.
Pitfalls
- Driving the difference amplifier from a source resistance. of source resistance in series with is a 10 % ratio error.
- Assuming the inputs are at ground. In a difference amplifier the op-amp inputs sit at , 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
- Design a summer that outputs with .
- A difference amplifier with uses 0.1 % resistors. What is the worst-case CMRR in dB?
- With matched resistors (), what is for , ?
Answer
- , (E24: ).
- , .
- ; the common mode is rejected.
Test yourself
A summer has and , with and . The output is…
Why do the inputs of an inverting summer not interact?
- Each input has its own op-amp
- The summing node is a virtual ground, so each input current depends only on its own voltage
- The resistors are matched
- The feedback is positive
The CMRR of a four-resistor difference amplifier is mainly limited by…
- the op-amp's slew rate
- the matching of the resistor ratios and
- the supply voltage
- the absolute value of
In the high-side current-sense example (, ), the op-amp's inputs sit at about…