Sub topic 7
Weighted sums and a binary-weighted DAC
The previous chapter derived the inverting summing amplifier with equal resistors. This chapter gives each input its own gain by choosing its resistor. A set of resistors in powers of two then gives a small digital-to-analog converter (DAC). You should be comfortable with the virtual ground at the inverting input and with Ohm's law for each input branch.
From equal sums to weighted sums
Take an inverting summer with inputs V1 … Vn through resistors R1 … Rn, and feedback resistor Rf. The inverting node is held at 0 V by feedback (the virtual ground), so each input branch carries a current set only by its own source and resistor:
- Branch current ik = Vk / R_k.
- The ideal op amp draws no input current, so all branch currents flow through Rf.
- The output is Vout = 0 − Rf × (i1 + … + in).
That gives the general result:
Vout = -Rf × (V1/R1 + V2/R2 + … + Vn/Rn)
= -(Rf/R1)·V1 - (Rf/R2)·V2 - … - (Rf/Rn)·VnEach input has its own gain, weight wk = Rf / Rk. A smaller Rk gives a larger weight. Weights are set independently, and you can change one without disturbing the others. This independence comes from the virtual ground. Every source sees a fixed load Rk to 0 V, no matter what the other sources do. A passive resistor network that sums voltages at a floating node has no such isolation, because each source loads the others.
Choosing resistors for target weights
- Pick Rf so the largest weight is what you want and the smallest input resistor is a sensible load for its source (often 1 kΩ to 100 kΩ).
- Compute Rk = Rf / wk for each input.
- Check the worst-case output against the op amp's swing limits.
A mixer example: weights of 1, 0.5 and 0.25 with Rf = 10 kΩ need R1 = 10 kΩ, R2 = 20 kΩ and R3 = 40 kΩ. With inputs of 1 V, 2 V and 4 V, the output is −(1 + 1 + 1) = −3 V.
Practical points
- Sign. Every weight is negative. For a positive result, follow the summer with a unity-gain inverting stage, or arrange the input signs so the result is already what you need.
- Input resistance. Channel k presents Rk to its source. A very small Rk can overload a weak source.
- Swing. The ideal sum can exceed the supply rails. The output then saturates and the formula no longer holds. Scale Rf or the weights to keep the largest expected sum inside the output range.
- Noise and offset. The op amp's input offset voltage is amplified by the noise gain 1 + Rf × Σ(1/R_k), not by the signal weights. Many inputs or small input resistors raise that gain.
A binary-weighted DAC
A DAC turns a binary code into a voltage. A weighted summer does this directly. Each bit switches its resistor between 0 V (bit = 0) and a reference voltage Vref (bit = 1). The bit's weight must be a power of two, so the resistors double from one bit to the next.
For a 4-bit DAC with bits b3 (MSB) to b0 (LSB), use these resistors:
| Bit | Resistor | Weight Rf/R_k with Rf = R/2 |
|---|---|---|
| b3 (MSB) | R | 1/2 |
| b2 | 2R | 1/4 |
| b1 | 4R | 1/8 |
| b0 (LSB) | 8R | 1/16 |
With Rf = R/2, the output is:
Vout = -Vref × (b3/2 + b2/4 + b1/8 + b0/16)
= -Vref × N / 16N is the integer value of the code, 8·b3 + 4·b2 + 2·b1 + b0. The output is proportional to the code, and one step (1 LSB) equals Vref / 16.
If you pick Rf = R instead, every weight doubles and the result is −Vref × N / 8. The full-scale value then reaches 15/8 of Vref. Choose Rf to set the full-scale output you want.
Worked numbers
Take R = 10 kΩ, so the resistors are 10 kΩ, 20 kΩ, 40 kΩ and 80 kΩ, and Rf = 5 kΩ. Let Vref = 5 V. One LSB is 5 / 16 = 0.3125 V. For code 1010 (N = 10), bits b3 and b1 are high:
- Current from b3: 5 V / 10 kΩ = 0.5 mA.
- Current from b1: 5 V / 40 kΩ = 0.125 mA.
- Total: 0.625 mA, and Vout = −5 kΩ × 0.625 mA = −3.125 V.
This equals −5 × 10 / 16, as the formula predicts.
Checking it numerically
The script below computes the output for every code.
VREF = 5.0
R = 10e3
RF = R / 2
RESISTORS = [R, 2 * R, 4 * R, 8 * R] # MSB first
def dac_output(code, vref=VREF, rs=RESISTORS, rf=RF):
"""Ideal binary-weighted DAC: Vout = -Rf * sum(bit * Vref / R_bit)."""
bits = [(code >> (3 - i)) & 1 for i in range(4)]
return -rf * sum(b * vref / r for b, r in zip(bits, rs))
for code in range(16):
print(f"{code:2d} {code:04b} {dac_output(code):8.4f} V")The output steps from 0 V at code 0 down to −4.6875 V at code 15 in 0.3125 V steps.
A SPICE operating-point check of code 1010 uses the same op amp model as the earlier summer, a high-gain voltage-controlled voltage source:
* 4-bit binary-weighted DAC, code 1010, ideal op amp as a high-gain VCVS
Vb3 b3 0 DC 5
Vb2 b2 0 DC 0
Vb1 b1 0 DC 5
Vb0 b0 0 DC 0
R3 b3 inv 10k
R2 b2 inv 20k
R1 b1 inv 40k
R0 b0 inv 80k
Rf inv out 5k
E1 out 0 0 inv 100k
.op
.endV(out) should read very close to −3.125 V. It differs slightly because the model's gain is finite.
How accurate must the resistors be?
The MSB carries the largest share of the output, so an error in its resistor matters most. Suppose the MSB resistor is 5% high (10.5 kΩ). Code 8 (1000) then gives −5 kΩ × 5 V / 10.5 kΩ = −2.381 V instead of −2.5 V. The error is 0.119 V, or 0.38 LSB.
A useful rule: for an n-bit DAC, the MSB resistor must be within about 1/2^n of its value for the error to stay under half an LSB. That is a limit on that resistor alone, and the errors of the other resistors and of Vref add to it.
| Bits | MSB resistor tolerance for under ½ LSB (alone) | Largest/smallest resistor ratio |
|---|---|---|
| 4 | about 6.25% | 8:1 |
| 8 | about 0.39% | 128:1 |
| 12 | about 0.024% | 2048:1 |
This table explains why the binary-weighted summer is practical for only a few bits. The tolerance gets tighter and the resistor spread grows. At 12 bits you would need a 2048:1 range of values, matched to 0.02%. Real converters use an R-2R ladder, which needs only two resistor values, or other structures that keep the ratios manageable. The summing idea is the same.
Other error sources add to the resistor errors:
- Reference accuracy. Vref scales every code, so its error is a gain error on the whole output.
- Switch resistance. A real switch adds series resistance to the bit's branch and shifts that bit's weight. The effect is largest on the MSB, whose resistor is smallest.
- Op amp offset. Offset appears at the output multiplied by the noise gain, which for this circuit is 1 + Rf × Σ(1/R_k) = 1 + 0.5 × (1 + 0.5 + 0.25 + 0.125) = 1.9375.
Common mistakes
- Using Rk = Rf × wk instead of Rf / w_k. A larger weight needs a smaller resistor.
- Forgetting the minus sign, which flips every code's polarity.
- Letting the full-scale sum exceed the output swing, which clips the top codes.
- Ordering the resistors backward so the MSB gets the largest resistor.
Exercise
A summing amplifier has Rf = 20 kΩ, input V1 = 0.5 V through R1 = 10 kΩ, and input V2 = 1.5 V through R2 = 30 kΩ. What is Vout, and what are the two weights?
Show answer
The weights are Rf/R1 = 2 and Rf/R2 = 20k/30k = 2/3. Vout = -(2 × 0.5 + (2/3) × 1.5) = -(1 + 1) = -2 V.
Exercise
A 3-bit binary-weighted DAC uses Vref = 4 V, resistors of 10 kΩ (MSB), 20 kΩ and 40 kΩ (LSB), and Rf = 5 kΩ. What is Vout for code 101, and what is the size of 1 LSB?
Show answer
The weights are 5k/10k = 1/2, 5k/20k = 1/4 and 5k/40k = 1/8, so Vout = -Vref × N / 8. Code 101 is N = 5, so Vout = -4 × 5 / 8 = -2.5 V. One LSB is Vref / 8 = 0.5 V.