State Machine๐Ÿ”—

The firmware uses the state machines described below to sequence its behavior.

A high level state machine is accessible over CAN (see the 0x016 (State ID) packet). Underneath, a lower level state machine is responsible for sequencing behavior that needs to happen at the switching frequency.

High-level state machine๐Ÿ”—

The high-level state machine is depicted below. Detailed transitions descriptions are found in the table below.

        stateDiagram-v2
    state "0 ยท Init" as Init
    state "1 ยท ReadyToSwitch" as ReadyToSwitch
    state "2 ยท ActivelySwitching" as ActivelySwitching
    state "3 ยท Faulted" as Faulted
    state "5 ยท Disabling" as Disabling
    state "6 ยท Faulting" as Faulting
    [*] --> Init: power on
    Init --> ReadyToSwitch: Initialized<br/>sensors ready
    ReadyToSwitch --> ActivelySwitching: Enable<br/>cmd 0x01 / 0x02 / 0x04
    ActivelySwitching --> ReadyToSwitch: Disable<br/>cmd 0x00 (or 0xFF)
    ActivelySwitching --> Disabling: Disable<br/>still winding down
    Disabling --> ReadyToSwitch: Disabled<br/>switching has stopped
    Disabling --> ActivelySwitching: Enable<br/>cmd 0x01 / 0x02 / 0x04
    Disabling --> Faulted: Fault<br/>slow or fast fault, or CAN timeout
    ActivelySwitching --> Faulting: Fault<br/>still winding down
    Disabling --> Faulting: Fault<br/>still winding down
    Faulting --> Faulted: Stopped<br/>switching has stopped
    ReadyToSwitch --> Faulted: Fault<br/>slow or fast fault
    ActivelySwitching --> Faulted: Fault<br/>slow or fast fault, or CAN timeout
    Faulted --> ReadyToSwitch: Clear Faults<br/>cmd 0xFF, no active faults
    class Init init
    class ReadyToSwitch idle
    class ActivelySwitching active
    class Disabling idle
    class Faulting fault
    class Faulted fault
    
States๐Ÿ”—

State Number

State

Description

0

Init

Awaiting initialization of all sensors

1

ReadyToSwitch

The motor controller is disabled and has no latched faults.

2

ActivelySwitching

The motor controller is actively switching.

3

Faulted

The motor controller has stopped itself in response to a fault condition (see below)

5

Disabling

A disable has been commanded, but the motor controller is still switching while it winds down (e.g. out of flux weakening). It stops switching on its own and moves to ReadyToSwitch.

6

Faulting

A fault has been detected, but the motor controller is still switching while it winds down (e.g. out of flux weakening). It stops switching on its own and moves to Faulted. Faults cannot be cleared until then.

4, 7-8, 17-18

Reserved

These are reserved debug states.

The transitions are described in greater detail here.

Transitions๐Ÿ”—

Transition Name

Description

Initialized

The low-level state machine reports that all sensors are initialized and reading properly (current sense, temp sense, resolver)

Enable

Valid Enable command is provided over CAN with a valid actuation command request.

Disable

A disable or clear faults command has been sent to the motor controller while it was switching. If it cannot stop switching immediately, it passes through Disabling first.

Disabled

The motor controller has finished winding down and stopped switching.

Stopped

After a fault, the motor controller has finished winding down and stopped switching.

Fault

The motor controller has detected a critical fault. Detailed fault descriptions are found below.

Clear Faults

The motor controller has received over CAN a ClearFaults message and has determined that the previous fault case is no longer applicable.

Low-level state machine๐Ÿ”—

The high-level state machine (controllable over CAN) controls a lower level state machine that runs at the full 32kHz control rate of the inverter

        stateDiagram-v2
    [*] --> Initializing: power on
    ResettingResolver --> Initializing: next tick
    Initializing --> Disabled: Initialized<br/>current sense & resolver ready
    Initializing --> Faulted: Fault<br/>fast fault
    Disabled --> Switching: Enable<br/>STATE = ActivelySwitching
    Switching --> Disabling: Disable<br/>STATE โ‰  ActivelySwitching
    Disabling --> Disabled: next tick
    Switching --> Faulting: Fault<br/>fast fault
    Disabled --> Faulting: Fault<br/>fast fault
    Disabling --> Faulted: Fault<br/>fast fault
    Faulting --> Faulted: next tick
    Faulted --> Disabled: Clear Faults<br/>cmd 0xFF, faults acknowledged
    Faulted --> ResettingResolver: Clear Faults<br/>cmd 0xFF, after RDC_FLT
    class Initializing init
    class ResettingResolver init
    class Disabled idle
    class Disabling idle
    class Switching active
    class Faulted fault
    class Faulting fault
    class ResettingResolver transient
    class Disabling transient
    class Faulting transient
    

