---
title: "Project: a linear power supply"
heading: From the wall transformer to a steady 5 volts
eyebrow: C5 · Lesson 55 · Project
xp: 80
---

::: hook
A bench supply for a small circuit takes 60 Hz AC from a transformer, rectifies it, smooths it, and then regulates it so the output stays put as the load and the line voltage change. Every block is something you've built in this course: the bridge and reservoir capacitor of lesson 8, the Zener reference of lesson 11, and an emitter follower (lesson 43) to supply the current the Zener can't. In this project you'll design one for 5 V at half an amp, simulate its ripple in Python, and set its Zener bias by simulating the real circuit.
:::

::: play
- The whole supply: a bridge from a 10.4 V peak source, a 2200 µF reservoir, and a Zener-referenced emitter follower feeding a 10 Ω load (about half an amp).
- The upper trace is the raw rectified voltage, rippling by about 1.5 V. The lower trace is the regulated output, nearly flat.
- Shrink the reservoir capacitor until the valleys of the raw voltage dip toward the output: the regulator runs out of headroom and the ripple comes through.
:::
:::

```sim circuit
V1 a b sine 10.4 V 60 Hz        @ 0,0 down 2
D1 a raw                        @ 1,0 up 2
D3 0 a                          @ 1,4 up 4
D2 b raw                        @ 3,2 up 4
D4 0 b                          @ 3,4 up 2
C1 raw 0 2200u                  @ 5,-2 down 6
RS raw z 93                     @ 5,-2 right 2
DZ 0 z BV=5.6                   @ 7,4 up 6
Q1 raw z out npn BF=50 IS=1e-13 @ 8,-2
RL out 0 10                     @ 9,-1 down 5
slider: C1 470u..10m log
slider: RL 10..1k log
scope: v(raw), v(out)
time: 0..100m s
meter: v(out), i(RL)
```

::: predict
## The regulator's output is about 4.9 V and its transistor needs at least 2 V across it. The raw voltage peaks at 9 V. How much ripple can the reservoir be allowed?

- [ ] None: any ripple reaches the output
- [x] About 2 V: the valleys must stay above 6.9 V
- [ ] About 4.5 V: half the peak
- [ ] As much as you like: the Zener absorbs it

::: reveal
About 2 V. The regulator removes ripple only while it has headroom: the raw voltage, even at the bottom of each valley, must stay at least 2 V above the output. Below that the pass transistor saturates and the ripple passes straight through.
:::
:::

::: nameit
## The design, block by block

For an output $V_o$ at up to $I_L$, with a pass transistor of minimum β, from a supply at frequency f:

1. **Reference:** the follower's output sits a $V_{BE}$ below its base, so $V_Z \approx V_o + 0.7$ V.
2. **Headroom:** the raw voltage's **valley** must stay at least $V_{CE,\text{min}}$ (about 2 V) above $V_o$: valley $= V_o + V_{CE,\text{min}}$.
3. **Reservoir:** choose the ripple $V_r$; the raw **peak** is valley + $V_r$, and $C = \frac{I_L}{2fV_r}$ (lesson 8).
4. **Transformer:** the secondary's peak is the raw peak plus two diode drops, so $V_\text{rms} = \frac{V_\text{peak} + 1.4}{\sqrt2}$, plus margin for low line voltage.
5. **Zener bias:** at the valley, $R_S$ must still deliver the most base current, $I_L/\beta_\text{min}$, plus the Zener's minimum current: $R_S = \frac{V_\text{valley} - V_Z}{I_L/\beta + I_{Z,\text{min}}}$.
6. **Heat:** the pass transistor drops the average raw voltage minus the output: $P = \left(V_\text{peak} - \frac{V_r}{2} - V_o\right)I_L$, often watts, so it goes on a heat sink (lesson 34).

## Ripple, simulated

With ideal diodes and a regulator drawing a steady $I_L$, the reservoir voltage follows the rectified input $|V_s\sin\omega t| - 1.4$ when that's higher, and otherwise falls at $I_L/C$. In code, one line per time step does both:

