---
title: Power supply lab
heading: Exact ripple and diode currents, Zener and follower regulators, in Python
eyebrow: C5 · Lesson 53 · Power supply lab
xp: 50
---

::: hook
Lessons 8 and 11 sized rectifiers and regulators with approximations: ripple as $\frac{I}{2fC}$, a conduction window of $\sqrt{2V_r/V_p}$, a Zener as a fixed voltage. Each is good to ten or twenty percent, which is fine for a first pass and not for a product. In this lab you'll compute the same quantities exactly from the models, see where the approximations err and in which direction, and build the calculations a power-supply design needs.

::: play
- A half-wave rectifier charges a capacitor that feeds a constant-current load. The second trace is the diode's current.
- The diode conducts in short pulses near each peak. Raise the load current: the ripple grows, the pulses widen, and their peaks climb.
- Raise the capacitance. The ripple falls, but the pulses get narrower and taller: the same charge has to arrive in less time.
:::
:::

```sim circuit
V1 in 0 sine 12 V 60 Hz          @ 0,0 down 3
D1 in out                        @ 0,0 right 3
C1 out 0 1000u                   @ 3,0 down 3
I1 out 0 100m                    @ 6,0 down 3
slider: C1 220u..4.7m log
slider: I1.amp 10m..500m log
scope: v(out), i(D1)
time: 0..100m s
meter: v(out), i(D1)
```

::: predict
## A full-wave rectifier with a 10.6 V peak feeds 100 mA from 1000 µF at 60 Hz. The formula $\frac{I}{2fC}$ gives 0.83 V of ripple. Is the true ripple larger or smaller?

- [ ] Larger, because the diode drop adds to it
- [x] Smaller, because the capacitor stops discharging before a full half-period has passed
- [ ] Exactly 0.83 V
- [ ] Larger, because the load current isn't constant

::: reveal
Smaller: 0.73 V. The formula assumes the capacitor discharges for the whole half-period, but recharging starts before the next peak, so the discharge lasts only $\frac{T}{2}$ minus the conduction time. The error grows with the ripple: the formula is conservative, which is the safe direction for a capacitor size and the unsafe one for a diode's peak current.
:::
:::

::: nameit
## Exact conduction with a constant-current load

Take the input as $V_p\sin\phi$ after the diode drops, with $\phi = \omega t$. While the diode conducts, the capacitor follows the input and the diode supplies $\omega CV_p\cos\phi + I_L$. That falls to zero just after the peak, at

$$\phi_\text{off} = \frac\pi2 + \arcsin\frac{I_L}{\omega CV_p}.$$

From there the capacitor discharges linearly, $v = V_p\sin\phi_\text{off} - \frac{I_L(\phi - \phi_\text{off})}{\omega C}$, until it meets the rising input of the next half-cycle (full-wave, π later) or the next cycle (half-wave, 2π later). Solving that crossing by bisection gives the turn-on phase $\phi_\text{on}$ and with it

- the ripple, $V_p(1 - \sin\phi_\text{on})$;
- the conduction angle, $\phi_\text{off} - \phi_\text{on}$;
- the peak diode current, $\omega CV_p\cos\phi_\text{on} + I_L$, at turn-on.

## A Zener with resistance

Model the Zener in breakdown as $V_{Z0}$ in series with $r_z$. With the supply, $R_S$, the Zener and the load $R_L$ all meeting at the output node, the node equation gives

$$V = \frac{V_\text{in}/R_S + V_{Z0}/r_z}{1/R_S + 1/r_z + 1/R_L},$$

valid while that V is at least $V_{Z0}$ (the Zener conducts). Below that the Zener is off and the output is just the divider $V_\text{in}\frac{R_L}{R_S + R_L}$.

## The follower regulator

