# Transformer (`transformer`)

> A transformer with turns ratio n, and optional magnetizing inductance, leakage, winding resistance, core loss and saturation.

![transformer](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/transformer.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/magnetics/transformer/)

**Group:** Magnetics · **Kind:** `{"kind":"transformer"}`

## When to use it

Use it for isolation and voltage scaling. Leave the optional parameters unset for an ideal part, or set llk1, rw1 and the others to see the leakage spike, the copper loss and the magnetizing current.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `p1` | electrical | Primary, dotted end; positive current enters here |
| `n1` | electrical | Primary, other end |
| `p2` | electrical | Secondary, dotted end |
| `n2` | electrical | Secondary, other end |

## Common parameters

- `n`: Turns ratio, first side to second side (Default: 1)
- `lm`: Inductance that magnetizes the core (Default: optional (off))

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `n` | — | 1 |  | Turns ratio, first side to second side |
| `lm` | H | optional (off) |  | Inductance that magnetizes the core |
| `im0` | A | 0 |  | Magnetizing current at the start, seen from the first side; needs lm or a core |
| `llk1` | H | 0 | 1n – 1m H | Leakage inductance in series with the first winding |
| `llk2` | H | 0 | 1n – 1m H | Leakage inductance in series with the second winding |
| `rw1` | Ω | 0 | 100u – 1 Ω | Wire resistance of the first winding |
| `rw2` | Ω | 0 | 100u – 1 Ω | Wire resistance of the second winding |
| `rcore` | Ω | optional (off) | 100 – 10meg Ω | Resistance across the first winding that models core loss |
| `isat` | A | optional (off) | 10m – 200 A | Magnetizing current where the core saturates; needs lm |
| `lmsat` | H | optional (off) | 1n – 10 H | Magnetizing inductance once the core is saturated; a fifth of lm when unset |
| `core` | — | optional (off) |  | Core from the catalogue; it sets the inductance curve and the core loss |
| `material` | — | optional (off) |  | Core material; needed when core names a shape |
| `turns` | — | optional (off) |  | Turns of the first winding |
| `gap` | m | optional (off) |  | Air gap in the core; unset uses the catalogue core's gap |
| `fsw` | Hz | optional (off) |  | Switching frequency; core and winding losses are worked out once per period |
| `coreTemp` | °C | 25 |  | Core and winding temperature |
| `coreAe` | m² | optional (off) |  | Effective area of a core you describe yourself; use with coreLe instead of core |
| `coreLe` | m | optional (off) |  | Magnetic path length of a core you describe yourself; use with coreAe |
| `coreVe` | m³ | optional (off) |  | Volume of that core for its core loss; coreAe times coreLe when unset |
| `bhCurve` | — | optional (off) |  | B-H curve of the core; pairs H:B in A/m and T, such as 0:0, 50:0.3, 200:0.45; replaces the material's curve |
| `psiCurve` | — | optional (off) |  | Flux linkage of the winding against its current from a field solve; pairs i:λ in A and Wb, such as 0:0, 1:2e-3, 4:5e-3 (odd about zero current), or from a negative current through 0 for a magnet-biased winding, such as -4:-1e-3, 0:2e-3, 4:4e-3; replaces the core's curve |
| `steinmetzK` | W/m³ | optional (off) |  | Steinmetz k of the core loss k·f^α·B^β, with f in Hz and B the peak flux density in T |
| `steinmetzAlpha` | — | optional (off) |  | Steinmetz α, the frequency exponent of the core loss |
| `steinmetzBeta` | — | optional (off) |  | Steinmetz β, the flux-density exponent of the core loss |
| `magneticsDesign` | — | optional (off) |  | Saved design from magnetics.design; the separate core parameters win over it |
| `surface` | m² | optional (off) |  | Outside surface of the wound part to the air; design.thermal gives its temperature rise from it and the loss |
| `coupledCurve` | — | optional (off) |  | Incremental inductances of the two windings against the core's magnetizing current from a field solve; rows i:L11:M:L22 in A and H from 0 A, such as 0:1e-3:4.8e-4:2.5e-4, 0.4:2e-4:8e-5:5e-5; the whole magnetic model in place of n, lm and the core, with leakage, winding resistance and rcore still added |

