# Discrete Integrator (`dIntegrator`)

> Adds up its input over time, one sample at a time.

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

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

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

## When to use it

Use it for a sampled integral, such as an angle from speed. Use Integrator for a continuous design.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `in` | signal | Signal to integrate |
| `out` | signal | Integral, limited to lo and hi |

## Common parameters

- `ts`: Time between samples (Default: required)
- `k`: How fast the output builds up (Default: 1)
- `lo`: Lowest value the output can reach (Default: -1e30)
- `hi`: Highest value the output can reach (Default: 1e30)
- `x0`: Initial output (Default: 0)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `ts` | s | required |  | Time between samples |
| `offset` | s | 0 |  | Time of the first sample |
| `k` | 1/s | 1 |  | How fast the output builds up |
| `method` | — | forward |  | Calculation method for the integral: `forward`, `backward` or `tustin` |
| `lo` | — | -1e30 |  | Lowest value the output can reach |
| `hi` | — | 1e30 |  | Highest value the output can reach |
| `x0` | — | 0 |  | Initial output |

_Parameter descriptions are in English in both languages._

## Model

With area = k·ts, forward gives x[k] = x[k-1] + area·u[k-1] with the output x[k-1], so it has no direct feedthrough. backward gives x[k] = x[k-1] + area·u[k] and tustin uses the average of u[k] and u[k-1]; both have feedthrough. The state is clamped to lo ... hi at each step, which is also the anti-windup. The output is x0 (clamped) before the first instant.

## Common mistakes

- Here method starts at forward, but in Discrete PI Controller and Discrete PID Controller it starts at backward. Forward lags the input by one sample, so choose backward or tustin when that matters and no loop closes through this block.
- k is per second. lo and hi start at plus and minus 1e30, so a constant offset in the input makes the output drift without limit; set the limits or remove the offset.

## Datasheet and sources

ts is the firmware loop period, 1/fs. k is the integral gain from your design, and it is 1 for a speed-to-angle integrator. lo and hi are the register range or the physical limit, and x0 is the value the firmware starts with.

## Example

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

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