The base node satisfies $\frac{V_\text{in} - V_B}{R_B} = \frac{V_B - V_{Z0}}{r_z} + \frac{I_L}{\beta + 1}$, and the output is $V_B - V_T\ln\frac{I_L}{I_S}$. The input must stay above both $V_Z + R_B\left(I_{Z,\text{min}} + \frac{I_L}{\beta + 1}\right)$ and $V_\text{out}$ plus the pass transistor's minimum voltage, or the output drops out.
:::

::: example
## Find the exact ripple, conduction angle and peak diode current for lesson 8's bridge supply: 10.6 V peak, 100 mA, 1000 µF, 60 Hz. Compare them with the approximations.

::: solution
1. **Turn-off angle.** $\omega CV_p$ = 4.00 A, so
   $$\begin{aligned} \phi_\text{off} &= \frac\pi2 + \arcsin\frac{0.1}{4.00} \\ &= 1.596\ \text{rad} \end{aligned}$$
   just past the peak.
2. **Turn-on angle.** Bisection finds the next turn-on at $\phi_\text{on}$ = 1.197 rad into the next half-cycle.
3. **Ripple.**
   $$\begin{aligned} \Delta V &= 10.6(1 - \sin 1.197) \\ &= 0.731\ \text{V} \end{aligned}$$
4. **Conduction angle and peak current.** The conduction angle is 0.399 rad (22.8°), and
   $$\begin{aligned} I_\text{pk} &= 4.00\cos 1.197 + 0.1 \\ &= 1.56\ \text{A} \end{aligned}$$
5. **Compare with the approximations.** They gave 0.833 V, 0.396 rad and 1.68 A: the ripple 14% high, the window less than 1% narrow, the peak current 8% high. All are on the safe side for sizing, but a supply designed to them carries a larger capacitor than it needs.

**Answer:** the exact ripple is 0.731 V, the conduction angle 0.399 rad (22.8°) and the peak diode current 1.56 A, against the approximations' 0.833 V, 0.396 rad and 1.68 A.
:::
:::

::: example
## A 5.1 V Zener ($r_z$ = 10 Ω) is fed from 12 V through 150 Ω. Find the output with 1 kΩ, 200 Ω and 100 Ω loads.

::: solution
1. **With 1 kΩ.**
   $$\begin{aligned} V &= \frac{12/150 + 5.1/10}{1/150 + 1/10 + 1/1000} \\ &= 5.480\ \text{V} \end{aligned}$$
   and the Zener carries $\frac{5.480 - 5.1}{10}$ = 38 mA.
2. **With 200 Ω.** The output is 5.284 V, with 18 mA in the Zener.
3. **With 100 Ω.** The formula gives 5.057 V, below $V_{Z0}$, so the Zener is off and the output is
   $$12 \times \frac{100}{250} = 4.80\ \text{V}$$
   Regulation has been lost.
4. **What the $r_z$ model shows.** The output already falls 0.2 V between the first two loads, which the fixed-voltage model hides.

**Answer:** the output is 5.480 V with 1 kΩ and 5.284 V with 200 Ω; with 100 Ω the Zener turns off and the output drops to 4.80 V.
:::
:::

::: example
## Lesson 52's follower regulator (5.6 V Zener with $r_z$ = 10 Ω, $R_B$ = 220 Ω, β = 50, $I_S = 10^{-14}$ A) runs from 9 V. What's its output at 50 mA and 500 mA, and what's its dropout input at 500 mA?

::: solution
1. **Base voltage at 50 mA.**
   $$\begin{aligned} V_B &= \frac{9/220 + 5.6/10 - 0.05/51}{1/220 + 1/10} \\ &= 5.738\ \text{V} \end{aligned}$$
2. **Output at 50 mA.**
   $$\begin{aligned} V_{BE} &= 0.02585\ln\frac{0.05}{10^{-14}} \\ &= 0.756\ \text{V} \end{aligned}$$
   so $V_\text{out}$ = 4.983 V.
