# Stepper Motor (`stepper`)

> A two-phase hybrid stepper motor with a magnet rotor.

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

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

**Group:** Machines · **Kind:** `{"kind":"machine","model":"stepper"}`

## When to use it

Use it for open-loop positioning with a driver that switches the winding currents. Use BLDC Machine or Surface PMSM for continuous rotation under feedback.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `a+` | electrical | Winding a positive end, current enters here |
| `a-` | electrical | Winding a negative end |
| `b+` | electrical | Winding b positive end, current enters here |
| `b-` | electrical | Winding b negative end |
| `shaft` | mechanical | Mechanical shaft, speed in rad/s |

## Common parameters

- `steps`: Full steps per turn (Default: 200)
- `kt`: Torque made per amp of phase current (Default: 0.5)
- `r`: Winding resistance per phase (Default: 1.5)
- `l`: Winding inductance per phase (Default: 3m)
- `j`: How strongly the rotor resists speeding up (Default: 5u)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `r` | Ω | 1.5 |  | Winding resistance per phase |
| `l` | H | 3m |  | Winding inductance per phase |
| `kt` | N·m/A | 0.5 |  | Torque made per amp of phase current |
| `steps` | — | 200 |  | Full steps per turn |
| `detent` | N·m | 10m |  | Holding torque with the windings off |
| `j` | kg·m² | 5u |  | How strongly the rotor resists speeding up |
| `b` | N·m·s/rad | 0 |  | Friction that grows with speed |
| `w0` | rad/s | 0 |  | Shaft speed at the start |
| `theta0` | rad | 0 |  | Rotor position at the start |

_Parameter descriptions are in English in both languages._

## Model

With Nr = steps/4 rotor teeth, the electrical angle is θe = Nr·θm. The flux is λa = l·ia + (kt/Nr)·cos(θe) and λb = l·ib + (kt/Nr)·sin(θe). The torque is Te = kt·(-ia·sin(θe) + ib·cos(θe)) - detent·sin(4·θe). One phase carrying I holds with a peak torque kt·I. Energizing +a, +b, -a, -b in turn moves the balance point by 90 electrical degrees, which is one full step of 2π/steps radians. The two windings do not couple.

## Common mistakes

- A stepper rings and resonates at low speed. Add viscous friction b or load damping, use microstepping with sine currents, and avoid stepping at the rotor's natural frequency.
- The driver sets the current, so supply each winding from an H-bridge that can reverse it. A plain voltage source lets the current rise only with the winding time constant, and the torque falls at high step rates.
- steps is the number of full steps per turn, a multiple of 4 from 4 to 4000 (200 for 1.8 degrees), or the run is refused. theta0 is an electrical angle, steps/4 times the mechanical angle, and the motor loses steps when the load or the acceleration exceeds the torque it can give.

Problems rules: `compile.error`

## Datasheet and sources

r and l are the winding resistance and inductance per phase, steps is 360 divided by the step angle, and detent is the detent torque. kt is the holding torque divided by the rated current (divide by the square root of 2 times the current if both phases were on), and j is the rotor inertia, where 1 g·cm² is 1e-7 kg·m².

## Example

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

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