$$V \leftarrow \max\left(V - \frac{I_L\,\Delta t}{C},\ |V_s\sin\omega t| - 1.4\right)$$

Run it for a few cycles and read the minimum and maximum of the last one.

## What the regulator buys

Between the reservoir and the load, ripple and load changes appear across the Zener divided by roughly $\frac{r_z}{R_S + r_z}$, with $r_z$ the Zener's small-signal resistance, and the follower adds its low output resistance. Integrated regulators replace the Zener with a bandgap reference and the follower with an error amplifier, and reject ripple a thousand times better; C6 builds one.
:::

::: example
## Design the supply for 5 V at 0.5 A with β ≥ 50, 60 Hz, 2 V of ripple and 2 V of headroom.

::: solution
1. **Zener voltage.** $V_Z$ = 5.7 V (a 5.6 V part gives 4.9 V).
2. **Raw supply levels.** Valley 7 V, peak 9 V.
3. **Capacitor.**
   $$\begin{aligned} C &= \frac{0.5}{120 \times 2} \\ &= 2083\ \mu\text{F} \end{aligned}$$
   Use 2200 µF.
4. **Transformer.** The secondary needs
   $$\frac{10.4}{\sqrt2} = 7.35\ \text{V RMS}$$
   so use an 8 V transformer.
5. **Zener resistor.**
   $$\begin{aligned} R_S &= \frac{7 - 5.7}{10\ \text{mA} + 5\ \text{mA}} \\ &= 87\ \Omega \end{aligned}$$
6. **Pass transistor.** It dissipates
   $$(8 - 5) \times 0.5 = 1.5\ \text{W}$$

**Answer:** a 5.7 V Zener fed through 87 Ω, 2200 µF, an 8 V RMS transformer, and a pass transistor that dissipates 1.5 W.
:::
:::

::: example
## With 2200 µF from a 12 V peak source at 0.5 A, how low does the raw voltage dip?

::: solution
1. **Estimate.**
   $$\begin{aligned} V_\text{min} &= 12 - 1.4 - \frac{0.5}{120 \times 2200\ \mu\text{F}} \\ &= 8.71\ \text{V} \end{aligned}$$
2. **Simulation.** Simulated, it bottoms at 9.03 V.
3. **Why it's higher.** The input catches the capacitor well before the next peak, so less charge is lost than the estimate assumes.

**Answer:** it dips to about 9.03 V, a little above the estimate of 8.71 V.
:::
:::

::: check
given: Vo = 3.3 | 5 | 12; head = 1.5 | 2.5; Vr = 1 | 2
answer: Vo + head + Vr
unit: V
tolerance: 0.5%

## A {Vo} V linear supply needs {head} V of headroom and allows {Vr} V of ripple. What raw peak voltage must it have?

::: right
Right. Valley $V_o + V_{CE,\text{min}}$, plus the ripple: {answer}.
:::

::: misses
- [Vo + head] That's the valley; the peak is a ripple higher.
- [any] Not yet. Start from the output and work up.
:::
:::

::: check
given: Vp = 9 | 16; Vr = 1 | 2
answer: (Vp + 1.4)/sqrt(2)
unit: V
tolerance: 0.5%

## A bridge supply's raw peak is {Vp} V. What RMS secondary voltage does its transformer need, before margin?

::: right
Right. $\frac{V_p + 1.4}{\sqrt2}$ = {answer}.
:::

::: misses
- [Vp/sqrt(2)] Add the two diode drops first.
- [any] Not yet. Peak plus two drops, over √2.
:::
:::

::: check
given: valley = 7 | 9; VZ = 5.6 | 6.2; IL = 0.3 | 1; beta = 30 | 80; IZ = 2 | 5
answer: (valley - VZ)/(IL/beta + IZ/1000)
unit: Ω
tolerance: 0.5%