3. **At 500 mA.** $V_B$ = 5.654 V and $V_{BE}$ = 0.815 V, so the output is 4.839 V: 144 mV lower, as lesson 52 estimated.
4. **What the base resistor needs.**
   $$\begin{aligned} V_\text{in} &\ge 5.6 + 220 \times (5 + 9.8)\ \text{mA} \\ &= 8.86\ \text{V} \end{aligned}$$
5. **What the pass transistor needs.** It needs 4.84 + 1.0 = 5.84 V.
6. **Which sets the limit.** So the regulator drops out below 8.86 V at full load: the Zener's resistor sets the limit, well above what the transistor needs.

**Answer:** the output is 4.983 V at 50 mA and 4.839 V at 500 mA, and the regulator drops out below an 8.86 V input at 500 mA.
:::
:::

::: check
kind: python

## Step 1. Write `conduction(Vp, f, C, IL, full=True)` returning `(ripple, angle, ipeak)` for a capacitor-input rectifier with an ideal diode and a constant-current load, as in the reading: find $\phi_\text{off}$, then bisect for the turn-on phase in the next half-cycle (full-wave) or cycle (half-wave).

```python starter
import math

def conduction(Vp, f, C, IL, full=True):
    Vr = IL / ((2 if full else 1) * f * C)
    return Vr, math.sqrt(2 * Vr / Vp), IL * (1 + 2 * math.pi * math.sqrt(Vp / (2 * Vr)))

print(conduction(10.6, 60, 1e-3, 0.1))
```

```python solution
import math

def conduction(Vp, f, C, IL, full=True):
    w = 2 * math.pi * f
    off = math.pi / 2 + math.asin(min(1.0, IL / (w * C * Vp)))
    v0 = Vp * math.sin(off)
    per = math.pi if full else 2 * math.pi
    g = lambda p: Vp * math.sin(p) - (v0 - IL * (p + per - off) / (w * C))
    lo, hi = 0.0, math.pi / 2
    for _ in range(100):
        mid = (lo + hi) / 2
        if g(mid) > 0:
            hi = mid
        else:
            lo = mid
    on = (lo + hi) / 2
    return Vp * (1 - math.sin(on)), off - on, w * C * Vp * math.cos(on) + IL

print(conduction(10.6, 60, 1e-3, 0.1))
```

```python tests
r, a, ip = conduction(10.6, 60, 1e-3, 0.1)
assert abs(r - 0.73093) < 1e-4 and abs(a - 0.39856) < 1e-4 and abs(ip - 1.55820) < 1e-4, f"Bridge: 0.731 V, 0.399 rad, 1.558 A; got {r}, {a}, {ip}"
r2, a2, ip2 = conduction(11.3, 60, 1.667e-3, 0.05, full=False)
assert abs(r2 - 0.47643) < 1e-4 and abs(ip2 - 2.09031) < 1e-4, f"Half-wave: 0.476 V and 2.090 A; got {r2}, {ip2}"
```

::: right
Right. The exact model uses no small-ripple assumption, so it stays correct where the formulas drift.
:::
:::

::: check
kind: python

## Step 2. Write `zener_design(Vmin, Vmax, VZ, ILmax, IZmin)` returning `(RS, PZ, PR)`: the largest series resistor, and the Zener's and the resistor's worst-case dissipation (at the highest input with no load).

```python starter
def zener_design(Vmin, Vmax, VZ, ILmax, IZmin):
    RS = (Vmin - VZ) / ILmax
    return RS, VZ * ILmax, 0.0

print(zener_design(9, 12, 5.1, 0.02, 0.005))
```

```python solution
def zener_design(Vmin, Vmax, VZ, ILmax, IZmin):
    RS = (Vmin - VZ) / (ILmax + IZmin)
    I = (Vmax - VZ) / RS
    return RS, VZ * I, (Vmax - VZ) ** 2 / RS

print(zener_design(9, 12, 5.1, 0.02, 0.005))
```

```python tests
RS, PZ, PR = zener_design(9, 12, 5.1, 0.02, 0.005)
assert abs(RS - 156) < 1e-9, f"Lesson 11: 156 Ω; got {RS}"
assert abs(PZ - 0.225577) < 1e-5 and abs(PR - 0.305192) < 1e-5, f"Expected 0.226 W and 0.305 W; got {PZ}, {PR}"
```

