Skip to content

The converters in CircuitJS1

  • Open the SPICE library’s circuits in CircuitJS1 and read their scopes.
  • Know how CircuitJS1 steps a circuit, and what can happen within a step where a diode stops conducting.
  • Tell a numerical spike from the circuit’s own, and know why the library’s circuits carry body diodes, backward Euler magnetics and a coupling just below one.

CircuitJS1 is Paul Falstad’s circuit simulator, adapted to the browser by Iain Sharp [Falstad & Sharp, CircuitJS1 browser circuit simulator]: it runs a circuit in the page and animates the currents through it. The repository’s sim/falstad/ folder has the SPICE library’s seven cases as CircuitJS1 circuits, each as a text file (File > Import From Text) and as a link that opens it on falstad.com. The link carries the whole circuit, compressed into its address [Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js]. A script writes every circuit from the list of parts behind the SPICE netlist of the same name, with the same example’s values, and checks that each part joins the same nodes as in the netlist.

CaseCircuitIdeal values the CI compares with
Buck converter, CCM
simulator preset: buck-basic
Open in CircuitJS1
output voltage: average 12 V
inductor current: average 1.2 A, max 1.5 A, min 900 mA
switch node: max 24 V
Buck converter, DCM
simulator preset: buck-light-load
Open in CircuitJS1
output voltage: average 15.74 V
inductor current: average 157.4 mA, max 413 mA, min 0 A
switch node: max 24 V
Boost converter, CCM
simulator preset: boost-ideal
Open in CircuitJS1
output voltage: average 24 V
inductor current: average 2.4 A, max 2.7 A, min 2.1 A
switch node: max 24.3 V
Buck-boost converter (inverting), CCM
simulator preset: buckboost-basic
Open in CircuitJS1
output voltage: average −12 V
inductor current: average 2.4 A, max 2.7 A, min 2.1 A
switch node: max 12 V, min −12.3 V
Flyback converter, CCM
simulator preset: flyback-ccm
Open in CircuitJS1
output voltage: average 8 V
drain: max 80.13 V
Flyback converter, DCM
simulator preset: flyback-dcm
Open in CircuitJS1
output voltage: average 20.36 V
drain: max 129.5 V
Forward converter with a reset winding, CCM
simulator preset: forward-basic
Open in CircuitJS1
output voltage: average 9.6 V
inductor current: average 1.92 A, max 2.208 A, min 1.632 A
drain: max 96 V

The scopes along the bottom show the inductor current (in the flyback, the switch current), the switch node or the drain, and the output. A circuit opens at about one switching period a second, with current dots slow enough to follow; the Simulation Speed slider runs it faster. It starts from the ideal steady state’s values, the output capacitor at the output voltage and the inductor (the flyback’s magnetizing inductance) at its current when the switch turns on, so the scopes show the steady state within the first periods. Reset returns the capacitor and inductor to these values. For values of your own, set them in the site’s simulator and open its link Open these values in CircuitJS1: the same circuit, built from the form (the same circuits).

The site’s CI opens a copy of every link on falstad.com in a headless browser, the same circuit with only its speed raised. It runs the copy for as many periods as the SPICE case and compares the averages and extremes of its last two periods with the ideal values in the table: each must lie within one percent of its quantity’s largest magnitude over those periods.