Commands๐Ÿ”—

The state machine can be commanded into a new state using the CAN packet 0x019 (Command Packet).

07COMMAND815DATA1623DATA2431DATA3239DATA
Command Packet๐Ÿ”—

Data Word

Description

Scaling (Divide by X to get real value)

Datatype

COMMAND

Command sent from user. See Command Table below.

N/A

u8

DATA

The data supplement used with the command packet. Interpretation depends on the COMMAND byte.

Command-dependent

i32

Command Table๐Ÿ”—

Command Name

Command ID

Description

Data Scaling (Divide by X to get real value)

Disable

0x00

Disables switching on the motor controller. DATA unused, leave as 0x00

N/A

Enable (Torque Control)

0x01

This instructs the motor controller to go into torque control mode. It will transition to ActivelySwitching and attempt to drive a desired torque. DATA is desired torque in Newton-Metres

10

Enable (Velocity Control โ€” edeg/s)

0x02

This instructs the motor controller to go into velocity control mode. DATA is desired velocity in electrical degrees per second.

1

Enable (Velocity Control โ€” MRPM)

0x04

This instructs the motor controller to go into velocity control mode. The conversion from mechanical to electrical RPM uses the configured EEPROM Configuration value for number of motor pole pairs. DATA is desired velocity in mechanical RPM.

1

Clear Faults

0xFF

Attempt to clear latched faults. DATA unused, leave as 0x00

N/A

Fast faults๐Ÿ”—

Fast faults are evaluated by the low-level state machine. They trigger the low-level state machine to fault.

Fast Faults๐Ÿ”—

Fault Name

Evaluation Interval

Trigger Packet

Description

OVC

32ฮผs

0x31E

max(abs(phase_currents)) > eeprom.overcurrent_threshold_amps

A phase current magnitude exceeded the overcurrent threshold on the coarse or fine current sense.

HVN_NP_OV

32ฮผs

0x31D

abs(gnd_to_neutral_point_v) > eeprom.max_np_capacitor_voltage

Ground-to-neutral-point voltage exceeded the maximum neutral point capacitor voltage.

This alarm may indicate internal FET damage, particularly if it fires immediately upon entering Switching.

NP_HVP_OV

32ฮผs

0x31D

abs(neutral_point_to_dc_bus_v) > eeprom.max_np_capacitor_voltage

Neutral-point-to-DC-bus voltage exceeded the maximum neutral point capacitor voltage.

This alarm may indicate internal FET damage, particularly if it fires immediately upon entering Switching.

RDC_FLT

32ฮผs

N/A

resolver.fault_flags & !ALLOWED_FAULT_FLAGS != 0

The resolver reported an error while reading rotor angle.

Note: In our implementation of the AD2S1210, we exceed the phase delay between the EXC output and SIN/COS inputs, meaning that fault flag 2 is expected, but has not been found to degrade performance significantly.

DC_PH_FLT

32ฮผs, must persist for 500 control ticks (about 15.6 ms)

N/A

A phase carries no current while voltage is applied.

HV_UV_FLT

32ฮผs

0x31F

dc_bus_v < eeprom.undervoltage_threshold_volts

DC bus voltage fell below the undervoltage threshold while the controller is enabled or commanded to enable.

ISNS_LOC

32ฮผs

N/A

Lost communication with the current sense ADCs, so no current sample is available.

HW_WDG_FLT

32ฮผs

N/A

A hardware watchdog has tripped due to excessive cycle skips in the low-level state machine. This likely indicates an issue with the flashed firmware.

Slow faults๐Ÿ”—

Slow faults are evaluated by the high-level state machine, and trigger the Disable path in the low-level state machine.

Slow Faults๐Ÿ”—

Fault Name

Evaluation Interval

Trigger Packet

Description

loss_of_comms

50ms

N/A

now_ms - last_command_timestamp_ms > eeprom.can_timeout_ms
CAN communications to the host device were lost.

OVT

50ms, debounced over 1.2 seconds

0x31E

max(temperatures) > eeprom.overtemp_threshold_c
A measured FET temperature exceeded the allowable maximum value for more than 1.2 seconds.

TSNS_LOC

50ms

N/A

now_ms - last_saw_new_temp > 1200ms
The microcontroller was not able to successfully read the FET temperatures for an extended period of time.

HVIL_FLT

50ms, debounced over 500 ms

N/A

eeprom.enable_hvil_alarm != 0 && !hvil_gpio
One or more HV connectors are not properly seated (the HVIL loop is open).