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 injectedHardware signalRequired firmware reaction
DRV8305 VDS tripnFAULT pin low + OV_VDS status bitTIM1 MOE brake disables all 6 PWM outputs immediately
TMC2209 stallDIAG pin high + SG_RESULT dropHoming stops cleanly and clears step generator
AS5600 magnet lostSTATUS.MD=0 via register overrideFOC 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.yaml

Suite & 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: 0

CI 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.yaml

Troubleshooting checklist

SymptomFix
PWM outputs stay active after fault flagClear TIM1->BDTR.MOE or wire the hardware BKIN break input so hardware gates off outputs immediately.
Wrong switching frequency on center-aligned timerCheck edge-aligned vs center-aligned ARR values in the PWM Timer Prescaler Calculator.

Frequently asked questions

QuestionAnswer
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.

Related boards & component twins

More in Fault Injection & Debugging