---
title: "Buck design project: power stage and type III loop"
heading: Designing a 12 V to 3.3 V, 5 A buck at 500 kHz, from inductor and capacitor sizing through the averaged plant with ceramic capacitors, a phase-margin calculator, and a type III compensator placed by Venable's K factor to cross over at 50 kHz with 60° of margin
eyebrow: S11 · Lesson 51 · Buck design project
xp: 80
---

::: hook
Point-of-load regulators like this one sit next to every processor and FPGA: 12 V in, a low voltage out at several amperes, half a megahertz, ceramic output capacitors. The ceramics are what make the loop hard. Their ESR is so small that the zero it would contribute lands far above the switching frequency, leaving the LC filter's full 180° of phase lag at crossover, and only a type III compensator, with two zeros, can lift it back. In this project you'll size the power stage, write the margin calculator, and design that compensator.
:::

::: predict
## With ceramic capacitors (2 mΩ ESR on 37.5 µF), what phase does the buck's control-to-output transfer function have at a 50 kHz crossover, well above its 14.6 kHz LC resonance?

- [ ] About −90°, like an integrator
- [ ] About −135°
- [x] About −170°, close to the LC filter's full lag
- [ ] About −270°

::: reveal
Above resonance the LC double pole contributes nearly −180°: about −172° at 3.4 times the resonance with a Q of 2.3. The ESR zero, at 2.1 MHz, gives back only 1.35°. The plant sits at −170.6°, so the compensator must supply phase lead, 140.6° above its integrator's −90°, for a 60° margin.
:::
:::

::: nameit
## The power stage

- Duty cycle $D = V/V_g$ and load $R = V/I$.
- Inductance for a ripple fraction r: $L = (V_g - V)D/(rIf_s)$.
- Capacitance for an output ripple Δv: $C = \Delta i_L/(8f_s\Delta v)$.

## The plant

The averaged control-to-output transfer function is the PWM gain $V_g/V_M$ times the divider formed by the inductor and the output impedance $Z = R \parallel (r_C + 1/sC)$:

$$G_{vd}(s) = \frac{V_g}{V_M}\cdot\frac{Z}{Z + sL}$$

## Margins

Find the crossover $f_c$ where $|T| = 1$ by bisection on log f, then $\text{PM} = 180° + \angle T(f_c)$, with the angle taken in (−360°, 0] so that a loop past −180° shows a negative margin.

## The K factor

A type III compensator, $G_c = \frac{\omega_i}{s}\frac{(1 + s/\omega_z)^2}{(1 + s/\omega_p)^2}$, with its zeros at $f_c/\sqrt{K}$ and its poles at $f_c\sqrt{K}$ adds exactly $4\arctan\sqrt{K} - 180°$ of lead at $f_c$. For a boost B (the lead needed above −90°), $K = \tan^2(B/4 + 45°)$. Then $\omega_i$ is chosen to make $|T(f_c)| = 1$.
:::

::: example
## Size the power stage for 12 V to 3.3 V at 5 A, 500 kHz, 30% ripple and 10 mV of output ripple.

::: solution
1. **Duty cycle and load.**
   $$\begin{aligned} D &= 3.3/12 \\ &= 0.275 \\ R &= 3.3/5 \\ &= 0.66\ \Omega \end{aligned}$$
2. **Inductor.** The ripple is 30% of 5 A, 1.5 A, so
   $$\begin{aligned} L &= \frac{8.7 \times 0.275}{1.5 \times 500\text{ kHz}} \\ &= 3.19\ \mu\text{H} \end{aligned}$$
3. **Capacitor.**
   $$\begin{aligned} C &= \frac{1.5}{8 \times 500\text{ kHz} \times 10\text{ mV}} \\ &= 37.5\ \mu\text{F} \end{aligned}$$
4. **The filter.** It resonates at 14.55 kHz with
   $$\begin{aligned} Q &= R/\sqrt{L/C} \\ &= 2.26 \end{aligned}$$
5. **ESR zero.** With 2 mΩ of ESR, the ESR zero sits at 2.12 MHz.

**Answer:** L = 3.19 µH and C = 37.5 µF, resonating at 14.55 kHz with Q = 2.26.
:::
:::

::: example
## Place the type III compensator for a 50 kHz crossover with 60° of margin.

::: solution
1. **Phase boost needed.** The plant's phase at 50 kHz is −170.56°, so
   $$\begin{aligned} \theta &= 60 - 90 + 170.56 \\ &= 140.56° \end{aligned}$$
