Run this example
The browser version is coming soon. Until then, open this example in the desktop app. Download Voltecx
The buckClosedLoop example is the 48 V to 12 V buck with a PI controller setting the duty cycle. By hand, the loop gain crosses 0 dB three times: it falls through it near 373 Hz, rises above it again on the output filter's resonance and falls through it last at 1758 Hz, where the phase margin is about 44°. The run starts from 0 V, settles inside ±1 % of 12 V at 3.3 ms without passing 12 V, and the loop gain measured on the switching circuit falls through 0 dB last at 1751 Hz with 45° of phase margin and 47 dB of gain margin.
Open it
In the app: File › Open Example › DC-DC › Buck converter, closed loop, press F5, then Analysis › Loop Gain with the signal duty. From the command line:
powercraft-cli run --cmd file.openExample --params '{"name": "buckClosedLoop"}' \
--cmd simulation.run \
--cmd analysis.loopGain --params '{"signal": "duty", "fStart": 100, "fStop": "20k", "points": 80}'
The power stage is the one of the open-loop buck: 48 V in, L1 = 100 µH, C1 = 100 µF, R1 = 2.4 Ω, 100 kHz. The capacitor now starts empty.
The hand calculation
The duty cycle drives the output through the LC filter. At low frequency the gain from duty to output is V per unit of duty. The filter resonates at
The PI controller is with and , so the loop gain is
Well below the filter is flat and . Setting : gives rad/s, a first crossing near 350 Hz (373 Hz with the filter's rise), where the phase margin is about 115°.
That is not the crossing that matters. Above it the gain keeps falling toward 0.48 (−6.4 dB), but the filter's resonance lifts it by up to : rises above 1 again at 1181 Hz, peaks at +2.1 dB near 1.51 kHz and falls through 1 for the last time at 1758 Hz. There the filter has already turned the phase most of the way to −180°, so the phase margin is about 44° (41° with the PWM's half-period delay). The last crossing sets the damping: the closed-loop poles are at s⁻¹, ζ ≈ 0.12, so a load step rings at about 1.9 kHz.
The run
The example runs for 10 ms from an empty capacitor.
| Quantity | Hand | Run |
|---|---|---|
| Settled output (last ten periods) | 12 V | 12.00 V |
| Settled duty cycle | 0.25 | 0.250 |
| Time into ±1 % of 12 V | — | 3.3 ms |
| Peak output | — | below 12.01 V |
| 0 dB crossings | 3 | 3 |
| Last fall through 0 dB | 1758 Hz | 1751 Hz |
| Phase margin there | 44.5° | 45° |
| Gain margin | — | 47 dB |
analysis.loopGain reads the margins at the last fall through 0 dB and says how many crossings it found (crossings, and a warning). Sweep densely around the resonance: the phase turns by about 90° between 1.3 and 2 kHz, so the default 50-point sweep from 10 Hz to 100 kHz reads 52° there, and a 12-point sweep from 100 Hz to 20 kHz steps over the resonance and finds only the first crossing. The ringing at start-up is that same resonance, excited while the duty cycle climbs; the integrator is slow, so it lets the output ring and then pulls it in.
analysis.loopGain injects a small perturbation into the duty signal of the switching circuit and measures the response at each frequency. It needs no averaged model, so the result includes the PWM and anything else the circuit holds.
Try next
- Halve Kp to 0.005: the resonance hump stays below 0 dB, and by hand the loop crosses once, near 330 Hz with about 100° of margin. Double it to 0.02: one crossing near 2.1 kHz with only about 27°. Run the loop gain again and compare.
- Change the load R1 to 24 Ω (0.5 A): Q rises to 24 and the resonance peak grows. Check the gain margin.
- Read how to design the PI for a buck for the full procedure.
Every number on this page comes from a run that a test repeats (auto::tests_worked_examples), so the page changes when the simulator does.