::: right
Right. The worst case for the Zener is no load at the highest input, when it takes everything the resistor passes.
:::
:::

::: check
kind: python

## Step 3. Write `zener_out(Vin, RS, VZ0, rz, RL)` returning the output of a Zener regulator with the $V_{Z0}$ + $r_z$ model, falling back to the plain divider when the Zener isn't conducting.

```python starter
def zener_out(Vin, RS, VZ0, rz, RL):
    return VZ0

print(zener_out(12, 150, 5.1, 10, 1000))
```

```python solution
def zener_out(Vin, RS, VZ0, rz, RL):
    V = (Vin / RS + VZ0 / rz) / (1 / RS + 1 / rz + 1 / RL)
    if V >= VZ0:
        return V
    return Vin * RL / (RS + RL)

print(zener_out(12, 150, 5.1, 10, 1000))
```

```python tests
assert abs(zener_out(12, 150, 5.1, 10, 1000) - 5.479876) < 1e-5, "1 kΩ load: 5.480 V."
assert abs(zener_out(15, 150, 5.1, 10, 1000) - 5.665635) < 1e-5, "15 V in: 5.666 V."
assert abs(zener_out(12, 150, 5.1, 10, 200) - 5.283582) < 1e-5, "200 Ω load: 5.284 V."
assert abs(zener_out(12, 150, 5.1, 10, 100) - 4.8) < 1e-9, "100 Ω: the Zener drops out, 4.80 V."
```

::: right
Right. Line and load regulation both fall out of one node equation.
:::
:::

::: check
kind: python

## Step 4. Write `follower_reg(Vin, VZ0, rz, RB, beta, IL, IS=1e-14)` returning the output of an emitter-follower regulator, from the base-node equation and $V_{BE} = V_T\ln\frac{I_L}{I_S}$ with $V_T$ = 0.02585 V.

```python starter
def follower_reg(Vin, VZ0, rz, RB, beta, IL, IS=1e-14):
    return VZ0 - 0.7

print(follower_reg(9, 5.6, 10, 220, 50, 0.5))
```

```python solution
import math

def follower_reg(Vin, VZ0, rz, RB, beta, IL, IS=1e-14):
    VB = (Vin / RB + VZ0 / rz - IL / (beta + 1)) / (1 / RB + 1 / rz)
    return VB - 0.02585 * math.log(IL / IS)

print(follower_reg(9, 5.6, 10, 220, 50, 0.5))
```

```python tests
a = follower_reg(9, 5.6, 10, 220, 50, 0.05)
b = follower_reg(9, 5.6, 10, 220, 50, 0.5)
assert abs(a - 4.982583) < 1e-5 and abs(b - 4.838662) < 1e-5, f"Expected 4.983 V and 4.839 V; got {a}, {b}"
assert abs(follower_reg(12, 5.6, 10, 220, 50, 0.5) - 4.969097) < 1e-5, "At 12 V in: 4.969 V."
```

::: right
Right. The 144 mV fall splits between $V_{BE}$'s logarithm and the base current loading the Zener.
:::
:::

::: check
kind: python

## Step 5. Write `dropout(Vout, IL, beta, VZ, RB, IZmin=0.005, vce=1.0)` returning the lowest input voltage at which a follower regulator still regulates at load current IL.

```python starter
def dropout(Vout, IL, beta, VZ, RB, IZmin=0.005, vce=1.0):
    return Vout + vce

print(dropout(4.9, 0.5, 50, 5.6, 220))
```

```python solution
def dropout(Vout, IL, beta, VZ, RB, IZmin=0.005, vce=1.0):
    return max(VZ + RB * (IZmin + IL / (beta + 1)), Vout + vce)

print(dropout(4.9, 0.5, 50, 5.6, 220))
```