2. **K factor.**
   $$\begin{aligned} K &= \tan^2(80.14°) \\ &= 33.10 \end{aligned}$$
3. **Zeros and poles.** They sit $\sqrt K$ = 5.753 below and above the crossover:
   $$\begin{aligned} f_z &= 50\text{ kHz}/\sqrt K \\ &= 8.691\ \text{kHz} \\ f_p &= 50\text{ kHz} \times \sqrt K \\ &= 287.6\ \text{kHz} \end{aligned}$$
4. **Integrator gain.** $\omega_i$ = 8661 s⁻¹ makes the loop gain 1 at 50 kHz.
5. **The finished loop.** It has 24.5 dB of gain at 1 kHz, and its closed-loop output impedance peaks at 98 mΩ near 36 kHz, against 650 mΩ at the open-loop filter's resonance.

**Answer:** zeros at 8.691 kHz, poles at 287.6 kHz and $\omega_i$ = 8661 s⁻¹ give a 50 kHz crossover with 60° of phase margin.
:::
:::

::: check
kind: python

## Step 1. Write `design_power_stage`: duty cycle, load, inductor and capacitor.

```python starter
import numpy as np

def design_power_stage(VG, V, I, FS, ripple=0.3, dv=0.01):
    # A buck from VG to V at load current I and switching frequency FS. Return (D, R, L, C):
    # the duty cycle, the load resistance, the inductance that makes the peak-to-peak inductor
    # ripple equal ripple*I, and the capacitance that makes the capacitive output ripple dv volts
    # peak to peak (ignore ESR).
    return 0.0, 0.0, 0.0, 0.0

print(design_power_stage(12.0, 3.3, 5.0, 500e3))
```

```python solution
import numpy as np

def design_power_stage(VG, V, I, FS, ripple=0.3, dv=0.01):
    D = V/VG
    R = V/I
    di = ripple*I
    L = (VG - V)*D/(di*FS)
    C = di/(8*FS*dv)
    return D, R, L, C

print(design_power_stage(12.0, 3.3, 5.0, 500e3))
```

```python tests
D, R, L, C = design_power_stage(12.0, 3.3, 5.0, 500e3)
assert abs(D - 0.275) < 1e-12 and abs(R - 0.66) < 1e-12, f"12 V to 3.3 V at 5 A: D = 0.275 and R = 0.66 Ω; got D = {D}, R = {R}."
assert abs(L/3.19e-6 - 1) < 1e-9, f"L = (VG − V)D/(ΔiL·FS) with ΔiL = 1.5 A gives 3.19 µH; got {L*1e6:.4f} µH."
assert abs(C/37.5e-6 - 1) < 1e-9, f"C = ΔiL/(8·FS·Δv) gives 37.5 µF; got {C*1e6:.4f} µF."
D, R, L, C = design_power_stage(24.0, 5.0, 2.0, 300e3, ripple=0.4, dv=0.005)
assert abs(L/(19*5/24/(0.8*300e3)) - 1) < 1e-9 and abs(C/(0.8/(8*300e3*0.005)) - 1) < 1e-9, f"24 V to 5 V at 2 A, 300 kHz, 40% ripple, 5 mV: L = 16.49 µH, C = 66.67 µF; got {L*1e6:.3f} µH, {C*1e6:.3f} µF."
```

::: right
Right. 3.19 µH and 37.5 µF for the 3.3 V, 5 A regulator, and your function works for any spec.
:::
:::

::: check
kind: python

## Step 2. Write `margins(T)`: crossover by bisection and the phase margin.

```python starter
import numpy as np

def margins(T, f_lo=1e2, f_hi=1e7):
    # T(f) returns the loop gain (complex) at frequency f in hertz. Assume |T| crosses 1 exactly
    # once between f_lo and f_hi. Find the crossover fc by bisection on log f, then the phase
    # margin pm = 180 + (phase of T at fc in degrees, taken in (-360, 0]). Return (fc, pm).
    return 0.0, 0.0

T = lambda f: 2*np.pi*5e3*np.sqrt(1.25)/(2j*np.pi*f*(1 + 1j*f/10e3))
print(margins(T))
```

```python solution
import numpy as np

def margins(T, f_lo=1e2, f_hi=1e7):
    lo, hi = f_lo, f_hi
    for _ in range(200):
        mid = np.sqrt(lo*hi)
        if abs(T(mid)) > 1:
            lo = mid
        else:
            hi = mid
    fc = np.sqrt(lo*hi)
    phase = np.degrees(np.angle(T(fc)))
    if phase > 0:
        phase -= 360
    return fc, 180 + phase

T = lambda f: 2*np.pi*5e3*np.sqrt(1.25)/(2j*np.pi*f*(1 + 1j*f/10e3))
print(margins(T))
```

