How the in-browser simulator works
Intent
Section titled “Intent”- See why a switching converter is a linear circuit within each switching interval, and what stepping it exactly means.
- Compare the exact step with a simple integration rule on a fast time constant.
- Know how the simulator finds the periodic steady state, and what that saves over a run from rest.
Theory
Section titled “Theory”A linear circuit in each interval
Section titled “A linear circuit in each interval”Between two switching events, every switch and diode of the simulator is either on or off, and what is left is a linear circuit: resistances, inductances, capacitances and constant sources. Its state, the inductor currents and the capacitor voltages, obeys linear differential equations with constant sources in each interval, the same description that state-space averaging starts from [Erickson & Maksimović 2020, Ch. 7]. For a capacitor charged through a resistance, the solution over a step is exact, however long the step:
- voltage after the step
- time step
- time constant
- voltage at the start of the step
- voltage it tends to
Assumptions, convention and source
- Assumptions
- the circuit is linear and its sources stay constant during the step
- single-pole (first-order) response to a step
- Notes
- each step multiplies the deviation from by , which lies between 0 and 1 however long the step is: the step is exact, and the deviation cannot grow. An inductor's current follows the same law with the time constant L over R
- Source
- Alexander & Sadiku 2017, Ch. 7 (First-Order Circuits: the complete response); derived here
- Derivation
- step-by-step sympy derivation
- Equation id
sim.exact_step· equations.yaml entry
A circuit with several states steps them all at once with the exponential of its equations’ matrix, which the simulator computes by scaling and squaring [Higham 2005]. Within an interval nothing is approximated beyond rounding, so the length of a step does not limit the accuracy of the state it reaches. The simulator still takes short sub-steps, a two-thousandth of the period or shorter, because it has to find the events: a diode could turn on and off again unseen within a long step (how it computes).
A simple rule on a fast time constant
Section titled “A simple rule on a fast time constant”A general-purpose integrator approximates the solution over small steps instead. The simplest rule, forward Euler, steps with the slope at the start of the step, and multiplies a decaying mode’s deviation by a fixed factor in every step [Hairer & Wanner 1996]:
- forward Euler's factor per step
- time step
- time constant
Assumptions, convention and source
- Assumptions
- one decaying mode on its own: its rate of change is minus its deviation over tau (the test equation)
- the same time step every step
- Notes
- the rule takes the slope at the start of the step. Its factor stays between -1 and 1 only while the step is shorter than ; a longer step multiplies the deviation by more than one in size and flips its sign every step, so the solution grows without bound. The circuit's fastest time constant, such as a small node capacitance behind a small resistance, then limits the step for the whole circuit
- Source
- Hairer & Wanner 1996, Sec. IV.2 (Stability Analysis for Explicit RK Methods: explicit Euler); derived here
- Derivation
- step-by-step sympy derivation
- Equation id
num.gain_fe· equations.yaml entry
A step longer than twice the time constant makes the factor larger than one in size, and the solution grows without bound. A converter has fast time constants, such as a small capacitance at the switch node behind a small resistance, next to the slow ones of its output filter: a rule like this would have to take steps shorter than the fastest, over as many periods as the slowest needs. SPICE avoids the blow-up with implicit rules, which keep a decaying mode from growing whatever the step (see the ngspice page).
Events
Section titled “Events”An interval ends when a switch changes state: at the gate’s edges, and when a diode’s current reaches zero or its voltage turns it on. The simulator finds that instant within the step on the same exact solution, so the next interval starts from the right state (how it computes).
The periodic steady state
Section titled “The periodic steady state”In CCM, with a filter that rings, a converter’s output settles from rest with its filter’s envelope time constant (envelope time constant), and reaching a small fraction of the start-up error takes many periods (periods to settle). The simulator looks instead for the state at the start of a period that the period maps back onto itself: the periodic steady state, a fixed point of the map from one period’s initial state to the next. Newton’s method finds it in a few iterations with the map’s derivative, how the state at the end of a period depends on the state at its start [Aprille & Trick 1972]. For a converter that derivative is the product of the steps’ matrices, corrected at every event whose instant depends on the state, such as a diode’s current reaching zero (how it computes). When neither the switching instants nor the order of the intervals depends on the state, as in a buck whose current stays above zero, with no capacitance across its switch, the map is affine, a matrix times the state plus a constant, and a single Newton step lands on the steady state if there is only one.
Worked example
Section titled “Worked example”A capacitance charging towards a voltage with a time constant of ten nanoseconds, stepped by fifty:
| Symbol | Value | How it is obtained |
|---|---|---|
| voltage at the start of the step | 0 V | given |
| voltage it tends to | 10 V | given |
| time constant | 10 ns | given |
| time step | 50 ns | given |
| voltage after the step | 9.93 V | One exact time step of a first-order circuit |
| forward Euler's factor per step | −4 | Forward Euler's factor per step on a decaying mode |
In one step of five time constants, the exact step brings the capacitor from 0 V to 9.93 V. Forward Euler’s factor for the same step is −4: its first step lands four times as far from the final voltage as it started, on the other side, and each further step does the same again.
Try it
Section titled “Try it”▶ Open in the equation explorer: Forward Euler's factor per step on a decaying mode
Preset from the example sim-exact-step
Sweep the step: forward Euler’s factor stays within one in size only below twice the time constant.
▶ Open in the equation explorer: One exact time step of a first-order circuit
Preset from the example sim-exact-step
The exact step approaches the final voltage however long the step is. Open the simulator with the buck example: its steady state is computed directly, without a start-up.
▶ Open in the simulator: Buck
Preset from the example buck-basic
Bench exercise
Section titled “Bench exercise”Charge a capacitor through a resistor from a function generator’s square wave, and capture the capacitor’s voltage. Read it at the start of a half-period and one time constant later, and compare with the exact step. Then take the samples twice the time constant apart and apply forward Euler’s rule by hand from the first one: the first step already overshoots the final voltage, while the circuit does not.
Gotchas
Section titled “Gotchas”- The steady state is not the start-up. Where a steady state exists, the simulator reports it; a start-up or a load step on the bench passes through transients it does not show. It draws the start-up from rest only when it finds no steady state.
- A small step does not make an explicit rule stable by itself. For a mode that decays without ringing, the step must be shorter than twice the fastest time constant, even when that mode is too fast to matter (forward Euler's factor). A lightly damped ring needs a much shorter step still, and an undamped one grows at any step [Hairer & Wanner 1996, Sec. IV.2].
- The plots draw samples. A peak narrower than a sub-step can be in the reported numbers but not in the plot.
Go deeper
Section titled “Go deeper”- Book chapter AC Equivalent Circuit Modeling (Ch. 7)
Averaging, perturbation and linearisation of converter equations, and the small-signal model of the PWM modulator. - Course 6.002 Circuits and Electronics (Spring 2007)
MIT's first circuits course, with video lectures, notes and problem sets.
Why can the simulator step each switching interval exactly?
Answer and explanation
Correct answer: C Every switch and diode is on or off within the interval; the exponential of the circuit's matrix gives the exact solution over any step.
A capacitor charges from 0 V towards 10 V with a time constant of 10 ns. Where is it after an exact step of 10 ns?
Answer and explanation
Correct answer: A The deviation from 10 V shrinks by e in one time constant: 10 V times (1 - 1/e) is about 6.3 V.
Forward Euler steps a mode with a time constant of 10 ns by 50 ns. What does each step multiply its deviation by?
Answer and explanation
Correct answer: C One minus the step over the time constant is 1 - 5: the deviation grows four times over and changes sign in every step.
Up to what step does forward Euler keep a mode that decays without ringing from growing?
Answer and explanation
Correct answer: D The factor, one minus the step over the time constant, stays within one in size only for steps up to twice the time constant; a ringing mode needs a shorter step still.
How does the simulator find the periodic steady state?
Answer and explanation
Correct answer: A The steady state is a fixed point of the map from one period's start to the next; Newton's method finds it with the map's derivative.
For a buck whose current stays above zero, with no capacitance across its switch, how many Newton steps does that take in principle?
Answer and explanation
Correct answer: B Neither the switching instants nor the order of the intervals depends on the state, and Newton's method solves an affine equation in one step if its solution is unique. A diode current reaching zero, or a capacitance across the switch that has to swing first, makes an instant depend on the state, and then it takes a few steps.
The numbers in the examples, presets and exercises on this site are synthetic: round teaching values, not data from any real design.