```python tests
assert abs(dropout(4.9, 0.5, 50, 5.6, 220) - 8.856863) < 1e-5, "220 Ω base resistor: 8.86 V, set by the Zener's feed."
assert abs(dropout(4.9, 0.5, 50, 5.6, 47) - 6.295784) < 1e-5, "47 Ω: 6.30 V."
assert abs(dropout(4.9, 0.5, 50, 5.6, 10) - 5.9) < 1e-9, "10 Ω: the transistor's 1 V sets it, 5.90 V."
```

::: right
Right. Two limits, and the larger one wins. A smaller $R_B$ lowers the first at the cost of more standing current.
:::
:::

::: check
kind: parts
given: Vp = 10 | 15; f = 50 | 60; C = 1000 | 2200; IL = 0.1 | 0.5

## A full-wave rectifier ({Vp} V peak after the diodes, {f} Hz) feeds {IL} A from {C} µF.

::: part
answer: IL/(2*f*C*1e-6)
unit: V
tolerance: 0.5%

### What ripple does the usual approximation give?

::: misses
- [IL/(f*C*1e-6)] Full-wave recharges twice per cycle.
- [any] $\frac{I_L}{2fC}$.
:::
:::

::: part
answer: pi/2 + asin(IL/(2*pi*f*C*1e-6*Vp))
unit: rad
tolerance: 0.5%

### At what phase does the diode stop conducting?

::: misses
- [pi/2] Just after the peak, when the capacitor's current can no longer supply the load.
- [any] $\frac\pi2 + \arcsin\frac{I_L}{\omega CV_p}$.
:::
:::
:::

::: check
given: Vin = 10 | 12; RS = 100 | 220; VZ = 5.1 | 6.2; rz = 5 | 20; RL = 1 | 4.7
answer: (Vin/RS + VZ/rz)/(1/RS + 1/rz + 1/(RL*1000))
unit: V
tolerance: 0.2%

## A Zener ($V_{Z0}$ = {VZ} V, $r_z$ = {rz} Ω) fed from {Vin} V through {RS} Ω drives {RL} kΩ. What's the output?

::: right
Right. The node equation: {answer}.
:::

::: misses
- [VZ] The Zener's resistance lets the output rise above $V_{Z0}$.
- [any] $\frac{V_\text{in}/R_S + V_{Z0}/r_z}{1/R_S + 1/r_z + 1/R_L}$.
:::
:::

::: explain
## Why does the usual ripple formula overestimate the ripple of a capacitor-input rectifier?

::: model
The formula assumes the capacitor supplies the load for an entire half-period (or period) between charging pulses. In reality the diode turns on again before the next peak, as soon as the rising input catches the falling capacitor voltage, so the capacitor discharges for the half-period minus the conduction time. A shorter discharge means less voltage lost, so the true ripple is smaller. The bigger the ripple, the earlier the diode turns on and the larger the error. The same short-window effect makes the formula for peak diode current, which assumes a narrow window, overestimate it too.
:::
:::

::: practice

::: check
given: Vp = 8 | 20; f = 50 | 60; C = 470 | 4700; IL = 0.05 | 1
answer: pi/2 + asin(IL/(2*pi*f*C*1e-6*Vp))
unit: rad
tolerance: 0.5%

## {Vp} V peak, {f} Hz, {C} µF, {IL} A. Turn-off phase?

::: misses
- [any] $\frac\pi2 + \arcsin\frac{I_L}{\omega CV_p}$.
:::
:::

::: check
given: Vin = 9 | 15; RS = 150 | 330; VZ = 4.7 | 8.2; rz = 8 | 25; RL = 2 | 10
answer: (Vin/RS + VZ/rz)/(1/RS + 1/rz + 1/(RL*1000))
unit: V
tolerance: 0.2%

## {VZ} V Zener, $r_z$ = {rz} Ω, {Vin} V through {RS} Ω, {RL} kΩ load. Output?

::: misses
- [any] The node equation.
:::
:::
:::