CircuitJS1 advances the whole circuit by one fixed time step at a time. It halves the step only when its iteration fails to converge, and then only if Auto-Adjust Timestep is on in Other Options [Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js]. The library’s circuits leave it off and step a five-hundredth of the switching period. SPICE instead chooses each step from an estimate of its error [The ngspice team, Ngspice User's Manual]; CircuitJS1 does not look for the instant a diode starts or stops conducting.

In every step each inductor becomes a companion model, a conductance in parallel with a current source. The model follows the trapezoidal rule unless the inductor’s Trapezoidal Approximation box is unchecked, which selects backward Euler, and a transformer’s windings work the same way [Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js]. A diode is nonlinear, so CircuitJS1 iterates: it replaces the diode by a straight line at its present voltage, solves the circuit, and repeats. It counts the diode as converged once its voltage changes by no more than 10 mV from one iteration to the next [Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js], and then keeps the solution it has without solving again.

The library’s diodes are near ideal: a change of their voltage far smaller than what the iteration accepts changes their current many times over. When a diode’s current reaches zero within a step, the straight line that stands for the diode can still carry current past zero, for that step and perhaps the next, and the inductor’s current ends below zero. In the library’s DCM buck it goes past zero by a little more than it changes in one step. Once the iteration finds the diode off, and nothing else takes the current, the next step has to bring the current back to zero, and backward Euler puts across the inductor, for that one step:

vjump=LIosΔtv_\mathrm{jump} = \frac{L I_\mathrm{os}}{\Delta t}
vjumpv_\mathrm{jump}
one-step voltage jump
Δt\Delta t
time step
IosI_\mathrm{os}
current past zero
LL
inductance
Voltage of a backward Euler step that stops an inductor's current✓ verified by 8 tests
Assumptions, convention and source
Assumptions
  • backward Euler: the inductor's voltage at the end of the step is its inductance times the change of its current, divided by the step
  • the current's path opens within the step, and nothing else (a body diode, a snubber, a node capacitance) takes the current
  • the same time step every step
Notes
a step can end with an inductor's current past zero through a diode, as when the iteration accepts the diode's straight-line model before its current has settled. When the diode then turns off and nothing else takes the current, the next step has to bring the current from −Ios-I_\mathrm{os} back to zero, and backward Euler puts this voltage across the inductor for that step: the node the current leaves ends up this far from the inductor's other end. The circuit has no such spike, and a shorter step does not remove it: the overshoot shrinks with the step, so the jump stays about as large as the voltage the inductor had across it before. The same step stops a leakage inductance's current when a switch opens with nothing to take its current (a body diode across the switch is reverse-biased then); that current does not shrink with the step, so that spike grows as the step shrinks. A diode across the node bounds the jump to a diode drop past a rail; a capacitance at the node, stepped by backward Euler, takes the current without a jump
Source
Alexander & Sadiku 2017, Ch. 6 (Capacitors and Inductors: v = L di/dt, and the current through an inductor cannot change abruptly); derived here; Hairer & Wanner 1996, Sec. IV.3 (implicit Euler takes the slope at the end of the step); Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js, Inductor.java: the backward Euler companion model, a resistance L over the time step in parallel with the previous current
Derivation
step-by-step sympy derivation
Equation id
sim.step_jump · equations.yaml entry

The node the current leaves ends up that far from the inductor’s other end: in the DCM buck without its body diode, the switch node leaps for one step from near zero to that much above the output, about ten volts above the input, a spike the circuit does not have. A shorter step does not remove it. The current’s overshoot is about its change in one step, so it shrinks with the step, and the jump stays about as large as the voltage the inductor had across it before the diode turned off, the output voltage in the buck: with the step halved and halved again, the DCM buck’s jump stayed between about 0.7 and 1.4 times its output voltage.

The library’s circuits therefore give each switch a body diode, as the site’s simulator has. It bounds the jump without removing it: the current past zero flows through it, so a node goes no further than a diode drop past a rail. The DCM buck’s switch node stops a diode drop above the input for a few steps, then dips below the output for one step as the body diode’s own current goes past zero. The DCM flyback’s drain, which falls back to the input when the diode turns off, can dip for a step, but no further than a diode drop below ground, where without the body diode it reaches far below. A capacitance at the node, stepped by backward Euler, takes the current without a jump.

CircuitJS1’s transformer inverts the matrix of its windings’ inductances, which is singular when the coupling is exactly one, and its dialog accepts a coupling only between zero and one [Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js]. The library’s transformers use 0.99999. The leakage inductance left adds a spike to the drain for one step at turn-off, as the switch stops its current within that step (one-step jump, with the leakage inductance the switch’s current flows through and the current it interrupts). That current does not shrink with the step, so the spike, less than a volt at the library’s step, is proportional to one minus the coupling and to one over the step.

That leakage is also a mode far faster than the step, and the trapezoidal rule’s factor for such a mode is close to minus one (the trapezoidal rule's factor): it rings from one step to the next. With the Trapezoidal Approximation box ticked, while the output diode conducts, the DCM flyback’s drain alternates at every step between about twice the level it should show and zero. The library’s inductors and transformers therefore use backward Euler, whose factor for such a mode is close to zero (backward Euler's factor).

The library’s DCM buck steps its inductor with backward Euler. Take its body diode away, and the current past zero when the freewheeling diode turns off has to stop within one step:

DCM buck example in CircuitJS1: the jump without a body diode
SymbolValueHow it is obtained
LL inductance100 µHgiven
IosI_\mathrm{os} current past zero3.7 mAgiven
Δt\Delta t time step20 nsgiven
vjumpv_\mathrm{jump} one-step voltage jump18.5 VVoltage of a backward Euler step that stops an inductor's current

The switch node jumps 18.5 V above the output, which sits at 15.7 V, so for one step it shows about ten volts above the input. With the body diode in place, the current flows back to the input through it, and the switch node stops a diode drop above the input for a few steps.

▶ Open in the equation explorer: Voltage of a backward Euler step that stops an inductor's current
Preset from the example falstad-jump

For a given step, the jump grows in proportion to the current past zero. Then see it in CircuitJS1: open the DCM buck from the table, select the diode across the switch and delete it, and watch the switch node’s scope spike at the end of each diode conduction. Change the time step in Other Options: the spike stays. In the DCM flyback, double-click the transformer and tick Trapezoidal Approximation: the drain’s scope fills with the step-by-step alternation. The site’s simulator finds the instant a diode’s current reaches zero within its step (how it steps), so it shows neither:

▶ Open in the simulator: Buck
Preset from the example buck-light-load

Capture a DCM converter’s switch node on the bench as the diode stops conducting: the inductance rings with the capacitance at the switch node (ringing frequency). Work out that capacitance from the ring’s frequency and the inductance. In CircuitJS1, give the library’s DCM buck your converter’s values, add the capacitance from the switch node to ground with its Trapezoidal Approximation box unchecked, and set a time step short enough to resolve the ring, a small fraction of its period. The switch node now leaves zero smoothly and rings at the bench’s frequency, clipped by the body diode at the input if it swings that far. Compare the frequency, not the decay: backward Euler damps an oscillation by itself, as its factor for an oscillation is below one in size [Hairer & Wanner 1996, Sec. IV.3], and the fewer steps a ring period spans, the sooner the simulated ring dies out.

  • A spike that lasts one step, and changes when the step changes, is numerical: look for a current with nowhere to go (one-step jump) before you look for a cause in the circuit.
  • A node that alternates at every step is the trapezoidal rule on a mode far faster than the step. Uncheck Trapezoidal Approximation on the inductors, transformers and capacitors in that mode.
  • A coupling of exactly one cannot be entered: the dialog refuses it [Falstad & Sharp, CircuitJS1 source code, version 4.1.5.1js]. Use a value just below one, and expect a small leakage spike at turn-off.
  • A diode with a steep curve converges loosely. The iteration stops on a change of voltage, not of current, so a near-ideal diode can end a step with the inductor’s current well past zero. Give the current a path: a body diode bounds the jump, and a node capacitance stepped by backward Euler (Trapezoidal Approximation unchecked) removes it.
  • Tool CircuitJS1 circuit simulator — P. Falstad (the original Java applet), I. Sharp (the port to the browser) · retrieved 2026-09-24
    A circuit simulator in the browser that animates the currents; good for a first look at a converter.
  • Tool CircuitJS1 source code — P. Falstad, I. Sharp · retrieved 2026-09-25
    The simulator's source: how it steps in time, and how it models its inductors, transformers and diodes in each step.
  • Tool Circuit Simulator JavaScript Interface Documentation — the CircuitJS1 project · retrieved 2026-09-25
    How a web page runs the simulator from JavaScript and reads its node voltages and currents after every step, as the site's CI does to check the library's circuits.
  1. How does CircuitJS1 advance the library's circuits in time?

    1. By steps it chooses from an estimate of its error, as SPICE does
    2. By one fixed step, a five-hundredth of the switching period; it would halve the step only on a convergence failure with Auto-Adjust Timestep on
    3. By a step it shortens at every diode turn-off
    4. By one step per switching period
    Answer and explanation

    Correct answer: B CircuitJS1 keeps its time step fixed. It halves it only when its iteration fails to converge, and only with Auto-Adjust Timestep on, which the library's circuits leave off; nothing shortens a step where a diode turns off.

  2. A 100 µH inductor steps by backward Euler with a 20 ns step. When its diode turns off, its current is 3.7 mA past zero and nothing else takes it. How large is the one-step jump across the inductor?

    1. 0.74 V
    2. 18.5 V
    3. 37 V
    4. 185 V
    Answer and explanation

    Correct answer: B The step must bring the current back to zero, so the inductor carries L times the current over the step: 100 µH times 3.7 mA over 20 ns is 18.5 V.

  3. You halve the time step to get rid of that spike. What happens to it?

    1. It halves
    2. It doubles
    3. It stays of the same order, because the current past zero shrinks with the step
    4. It disappears
    Answer and explanation

    Correct answer: C The current goes past zero by about its change in one step, which halves with the step, while the shorter step doubles the voltage for a given current. The jump stays about as large as the voltage the inductor had across it before the diode turned off: in the library's DCM buck, between about 0.7 and 1.4 times the output voltage.

  4. What do the library's circuits add so that a node cannot jump far outside the supply when a diode turns off?

    1. A shorter time step
    2. A body diode across each switch
    3. The trapezoidal rule for the inductors
    4. A coupling of exactly one
    Answer and explanation

    Correct answer: B The current past zero flows through the body diode, so the node goes no further than a diode drop past a rail; a one-step dip within the rails can remain. A shorter step does not help, and a capacitance at the node, stepped by backward Euler, is what takes the current without any jump.

  5. With Trapezoidal Approximation ticked on its transformer, the DCM flyback's drain alternates at every step, while the output diode conducts, between about twice its expected level and zero. Why?

    1. The leakage inductance rings with the switch's capacitance
    2. The trapezoidal rule meets a mode far faster than the step, and its factor per step for that mode is close to minus one
    3. The body diode conducts at every other step
    4. The output capacitor's series resistance
    Answer and explanation

    Correct answer: B The leakage inductance makes a mode far faster than the step. The trapezoidal rule multiplies it by nearly minus one in every step, so it flips its sign without decaying; backward Euler's factor for it is close to zero.

  6. Why do the library's transformers use a coupling of 0.99999 rather than 1?

    1. To model a real transformer's leakage
    2. CircuitJS1 inverts the windings' inductance matrix, which is singular at a coupling of one, and its dialog accepts only values below one
    3. A coupling of one would slow the simulation down
    4. To damp the ringing of the drain
    Answer and explanation

    Correct answer: B The determinant L1 L2 - M^2 of the inductance matrix vanishes at a coupling of one, so the matrix cannot be inverted. The leakage that 0.99999 leaves adds a one-step spike to the drain at turn-off, less than a volt at the library's step, as the switch stops the leakage inductance's current within that step.

The numbers in the examples, presets and exercises on this site are synthetic: round teaching values, not data from any real design.