## A Zener-follower regulator ($V_Z$ = {VZ} V) must deliver {IL} A with β ≥ {beta}, keeping {IZ} mA in the Zener when the raw voltage dips to {valley} V. What $R_S$?

::: right
Right. $\frac{V_\text{valley} - V_Z}{I_L/\beta + I_{Z,\text{min}}}$ = {answer}.
:::

::: misses
- [(valley - VZ)/(IZ/1000)] The base current comes through $R_S$ too.
- [any] Not yet. $R_S$ must supply the base current and the Zener at the valley.
:::
:::

::: check
given: Vp = 9 | 15; Vr = 1 | 3; Vo = 5 | 9; IL = 0.5 | 1.5
answer: (Vp - Vr/2 - Vo)*IL
unit: W
tolerance: 0.5%

## A pass transistor feeds {IL} A at {Vo} V from a raw supply peaking at {Vp} V with {Vr} V of ripple. What does it dissipate?

::: right
Right. $\left(V_p - \frac{V_r}{2} - V_o\right)I_L$ = {answer}.
:::

::: misses
- [(Vp - Vo)*IL] Use the average raw voltage, half a ripple below the peak.
- [any] Not yet. Average voltage across it, times the current.
:::
:::

::: check
kind: python

## Write `design_supply(Vout, IL, beta, f=60, Vr=2.0, head=2.0, IZmin=5e-3)` returning a dict with keys `VZ`, `valley`, `peak`, `C`, `Vrms`, `RS` and `Ppass`, following the six steps.

```python starter
import math

def design_supply(Vout, IL, beta, f=60, Vr=2.0, head=2.0, IZmin=5e-3):
    peak = Vout + Vr
    return {"VZ": Vout, "valley": Vout, "peak": peak, "C": IL / (f * Vr),
            "Vrms": peak / math.sqrt(2), "RS": 100.0, "Ppass": (peak - Vout) * IL}
```

```python solution
import math

def design_supply(Vout, IL, beta, f=60, Vr=2.0, head=2.0, IZmin=5e-3):
    VZ = Vout + 0.7
    valley = Vout + head
    peak = valley + Vr
    return {"VZ": VZ, "valley": valley, "peak": peak,
            "C": IL / (2 * f * Vr),
            "Vrms": (peak + 1.4) / math.sqrt(2),
            "RS": (valley - VZ) / (IL / beta + IZmin),
            "Ppass": (peak - Vr / 2 - Vout) * IL}
```

```python tests
import math
d = design_supply(5, 0.5, 50)
want = {"VZ": 5.7, "valley": 7.0, "peak": 9.0, "C": 0.5 / 240, "Vrms": 10.4 / math.sqrt(2), "RS": 1.3 / 0.015, "Ppass": 1.5}
for k, w in want.items():
    assert k in d, f"The result needs a {k} entry."
    assert abs(d[k] - w) <= 1e-9 * abs(w), f"5 V, 0.5 A, beta 50: {k} should be {w:.6g}, got {d[k]:.6g}."
d = design_supply(12, 1.0, 40, f=50, Vr=1.5, head=2.5)
want = {"VZ": 12.7, "valley": 14.5, "peak": 16.0, "C": 1 / 150, "Vrms": 17.4 / math.sqrt(2), "RS": 1.8 / 0.03, "Ppass": 3.25}
for k, w in want.items():
    assert abs(d[k] - w) <= 1e-9 * abs(w), f"12 V, 1 A: {k} should be {w:.6g}, got {d[k]:.6g}."
```

::: right
Right. A design function like this turns the whole procedure into one call, so you can try other ripple and headroom choices and see what they cost in capacitance and heat.
:::
:::

::: check
kind: python

## Write `simulate_supply(Vs, f, C, IL, dt=2e-6, cycles=6)`: step the reservoir voltage from 0 with the update rule above (input $|V_s\sin 2\pi ft| - 1.4$), and return `(vmin, vmax)` over the last cycle.

```python starter
import math

def simulate_supply(Vs, f, C, IL, dt=2e-6, cycles=6):
    vmax = Vs - 1.4
    return vmax - IL / (2 * f * C), vmax
```

