Overview
The general idea of charger is to poll if the charger is plugged in, then request permission from centre console to charge and start charging if allowed. When the battery is full or the charger is unplugged, we stop charging.
Modules:
charger_controller: This module is effectively a wrapper around mcp2515 that manages communication explicitly with the charger. It can be thought of as the ‘driver’ for the charger.
uses mcp2515’s driver to send charging messages
methods:
charger_controller_init
charger_controller_activate
charger_controller_deactivate
Upon receiving a message from the charger, checks for fault bits in the status, and sends a CHARGER_FAULT message with the appropriate fault.
charger_control_pilot: wraps PWM, also converts PWM value to current based on J1772 standard.
Exposes
uint16_t control_pilot_get_current()
to read the PWM of the control pilot pin. Returns a value in deciamps that is the maximum current the charger can provide.
charger_connection_sense: periodically reads the state of the connection_sense pin to determine whether or not the charger is connected. The charger can be unplugged, plugged in with the button pressed, or plugged in with the button released. You need to press the button to unplug the charger (think of it like the handle on a car door - the door can be open, closed with handle pulled, or closed with handle not pulled).
periodically poll the connection sense (CS) pin via ADC to determine state (defined at 500 ms)
upon connecting or disconnecting, transmit
SYSTEM_CAN_MESSAGE_CHARGER_CONNECTED_STATE
with the appropriate exported enum value, and raise aCHARGER_CHARGE_EVENT_STOP/BEGIN
if it’s disconnected or connected respectively.
begin_sequence: handles the sequence of things that need to happen to begin charging
upon processing a
CHARGER_CHARGE_EVENT_BEGIN
event, transmitSYSTEM_CAN_MESSAGE_REQUEST_TO_CHARGE
.Centre console will get the request. If we’re in the appropriate drive state (parking) centre console will send back
SYSTEM_CAN_MESSAGE_ALLOW_CHARGING
.
Upon receiving a
SYSTEM_CAN_MESSAGE_ALLOW_CHARGING
, begin the init sequence:make sure charger is on (transmit
SYSTEM_CAN_MESSAGE_CHARGER_FAULT
if not)Get a pwm reading from control pilot to deduce max current allowed
set relay state then load switch state
enable charging via control pilot
activate charger via
charger_controller_activate
stop_sequence: handles the sequence of things that need to happen to stop charging
Upon processing a
CHARGER_CHARGE_EVENT_STOP
, the sequence will:deactivate the charger via
charger_controller_deactivate
Turn off the control pilot
Turn off the load switch then the relay
battery_monitor: stops charging when the battery is full.
repeatedly receives SYSTEM_CAN_MESSAGE_BATTERY_AGGREGATE_VC
If voltage is over 135 V (defined threshold) will raise a CHARGER_CHARGE_EVENT_STOP event.
Operation Mode:
The BMS sends operating information (Message 1) to charger at fixed interval of 1s. After receiving the message, the charger will work under the Voltage and Current in Message. If the Message is not received within 5s, it will enter into communication error state and stop charging.
...
Controlled Relays & Hardware
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|
View file | ||
---|---|---|
|