# Worked example: a 12 V to 8 V flyback converter

The `flyback` example runs a 1:1 coupled inductor at a duty cycle of 0.4 and 100 kHz from 12 V into a 20 Ω load. By hand, the output is 8 V, the primary current peaks at 1.14 A and the converter stays in continuous conduction. The run gives 7.94 V, a 1.15 A peak and 0.19 A still flowing in the secondary when the switch turns on again. It also shows a 57.6 V spike on the drain, where the ideal plateau is 20 V: the leakage inductance.

## Open it

In the app: **File › Open Example › Isolated › Flyback converter**, then press **F5**. From the command line:

```sh
powercraft-cli run --cmd file.openExample --params '{"name": "flyback"}' \
  --cmd simulation.run \
  --cmd scope.measure --params '{"signals": ["v(out)", "i(T1.1)", "v(drain)"], "t0": 0.0029, "t1": 0.003}'
```

![The flyback example: a 12 V source, the coupled inductor T1 (50 µH each side, coupling 0.995), switch S1 with an RC snubber (2 nF, 50 Ω) on its drain, diode D1, C1 = 47 µF and a 20 Ω load, driven at a constant duty of 0.4 and 100 kHz.](https://voltecx-web.nguyenvanqui291.workers.dev/media/worked-examples/flyback-converter-12v-to-8v/schematic.svg)

| Part | Value |
| --- | --- |
| Input $V_{in}$ | 12 V |
| Coupled inductor T1 | 50 µH : 50 µH ($n = 1$), $k = 0.995$ |
| Duty cycle $D$ | 0.4 (open loop) |
| Switching frequency $f_{sw}$ | 100 kHz |
| Snubber | 2 nF in series with 50 Ω, drain to ground |
| Output | C1 = 47 µF (starts at 8 V), R1 = 20 Ω |

## The hand calculation

A flyback stores energy in the magnetising inductance while the switch is on and releases it to the output while the switch is off. In continuous conduction, the volt-second balance gives

$$V_{out} = n\,V_{in}\,\frac{D}{1 - D} = 12 \times \frac{0.4}{0.6} = 8\ \text{V}$$

The magnetising inductance is about $k\,L_1 = 49.75$ µH. During the on-time it ramps by

$$\Delta I = \frac{V_{in}\,D}{f_{sw}\,L_m} = \frac{12 \times 0.4}{100\ \text{kHz} \times 49.75\ \mu\text{H}} = 0.965\ \text{A}$$

All the output current passes through the secondary during the off-time, so the magnetising current (referred to the primary) averages $I_{out}/(1 - D)$. With the run's 7.94 V, $I_{out}$ = 0.397 A and that average is 0.661 A. The ramp then runs from

$$0.661 - \frac{0.965}{2} = 0.18\ \text{A} \quad\text{to}\quad 0.661 + \frac{0.965}{2} = 1.14\ \text{A}$$

The valley is above zero, so the core never empties: continuous conduction. When the switch is off, the drain sits at $V_{in} + V_{out}/n = 20$ V.

## The run

The example runs for 3 ms; the measurements are over the last ten periods.

| Quantity | Hand | Run |
| --- | --- | --- |
| Mean output voltage | 8 V (ideal) | 7.94 V |
| Peak primary current | 1.14 A | 1.15 A |
| Secondary current when the switch turns on | 0.18 A | 0.19 A |
| Drain voltage, off-time plateau | 20 V | 20 V |
| Drain voltage, peak | — | 57.6 V |

![Three periods at the end of the run: the drain voltage v(drain) with a spike at each turn-off and a 20 V plateau, the primary current i(T1.1) ramping to 1.15 A while the switch is on, the secondary current i(D1) ramping down to 0.19 A while it is off, and the output v(out).](https://voltecx-web.nguyenvanqui291.workers.dev/media/worked-examples/flyback-converter-12v-to-8v/steady-state.svg)

The output is 0.8 % below the ideal 8 V: the formula has no leakage inductance, no snubber and no on-resistance. The drain spike is the leakage inductance. With $k = 0.995$, a small part of the primary inductance is not coupled to the secondary. When the switch opens, the current in it has nowhere to go but the snubber capacitor, and at the edge the drain jumps to 57.6 V, the 1.15 A of the primary current times the 50 Ω snubber resistor, before the snubber capacitor takes over and the drain settles to the plateau. A real design sizes the switch's voltage rating for that spike, not for the 20 V plateau.

## Try next

- Change k to 0.98 and run again: more of the primary is leakage. Compare the drain spike and the output with this run.
- Raise R1 to 100 Ω. The average magnetising current falls below half the ripple, the secondary current reaches zero before the period ends, and the converter enters discontinuous conduction.
- Read [the flyback transformer design steps](https://voltecx-web.nguyenvanqui291.workers.dev/blog/flyback-transformer-design-steps) to choose n, $L_m$ and the core for a real specification.

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.