```python solution
import math

def simulate_supply(Vs, f, C, IL, dt=2e-6, cycles=6):
    n = int(round(cycles / f / dt))
    last = int(round(1 / f / dt))
    V = 0.0
    lo, hi = float("inf"), float("-inf")
    for k in range(n + 1):
        t = k * dt
        V = max(V - IL * dt / C, Vs * abs(math.sin(2 * math.pi * f * t)) - 1.4)
        if k > n - last:
            lo, hi = min(lo, V), max(hi, V)
    return lo, hi
```

```python tests
cases = [((12, 60, 2200e-6, 0.5), 9.032773467526358), ((10, 50, 1000e-6, 0.2), 6.986913467049732), ((17, 60, 4700e-6, 1.0), 14.077034703369966), ((9, 60, 470e-6, 0.1), 6.1674668243496775)]
for args, wmin in cases:
    lo, hi = simulate_supply(*args)
    assert abs(hi - (args[0] - 1.4)) < 2e-3, f"For {args}: the peak should be {args[0] - 1.4:.3f} V, got {hi:.3f} V."
    assert abs(lo - wmin) < 2e-3, f"For {args}: the valley should be {wmin:.3f} V, got {lo:.3f} V."
```

::: right
Right. The simulated valley sits 0.25 to 0.4 V above the $I_L/2fC$ estimate in these cases, so a design from the estimate has a little extra headroom.
:::
:::

::: check
kind: design
choose: RS
goal: dc(i(DZ)) = -5m ± 10%
solution: RS = 93

## The regulator alone, fed from the 7 V valley, drives a 10 Ω load through a pass transistor with β = 50. Choose $R_S$ so the Zener keeps 5 mA. (The meter's Zener current is negative: it flows in reverse.)

```sim circuit
VIN in 0 7                          @ 0,0 down 4
RS in z 330                         @ 0,0 right 2
DZ 0 z BV=5.6                       @ 2,4 up 4
Q1 in z out npn BF=50 IS=1e-13      @ 3,0
RL out 0 10                         @ 4,1 down 3
meter: v(out), i(DZ), i(Q1)
```

::: right
Right. About 93 Ω: the output settles near 4.89 V, so the load takes 0.49 A and the base 9.6 mA, and the remaining 5 mA keeps the Zener in breakdown.
:::
:::

::: explain
## Why does a linear regulator need headroom, and what does that cost?

::: model
The pass transistor is the regulator's control element: it absorbs the difference between the raw voltage and the output, adjusting its own voltage drop as the raw voltage ripples. That only works while it stays in its active region, which needs a volt or two across it at the lowest point of the ripple. So the raw supply has to sit well above the output, and the transistor dissipates that difference times the load current all the time, as heat. A 5 V supply from a 9 V peak wastes about a third of its input power, which is why switching regulators replace linear ones wherever efficiency matters.
:::
:::

::: practice

::: check
given: Vo = 3.3 | 5 | 9
answer: Vo + 0.7
unit: V
tolerance: 0.5%

## What Zener voltage gives an emitter follower output of {Vo} V?

::: misses
- [any] One $V_{BE}$ higher.
:::
:::

::: check
given: IL = 0.25 | 1; f = 50 | 60; Vr = 1 | 2
answer: IL/(2*f*Vr)*1e6
unit: µF
tolerance: 0.5%

## What reservoir capacitor gives {Vr} V of ripple at {IL} A from a {f} Hz bridge?

::: misses
- [any] $I_L/(2fV_r)$.
:::
:::

::: check
given: P = 1 | 3; TJ = 125 | 150; TA = 25 | 40
answer: (TJ - TA)/P
unit: °C/W
tolerance: 0.5%

## A pass transistor dissipates {P} W and must stay below {TJ} °C at {TA} °C ambient. What total thermal resistance can it have?

::: misses
- [any] $(T_J - T_A)/P$.
:::
:::
:::
