Fault Injection & Debugging
Testing PWM dead-time, StallGuard and overcurrent trips in CI
Prove your motor controller cuts PWM outputs on an nFAULT or StallGuard trip without smoking real power stages.
Testing shoot-through protection, VDS overcurrent trips and rotor-stall shutdowns on live 48 V inverters destroys MOSFETs whenever an ISR flag is inverted.
CircuitTwin runs your STM32G4, STM32F4 or C2000 firmware against DRV8305, TMC2209 and AS5600 encoder twins, injecting SPI fault flags and frozen shaft angles to verify safe PWM brake behavior in CI.
Motor-control fault checks
| Fault injected | Hardware signal | Required firmware reaction |
|---|---|---|
DRV8305 VDS trip | nFAULT pin low + OV_VDS status bit | TIM1 MOE brake disables all 6 PWM outputs immediately |
TMC2209 stall | DIAG pin high + SG_RESULT drop | Homing stops cleanly and clears step generator |
AS5600 magnet lost | STATUS.MD=0 via register override | FOC loop enters safe coast instead of full-torque spin |
Local CLI workflow
Shell - run motor-control fault suite
ct test run --json --junit results/motor-faults.xml tests/motor-safety.suite.yamlSuite & fault configuration
tests/motor-safety.suite.yaml
version: 1
board: nucleo-f446re
firmware: build/foc_ctrl.elf
tests:
- name: encoder-magnet-lost-safe-coast
timeout_ms: 2000
faults:
- at_ms: 150
part: as5600
kind: register_override
register: 0x0B
value: 0x00
expect:
console_contains: "FOC_SAFE_COAST"
exit_code: 0CI pipeline integration
.github/workflows/motor-safety.yml
name: Motor Safety Fault CI
on: [push, pull_request]
jobs:
motor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: circuittwin/action@v1
with:
suite: tests/motor-safety.suite.yamlTroubleshooting checklist
| Symptom | Fix |
|---|---|
| PWM outputs stay active after fault flag | Clear TIM1->BDTR.MOE or wire the hardware BKIN break input so hardware gates off outputs immediately. |
| Wrong switching frequency on center-aligned timer | Check edge-aligned vs center-aligned ARR values in the PWM Timer Prescaler Calculator. |
Frequently asked questions
| Question | Answer |
|---|---|
| Can CircuitTwin verify FOC encoder fault recovery on AS5600? | Yes. Override AS5600 STATUS register 0x0B (magnet-detected bit) or freeze the angle register at a fixed timestamp and assert safe-coast shutdown. |