# Carrier (`carrier`)

> A triangle or sawtooth wave between 0 and 1 for PWM.

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

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

**Group:** Control · **Kind:** `{"block":"carrier","kind":"control"}`

## When to use it

Use it to compare a reference with a carrier in your own Comparator, or to share one carrier among gates. PWM Generator already has one.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `phase` | signal | Optional phase input in degrees; while wired it replaces the `phase` parameter (phase-shifted bridges). |
| `freq` | signal | Optional frequency input in Hz; while wired it replaces `freq` and the carrier integrates it, so the frequency may change without a jump. |
| `out` | signal | Carrier wave between 0 and 1 |

## Common parameters

- `freq`: Carrier frequency; a wired freq input replaces it (Default: required)
- `shape`: Triangle or sawtooth wave shape: `triangle` or `sawtooth` (Default: triangle)
- `phase`: How far the wave is shifted, as a fraction of one period; a wired phase input (degrees) replaces it (Default: 0)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `freq` | Hz | required |  | Carrier frequency; a wired freq input replaces it |
| `shape` | — | triangle |  | Triangle or sawtooth wave shape: `triangle` or `sawtooth` |
| `phase` | — | 0 |  | How far the wave is shifted, as a fraction of one period; a wired phase input (degrees) replaces it |

_Parameter descriptions are in English in both languages._

## Model

With `x` the position in the present period (0 to 1, shifted by `phase`), a `triangle` carrier is `2*x` for `x < 0.5` and `2 - 2*x` after, so it starts at 0, peaks at 1 at half a period and returns to 0. A `sawtooth` ramps from 0 to 1 and falls back at each period. The frequency is `freq` in Hz and `phase` is a fraction of one period. A wired `phase` input (degrees, divided by 360) and a wired `freq` input replace the parameters; with `freq` wired the position in the period is the integral of the frequency.

## Common mistakes

- A carrier much faster than the step cannot be resolved. Keep the maximum step at or below one fiftieth of the carrier period, which is 1 us at 20 kHz.
- Write the frequency with its prefix, 20k and not 20. The carrier runs from 0 to 1, so a reference between -1 and 1 must first become a duty, for example with Space-Vector Modulator set to duty.

Problems rules: `step.too_large`, `param.out_of_range`

## Datasheet and sources

No datasheet applies. The value of freq is the switching frequency you chose, usually limited by device switching loss and the MCU timer, and phase lets you interleave several carriers.

## Example

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

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