```python tests
K = 2*np.pi*5e3*np.sqrt(1.25)
T = lambda f: K/(2j*np.pi*f*(1 + 1j*f/10e3))
fc, pm = margins(T)
want = 90 - np.degrees(np.arctan(0.5))
assert abs(fc/5e3 - 1) < 1e-6, f"K/(s(1 + s/p)) with this K crosses over at exactly 5 kHz; got {fc:.3f} Hz."
assert abs(pm - want) < 1e-4, f"Its phase margin is 90° − atan(0.5) = {want:.4f}°; got {pm:.4f}°."
Td = lambda f: T(f)*np.exp(-2j*np.pi*f*50e-6)
fc, pm = margins(Td)
assert abs(pm - (want - 90)) < 1e-4, f"With 50 µs of delay the phase at 5 kHz falls another 90°, past −180°: the margin is {want - 90:.4f}°, negative; got {pm:.4f}°. Take the phase in (−360°, 0]."
T2 = lambda f: 1e6/(2j*np.pi*f)**2*(1 + 2j*np.pi*f/1e4)
fc, pm = margins(T2)
w = np.sqrt((1e12/1e8 + np.sqrt(1e24/1e16 + 4e12))/2)
assert abs(fc/(w/(2*np.pi)) - 1) < 1e-6 and abs(pm - np.degrees(np.arctan(w/1e4))) < 1e-4, f"A double integrator with a zero at 10⁴ rad/s crosses at {w/(2*np.pi):.2f} Hz with {np.degrees(np.arctan(w/1e4)):.3f}° of margin; got {fc:.2f} Hz and {pm:.3f}°."
```

::: right
Right. Exact crossovers and margins, including a negative one when delay pushes the phase past −180°.
:::
:::

::: check
kind: python

## Step 3. Write `type3_kfactor(fc, pm)`: place the compensator.

```python starter
import numpy as np

VG, VM, RC = 12.0, 1.0, 2e-3        # input, PWM ramp amplitude, capacitor ESR
D, R, L, C = 0.275, 0.66, 3.19e-6, 37.5e-6

def plant(f):
    # Control-to-output transfer function of the averaged buck: the PWM gain VG/VM times the
    # divider formed by the inductor and the load in parallel with the capacitor and its ESR.
    s = 2j*np.pi*f
    Z = 1/(1/R + 1/(RC + 1/(s*C)))
    return VG/VM*Z/(Z + s*L)

def comp(f, wi, fz, fp):
    # Type III compensator: an integrator wi/s, two zeros at fz and two poles at fp (hertz).
    s = 2j*np.pi*f
    return wi/s*(1 + s/(2*np.pi*fz))**2/(1 + s/(2*np.pi*fp))**2

def margins(T, f_lo=1e2, f_hi=1e7):
    lo, hi = f_lo, f_hi
    for _ in range(200):
        mid = np.sqrt(lo*hi)
        if abs(T(mid)) > 1:
            lo = mid
        else:
            hi = mid
    fc = np.sqrt(lo*hi)
    phase = np.degrees(np.angle(T(fc)))
    if phase > 0:
        phase -= 360
    return fc, 180 + phase

def type3_kfactor(fc, pm):
    # Venable's K factor: find the plant's phase at fc, the boost the compensator must add above
    # its integrator's -90 degrees to leave margin pm, K = tan(boost/4 + 45 deg)^2, zeros at
    # fc/sqrt(K) and poles at fc*sqrt(K). Then pick wi so that |plant*comp| = 1 at fc.
    # Return (wi, fz, fp).
    return 1.0, 1e3, 1e5

wi, fz, fp = type3_kfactor(50e3, 60.0)
print(wi, fz, fp, margins(lambda f: plant(f)*comp(f, wi, fz, fp)))
```

