S11 · Lesson 50 · Converter simulation lab
Simulating a synchronous buck switch by switch with Runge–Kutta, checking its ripple against the formulas of lesson 3, simulating the averaged model with a tenth of the steps, and measuring the overshoot of a duty-cycle step against the second-order transfer function
Lesson 16 replaced the switch by its average and got a linear model that's easy to analyze and fast to simulate. In this lab you'll test that trade directly. You'll simulate a 12 V buck both ways, check the switching model's ripple against the formulas you derived by hand, and find where the averaged model is exact, where it's off, and by how much.
Predict
Starting from rest, the switching model's output voltage, averaged over each cycle, runs slightly ahead of the averaged model during the start-up transient. Why?
With trailing-edge modulation the switch node sits at VG for the first DT of each cycle. The average over the cycle is the same, but its center falls before the cycle's center, a small time advance. During the fast start-up it shows as a difference of several percent; in steady state and for slow changes it vanishes. That's the modulator delay that more refined averaged models include.
Name it
The converter
A synchronous buck with = 12 V, L = 22 µH, C = 47 µF, R = 2 Ω and = 100 kHz. The state is the inductor current and capacitor voltage:
where the switch node is for the first DT of each cycle and 0 for the rest (both switches are ideal and the current may reverse).
The averaged model
Replace by its average . The model is linear and time-invariant, with the transfer function of lesson 17, a resonance at = 4.95 kHz and damping = 0.171.
What to check
- The switching model in steady state: average , inductor ripple , output ripple .
- The averaged model against its exact solution, and its peak from rest, .
- A duty step's overshoot, the same expression, independent of the step's size and direction.
Worked example
What do the two models give at D = 0.3?
Show the solution
- Switching model at steady state. It settles to an average of 3.6000 V, with 1.147 A of inductor ripple (the formula gives 1.145) and 30.5 mV of output ripple (the formula gives 30.5).
- Averaged model from rest. It peaks at 5.686 V, using 2,000 steps against the switching model's 20,000. The formula gives
- During start-up. The switching model's cycle averages lead by up to 0.31 V (8.5% of the final value) four cycles in; by the time the ringing has died out the two agree.
Answer both models agree with the formulas: the switching model settles at 3.6000 V with 1.147 A and 30.5 mV of ripple, and the averaged model peaks at 5.686 V from rest.
Worked example
A duty step from 0.3 to 0.4 overshoots by how much in each model?
Show the solution
- Averaged model. It overshoots by 0.5796 of the step, matching with ζ = 0.171.
- Switching model. Its cycle averages overshoot by 0.5753, 0.75% less.
- A small step. For a small step (0.6 to 0.65) the difference shrinks to 0.07%.
- Which to use. For loop design at crossovers well below the switching frequency, the averaged model is the right tool.
Answer 0.5796 of the step in the averaged model and 0.5753 in the switching model, 0.75% less.
Check
Step 1. Write simulate_switched(D): the buck pulse by pulse.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write simulate_averaged(D): the same converter with the switch averaged.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write duty_step_overshoot(D1, D2): a small-signal step on the averaged model.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
When is the averaged model good enough, and when do you need the switching simulation?
The averaged model throws away everything that happens within a switching period: the ripple and the timing of the pulses within each cycle. That's harmless whenever the quantities of interest change slowly compared with the switching period, which covers steady-state averages, efficiency trends and control loops with crossover well below the switching frequency, the usual design rule. It loses accuracy for fast transients, as the start-up here shows, and it can't predict the ripple itself, peak currents for saturation and current limits, subharmonic oscillation in current-mode control, or anything near half the switching frequency. Those need the switching simulation, which costs far more steps but sees each pulse.
Practice
Keep practicing
3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.