DC motor drive on a simulated bench
Identify, home, protect, fall back: six parameters found within 0.7 %, a chip fault handled in 1.05 ms, back-EMF speed 5.0 ms after the encoder dies. All on the simulated bench.

After the control library I wanted one complete drive, not a loop in isolation: a small brushed motor on an integrated H-bridge with a quadrature encoder (4096 counts), the way it would sit on a board. That means everything around the PI that nobody draws in the block diagram. A CiA 402 state machine, so the drive can be enabled, faulted and reset properly. An identifier that measures the motor instead of trusting the datasheet. Homing against a hard stop. Protection: chip fault, I²t heating, stall. A back-EMF speed estimate for when the encoder dies.
There’s no board yet, so the plant is simulated: an H-bridge model with dead time, current ripple, heating
and a bus, an encoder model with edge timing, on the brushed-motor model from my act library. One PWM
period is 50 µs, the slow loop runs every 20th tick (1 kHz). The glue between drivers and control goes only
through the driver interfaces, so the same code can later sit on hardware.
One executable, dc-motor, runs six scenarios, checks its headline numbers against the plant’s true
state and exits non-zero if one is off. I re-built and re-ran it on 2026-11-22 in double and in float; both
end with dc-motor: all expectations met.
The stories
| # | Story | Result | Status |
|---|---|---|---|
| 1 | Commissioning from a datasheet that's 50 % wrong Enable, identify R, L, Kt, J, b and friction on the drive itself, re-tune from that, home on a hard stop, then move 30 rad |
Six motor parameters identified within 0.7 % (datasheet off by 17-50 %) in 4.9 s; origin exact to the count, final error 0.7 counts | Done |
| 2 | A load step, a disturbance observer, and a current sensor that can't tell direction What a disturbance observer buys (and costs) under a 0.02 N·m step, and running the inner loop on a magnitude-only current signal |
Observer: dip 2.49 -> 1.51 rad/s, recovery 18.0 -> 3.1 ms, at 2.8x the current noise; magnitude-only sensing holds the 3 A limit with 2.2x the speed noise | Done |
| 3 | When it goes wrong: chip fault, a hot winding, a dead encoder Three failure scenarios on the simulated drive: fault and reset through CiA 402, I²t derating on a pump, back-EMF fallback when the encoder line dies |
Fault in 1.05 ms; winding peaks at 95.6 °C under a 110 °C limit with nothing tripped; dead encoder to back-EMF speed in 5.0 ms, still running | Done |
Still open
All of this is the simulator’s truth. A real motor’s back-EMF constant falls as the magnets warm and nothing re-checks it while running, and the host loop is sequential, so it never shows the interrupt preempting the 1 kHz task halfway through a step. The first real board will re-measure every number on these pages.