```python solution
import numpy as np

VG, VM, RC = 12.0, 1.0, 2e-3        # input, PWM ramp amplitude, capacitor ESR
D, R, L, C = 0.275, 0.66, 3.19e-6, 37.5e-6

def plant(f):
    # Control-to-output transfer function of the averaged buck: the PWM gain VG/VM times the
    # divider formed by the inductor and the load in parallel with the capacitor and its ESR.
    s = 2j*np.pi*f
    Z = 1/(1/R + 1/(RC + 1/(s*C)))
    return VG/VM*Z/(Z + s*L)

def comp(f, wi, fz, fp):
    # Type III compensator: an integrator wi/s, two zeros at fz and two poles at fp (hertz).
    s = 2j*np.pi*f
    return wi/s*(1 + s/(2*np.pi*fz))**2/(1 + s/(2*np.pi*fp))**2

def margins(T, f_lo=1e2, f_hi=1e7):
    lo, hi = f_lo, f_hi
    for _ in range(200):
        mid = np.sqrt(lo*hi)
        if abs(T(mid)) > 1:
            lo = mid
        else:
            hi = mid
    fc = np.sqrt(lo*hi)
    phase = np.degrees(np.angle(T(fc)))
    if phase > 0:
        phase -= 360
    return fc, 180 + phase

def type3_kfactor(fc, pm):
    plant_phase = np.degrees(np.angle(plant(fc)))
    if plant_phase > 0:
        plant_phase -= 360
    boost = pm - 90 - plant_phase
    K = np.tan(np.radians(boost/4 + 45))**2
    fz, fp = fc/np.sqrt(K), fc*np.sqrt(K)
    wi = 1/abs(plant(fc)*comp(fc, 1.0, fz, fp))
    return wi, fz, fp

wi, fz, fp = type3_kfactor(50e3, 60.0)
print(wi, fz, fp, margins(lambda f: plant(f)*comp(f, wi, fz, fp)))
```

```python tests
for (fc0, pm0) in ((50e3, 60.0), (30e3, 50.0), (80e3, 55.0)):
    wi, fz, fp = type3_kfactor(fc0, pm0)
    fc, pm = margins(lambda f: plant(f)*comp(f, wi, fz, fp))
    assert abs(fc/fc0 - 1) < 1e-6, f"The loop should cross over at {fc0/1e3:.0f} kHz; yours crosses at {fc/1e3:.4f} kHz."
    assert abs(pm - pm0) < 1e-6, f"At {fc0/1e3:.0f} kHz the phase margin should be {pm0}°; yours is {pm:.4f}°."
    assert fz < fc0 < fp, "The zeros belong below crossover and the poles above it."
wi, fz, fp = type3_kfactor(50e3, 60.0)
assert abs(fz/8691.356 - 1) < 1e-5 and abs(fp/287642.11 - 1) < 1e-5, f"For 50 kHz and 60° the plant's phase is −170.56°, the boost 140.56° and K = 33.10: zeros at 8.691 kHz, poles at 287.6 kHz; got {fz:.1f} Hz and {fp:.1f} Hz."
```

::: right
Right. Every design crosses exactly where you asked with exactly the margin you asked for.
:::
:::

::: explain
## Why does a buck with ceramic output capacitors need a type III compensator, when one with electrolytic capacitors can often use type II?

::: model
An electrolytic capacitor's ESR is large enough that its zero falls below or near the crossover frequency, and that zero cancels half of the LC filter's 180° of phase lag. The loop then needs only modest lead, which a type II compensator (an integrator with one zero and one pole) can supply. A ceramic capacitor's ESR is milliohms, so its zero lands at megahertz, far above any usable crossover, and the plant arrives at crossover with nearly the full −180°. Adding the integrator's −90° leaves the loop near −270°, so the compensator must supply more than 90° of lead to have any margin at all. A single zero can give at most 90°; a type III compensator has two zeros and can give up to almost 180°.
:::
:::

::: practice

::: check
given: g = 5 | 12 | 48; V = 1 | 3.3; I = 2 | 10; f = 200 | 1000; r = 0.2 | 0.4
answer: (g - V)*(V/g)/(r*I*f*1e3)*1e6
unit: µH
tolerance: 0.5%

## Buck inductance: {g} V to {V} V, {I} A, {f} kHz, ripple fraction {r}?

::: misses
- [any] $(V_g - V)D/(rIf_s)$.
:::
:::

::: check
given: B = 100 | 130 | 160
answer: tan((B/4 + 45)*pi/180)^2
tolerance: 0.5%

## K factor for {B}° of boost (type III)?

::: misses
- [any] $\tan^2(B/4 + 45°)$.
:::
:::

::: check
given: f = 20 | 50 | 100; K = 10 | 30 | 60
answer: f/sqrt(K)
unit: kHz
tolerance: 0.5%

## Type III zeros for crossover at {f} kHz with K = {K}?

::: misses
- [any] $f_c/\sqrt{K}$.
:::
:::
:::
