Charger FSM
The Charger.ino logic revolves around a Finite State Machine (FSM) that dictates the safety protocol for connecting the accumulator to the external charging source.
Flow Diagram
State Machine Overview
The system iterates through the following states:
- IDLE: All relays are open. The system waits for the operator to press the Start button, provided that the physical SDC (Shutdown Circuit) is okay and no BMS errors are detected.
- PRECHARGE: The initial step of connection. The AIR- relay and Precharge relays are engaged. The AIR+ relay remains open. This limits the inrush current to the accumulator.
- WAIT_COMP: The system waits for the precharge circuit to equalize voltage. A fixed delay ensures sufficient time has passed for stabilization before fully connecting.
- CHARGING: The main charging phase. The AIR+ relay engages, and after a brief overlap, the Precharge relay disengages, completing the direct connection for high current charging.
- FAULT: A safe failure state. All relays are opened immediately. The system drops into this state if the SDC fails, the BMS reports an error, or the CAN connection to the BMS is lost. The operator must turn off the start switch to re-arm the system once the fault is cleared.
Hardware Interlocks
The FSM checks faultActive() continuously. This evaluates:
in.sdc_ok: A physical interlock indicating the hardware shutdown circuit is closed.in.safety_ok: The BMS reporting that charging is permitted.in.bms_error: Any error bits flagged via CAN.
Any failure in these conditions triggers an immediate fallback to the FAULT state and asserts the AMS_ERROR_OUT pin if applicable.