_Parameter descriptions are in English in both languages._

**Use for:** Isolation · Isolated DC-DC stages · Gate-drive transformers

**Not for:** Three-phase transformers → [`transformer3`](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/magnetics/transformer3/) · Current sensing → [`currentTransformer`](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/ic/currentTransformer/)

## Formulas

| Formula | Equation | Source |
|---|---|---|
| Secondary voltage | v2 = v1 / n | Hayt, Kemmerly & Durbin, Engineering Circuit Analysis, 8th ed. (2012), ch. 13 (the ideal transformer) |
| Load reflected to the primary | zin = n²·rl | Hayt, Kemmerly & Durbin, Engineering Circuit Analysis, 8th ed. (2012), ch. 13 (impedance matching) |
| Magnetizing current ripple | Δim = v1·ton / lm | Erickson & Maksimović, Fundamentals of Power Electronics, 3rd ed. (2020), §6.3 (transformer isolation, magnetizing inductance) |

## Quick check

Inputs:

- `n`: Turns ratio N1/N2 = 4 —, `n`
- `v1`: Primary voltage = 48 V
- `rl`: Secondary load = 2 Ω
- `lm`: Magnetizing inductance = 500u H, `lm`
- `ton`: Time the voltage is applied = 5u s

Outputs:

- `v2`: Secondary voltage = `v1/n` V
- `zin`: Reflected load = `n^2*rl` Ω
- `dim`: Magnetizing current ripple = `v1*ton/lm` A

## Model logic

- The ideal windings are one extra branch current that forces v1 = n·v2 and i2 = −n·i1, so on its own the part passes DC.
- rw1 and llk1 sit in series on the primary and rw2 and llk2 on the secondary; zero leaves each one out, and leakage starts with no current.
- With lm set, an inductor across ideal winding 1 starts at im0, and rcore sits across it; without lm there is no magnetizing current at all.
- isat makes lm a two-slope knee (lmsat, or 0.2·lm, above it) by the previous accepted current; a catalogue core replaces it with its curve.

## Model

The ideal windings obey v1 = n * v2 with n = N1 / N2, and the currents obey i2 = -n * i1 when both are positive into the dotted ends. rw1 and llk1 sit in series between p1 and ideal winding 1, and rw2 and llk2 between p2 and ideal winding 2, so each side's leakage and resistance is on its own side. With lm set, an inductor of that value sits across ideal winding 1 and carries the magnetizing current, and rcore sits across it for core loss. When isat is set, the magnetizing inductance is lm while its current magnitude stays below isat and lmsat above it (0.2 * lm when lmsat is unset), the same two-slope knee as the Inductor. With every optional parameter unset, the part is ideal and simulates exactly as before.

## Common mistakes

- n is N1 / N2, so a 10 to 1 step-down uses n = 10, and 0.1 steps the voltage up. Check the ratio against the rated primary and secondary voltages.
- The secondary has no reference unless something in it touches ground. A DC component on the primary drives the lm current up without limit unless isat is set, and even then lmsat only slows it.
- Leakage inductance stores energy each time the primary current is cut, about 0.5 * llk1 * i^2. A flyback with llk1 and no clamp or snubber across the switch shows a very high turn-off spike. isat needs lm, because it saturates the magnetizing inductance.

Problems rules: `island.floating`, `param.out_of_range`

## Datasheet and sources

n is the rated primary voltage divided by the rated secondary voltage, or the ratio of turns. lm is the primary inductance measured with the secondary open. llk1 is the leakage inductance measured on the primary with the secondary shorted; put it all on the primary with llk2 at zero unless the split is known. rw1 and rw2 are the DC resistances of each winding, isat is the magnetizing current where the inductance has dropped by the stated percentage, and rcore is a one-frequency estimate of core loss.

## Example

Open the example with the command `file.openExample` and the name `demo:transformer`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
