# Flyback: design the transformer

A flyback stores energy in its coupled inductor while the switch is on and passes it to the output while it is off. Here you simulate the flyback example, let `magnetics.design` pick a core, the turns, the wire and the air gap from the simulated currents, write the result into the circuit and check it. About 10 minutes.

Pictures: a numbered red box is what you click or read, `[Run]` is a button, `Design › Automate` a menu path, `F5` a key.

## 1. Open the flyback example

Choose `File › Open Example › Isolated › Flyback converter`.

![The File menu open at Open Example, Isolated, Flyback converter, marked 1 to 4](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/01-open-example.png)

1. `File`.
2. `Open Example`.
3. `Isolated`.
4. `Flyback converter`.

## 2. Read the circuit

![The flyback schematic with T1, S1, D1 and C1, marked 1 to 4](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/02-schematic.png)

1. `T1`: the coupled inductor, 50 µH on each side (1:1), coupling 0.995.
2. `S1`: the switch, at 100 kHz and a duty of 0.4.
3. `D1`: the output diode.
4. `C1`: the 47 µF output capacitor, with a 20 Ω load.

The 12 V source `Vin` and an RC snubber (`Csn`, `Rsn`) complete the circuit.

## 3. Simulate it first

Press `F5` (or `[▶ Run]`). The magnetics design reads the winding currents from this run.

![The scope in the panel after the first run, v(out), marked 1](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/03-run.png)

1. `v(out)` settles near 7.9 V.

## 4. Open Design Magnetics

Choose `Design › Automate › Design Magnetics`.

![The Design menu open at Automate, Design Magnetics, marked 1 to 3](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/04-menu.png)

1. `Design`.
2. `Automate`.
3. `Design Magnetics`.

## 5. Check the spec

The Design page opens at `Magnetics`. Every field may stay empty: the part is the only magnetic part, `T1`, and the currents come from the last run.

![The Magnetics task of the Design page, marked 1 to 3](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/05-form.png)

1. `Magnetics`, the task.
2. `Part kind`: `Auto` designs `T1` as the coupled inductor it is.
3. Click `[Run]`.

## 6. Read the design and apply it

The result shows beside the spec. Collapse the bottom panel (`↓` at its top right) to see all of it, then click `[Apply]`: the design is written into `T1` as one undo step, and the circuit is simulated again with the new part to check it. The best fit is picked in the `Core` table; pick another row's round button first to apply that core instead. A greyed `[Apply]` says why when you point at it.

![The result: loss, temperature, peak flux, Verified, and the chosen core, marked 1 to 5](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/06-result.png)

1. The total loss of the best candidate: 37.4 mW.
2. Its temperature: 42.06 °C at 40 °C ambient.
3. Its peak flux density: 132.7 mT, well below the 503 mT where the ferrite saturates.
4. The check: `✔ Verified`.
5. The core it chose.

**Result:** the best candidate is an EFD 20/10/7 core in Ferroxcube 3C95 ferrite with 14 turns on each side of 10 × 0.1 mm litz (three strands in parallel on the primary, four on the secondary), wound on its CSH-EFD20-1S-8P coil former, and a 0.163 mm gap, for 49.5 µH. It loses 37 mW, runs at 42 °C at 40 °C ambient and peaks at 133 mT, well below saturation. The check says `✔ Verified`. Scroll down for the changes it made, each check, every number and the other candidates.

The candidates are ranked by the size of the core, the smallest first, then by loss. To see the larger core with the least loss, set `Rank cores by` to `Least loss`, or type a shape from the catalogue into `Shape` under `Advanced` (besides the E pairs and rings, ETD, PQ, RM, EFD and planar sets such as `ETD 34/17/11`, `PQ 26/25` or `E 32/6/20`, read from the Ferroxcube and TDK data sheets), and run again. The notes at the bottom are worth reading: the catalogue is a starter set, so check the core, gap and wire against the maker's data sheet.

The page also draws the winding as a cross-section: the core side on the left, each layer coloured by its winding, and a line for the magnetomotive force across the window. Hover a layer to see its turns, its Dowell factor and its loss; the table under it lists every layer. For a transformer, `Winding order` picks `P/S`, or `P/S/P` to split the primary around the secondary: the result then names the other arrangement beside the chosen one with its winding loss and leakage, so you can see what interleaving would save.

## 7. Simulate with the designed part

Close the Design page with the `×` on its tab, open the bottom panel again and press `F5`.

![The scope in the panel after the second run, v(out), marked 1](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/img/en/flyback-magnetics/07-rerun.png)

1. `v(out)` settles near 7.9 V with the designed `T1` (its inductances and coupling now come from the core and the winding).

## The same steps from a script

```sh
powercraft-cli run \
    --cmd file.openExample  --params '{"name":"flyback"}' \
    --cmd simulation.run    --params '{}' \
    --cmd magnetics.design  --params '{"apply":true,"verify":true}' \
    --cmd simulation.run    --params '{}' \
    --cmd scope.measure     --params '{"signals":["v(out)"],"t0":"2m"}'
```

## Your own cores and materials

If your core, material or wire is not in the catalogue, import its OpenMagnetics MAS records (a vendor's MAS file, or records you write from the data sheet) with `magnetics.importMas`. Every record is checked first, and a bad value is refused with its field named. `magnetics.design` then searches your records beside the built-in ones and marks a design that uses one as user data (`userData`). The desktop app keeps them in `library/magnetics.json` in its settings folder. On the command line, `--root .` lets the chain read the file from the current folder:

```sh
powercraft-cli run --root . \
    --cmd magnetics.importMas --params '{"path":"my-ferrite.ndjson"}' \
    --cmd magnetics.library   --params '{"source":"user"}'
```

If the data sheet plots the material's loss but gives no Steinmetz coefficients, read a few sine-loss points off its curves, at two or more frequencies and two or more flux densities, and fit them with `magnetics.steinmetzFit`. It returns `k`, `alpha` and `beta` (W/m³, Hz, T peak) with the error of the fit at every point (`errorPct`, `maxErrorPct`) and the range the fit holds over. Fit each frequency range on its own points, because a ferrite's α and β change with frequency:

```sh
powercraft-cli run --cmd magnetics.steinmetzFit --params '{"lossUnit":"kW/m3","points":[
  {"frequencyHz":50e3,"bPeakT":0.1,"loss":20},{"frequencyHz":100e3,"bPeakT":0.1,"loss":50},
  {"frequencyHz":100e3,"bPeakT":0.2,"loss":300},{"frequencyHz":200e3,"bPeakT":0.1,"loss":130}]}'
```

The points above only show the format. Read yours from your data sheet.

Next: [boost and buck-boost](https://voltecx-web.nguyenvanqui291.workers.dev/docs/tutorials/04-boost-buck-boost/).
