![]() |
Midnight Sun Firmware
|
Rear Controller Board Firmware. More...
Classes | |
| struct | RearControllerConfig |
| struct | RearControllerStorage |
| struct | ThermistorDataPoint |
Macros | |
| #define | CONV_DELAY_MS 10 |
| #define | AUX_CONV_DELAY_MS 3 |
| #define | RETRY_DELAY_MS 1 |
| #define | CELL_SENSE_CONVERSIONS 0 |
| #define | SOLAR_VOLTAGE_THRESHOLD 42000 |
| #define | AFE_BALANCING_UPPER_THRESHOLD 41500 |
| #define | AFE_BALANCING_LOWER_THRESHOLD 40000 |
| #define | REAR_CONTROLLER_FAN_TEMP_THRESHOLD_C 40 |
| #define | REAR_CONTROLLER_PRECHARGE_EVENT 0U |
| #define | REAR_CONTROLLER_KILLSWITCH_EVENT 1U |
| #define | REAR_CONTROLLER_CURRENT_SENSE_FILTER_ALPHA 0.5 |
| #define | REAR_CONTROLLER_CURRENT_SENSE_MAX_RETRIES 3 |
| #define | REAR_CONTROLLER_SERIES_COUNT 36U |
| #define | REAR_CONTROLLER_PARALLEL_COUNT 9U |
| #define | REAR_CONTROLLER_CELL_CAPACITY_AH 4.5 |
| #define | REAR_CONTROLLER_CAN_RX { .port = GPIO_PORT_B, .pin = 8 } |
| Rear Controller CAN RX Port. | |
| #define | REAR_CONTROLLER_CAN_TX { .port = GPIO_PORT_B, .pin = 9 } |
| Rear Controller CAN TX Port. | |
| #define | REAR_CONTROLLER_POS_RELAY_ENABLE_GPIO { .port = GPIO_PORT_A, .pin = 6 } |
| Rear Controller positive relay enable pin. | |
| #define | REAR_CONTROLLER_POS_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 5 } |
| Rear Controller positive relay sense pin. | |
| #define | REAR_CONTROLLER_NEG_RELAY_ENABLE_GPIO { .port = GPIO_PORT_A, .pin = 4 } |
| Rear Controller negative relay enable pin. | |
| #define | REAR_CONTROLLER_NEG_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 3 } |
| Rear Controller negative relay sense pin. | |
| #define | REAR_CONTROLLER_SOLAR_RELAY_ENABLE_GPIO { .port = GPIO_PORT_A, .pin = 8 } |
| Rear Controller solar relay enable pin. | |
| #define | REAR_CONTROLLER_SOLAR_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 9 } |
| Rear Controller solar relay sense pin. | |
| #define | REAR_CONTROLLER_MOTOR_RELAY_ENABLE_GPIO { .port = GPIO_PORT_C, .pin = 4 } |
| Rear Controller motor relay enable pin. | |
| #define | REAR_CONTROLLER_MOTOR_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 7 } |
| Rear Controller motor relay sense pin. | |
| #define | REAR_CONTROLLER_MOTOR_LV_ENABLE_GPIO { .port = GPIO_PORT_C, .pin = 12 } |
| Rear Controller motor low-voltage enable pin. | |
| #define | REAR_CONTROLLER_MOTOR_FAN_PWM { .port = GPIO_PORT_B, .pin = 2 } |
| Rear Controller fan pwm. | |
| #define | REAR_CONTROLLER_MOTOR_FAN_SENSE_1 { .port = GPIO_PORT_B, .pin = 0 } |
| Rear Controller fan sense 2. | |
| #define | REAR_CONTROLLER_MOTOR_FAN_SENSE_2 { .port = GPIO_PORT_B, .pin = 1 } |
| Rear Controller fan sense 1. | |
| #define | REAR_CONTROLLER_CURRENT_SENSE_I2C_PORT I2C_PORT_1 |
| Current sense I2C port. | |
| #define | REAR_CONTROLLER_CURRENT_SENSE_I2C_SDA_GPIO { .port = GPIO_PORT_B, .pin = 11 } |
| Current sense I2C serial data pin. | |
| #define | REAR_CONTROLLER_CURRENT_SENSE_I2C_SCL_GPIO { .port = GPIO_PORT_B, .pin = 10 } |
| Current sense I2C clock pin. | |
| #define | REAR_CONTROLLER_CURRENT_SENSE_ACS37800_I2C_ADDR (96) |
| Current sense slave address. | |
| #define | REAR_CONTROLLER_ADBMS_AFE_SPI_PORT SPI_PORT_2 |
| AFE SPI port. | |
| #define | REAR_CONTROLLER_ADBMS_AFE_SPI_BAUDRATE SPI_BAUDRATE_312_5KHZ |
| AFE SPI Baudrate. | |
| #define | REAR_CONTROLLER_ADBMS_AFE_SPI_SDO_GPIO { .port = GPIO_PORT_B, .pin = 15 } |
| AFE SPI Serial data out. | |
| #define | REAR_CONTROLLER_ADBMS_AFE_SPI_SDI_GPIO { .port = GPIO_PORT_B, .pin = 14 } |
| AFE SPI Serial data in. | |
| #define | REAR_CONTROLLER_ADBMS_AFE_SPI_SCK_GPIO { .port = GPIO_PORT_B, .pin = 13 } |
| AFE SPI Serial clock line. | |
| #define | REAR_CONTROLLER_ADBMS_AFE_SPI_CS_GPIO { .port = GPIO_PORT_B, .pin = 12 } |
| AFE SPI Chip select line. | |
| #define | REAR_CONTROLLER_PCS_VALID1 { .port = GPIO_PORT_C, .pin = 6 } |
| Rear Controller PCS input valid pin 1. | |
| #define | REAR_CONTROLLER_PCS_VALID2 { .port = GPIO_PORT_C, .pin = 7 } |
| Rear Controller PCS input valid pin 2. | |
| #define | REAR_CONTROLLER_AUX_VALID1 { .port = GPIO_PORT_C, .pin = 8 } |
| Rear Controller AUX input valid pin 1. | |
| #define | REAR_CONTROLLER_AUX_VALID2 { .port = GPIO_PORT_C, .pin = 9 } |
| Rear Controller AUX input valid pin 2. | |
| #define | REAR_CONTROLLER_PCS_VSENSE { .port = GPIO_PORT_A, .pin = 2 } |
| Rear Controller PCS voltage sense. | |
| #define | REAR_CONTROLLER_AUX_VSENSE { .port = GPIO_PORT_A, .pin = 1 } |
| Rear Controller AUX voltage sense. | |
| #define | REAR_CONTROLLER_PCS_ISENSE { .port = GPIO_PORT_C, .pin = 3 } |
| Rear Controller PCS current sense. | |
| #define | REAR_CONTROLLER_AUX_ISENSE { .port = GPIO_PORT_C, .pin = 2 } |
| Rear Controller AUX current sense. | |
| #define | REAR_CONTROLLER_PRECHARGE_MONITOR_GPIO { .port = GPIO_PORT_A, .pin = 0 } |
| Precharge monitoring pin. | |
| #define | REAR_CONTROLLER_KILLSWITCH_MONITOR_GPIO { .port = GPIO_PORT_C, .pin = 5 } |
| Killswitch monitoring pin. | |
| #define | REAR_CONTROLLER_BOARD_LED { .port = GPIO_PORT_A, .pin = 10 } |
| Rear Controller board LED. | |
| #define | PACK_MAX_DISCHARGE_CURRENT_A -80.0 |
| #define | PACK_MAX_CHARGE_CURRENT_A 80.0 |
| #define | PACK_SHORT_CIRCUIT_CURRENT_A 60000 |
| #define | CELL_OVERVOLTAGE_LIMIT_mV 4200 |
| #define | CELL_UNDERVOLTAGE_LIMIT_mV 2500 |
| #define | CELL_UNBALANCED_LIMIT_mV 500 |
| #define | PACK_OVERVOLTAGE_LIMIT_mV 151200 |
| #define | PACK_UNDERVOLTAGE_LIMIT_mV 90000 |
| #define | CELL_OVERTEMP_DISCHARGE_LIMIT_C 60 |
| #define | CELL_OVERTEMP_CHARGE_LIMIT_C 60 |
| #define | CELL_UNDERTEMP_CHARGE_LIMIT_C 0 |
| #define | SHORT_CIRCUIT_RESPONSE_MS 1U |
| #define | OVERCURRENT_RESPONSE_LOOPS 2 |
| #define | OVERTEMP_RESPONSE_MS 500U |
| #define | UNDERVOLTAGE_RESPONSE_MS 1000U |
| #define | OVERVOLTAGE_RESPONSE_MS 1000U |
| #define | NUM_REAR_RELAYS 4U |
| #define | REAR_CLOSE_RELAYS_DELAY_MS 250U |
| #define | REAR_CLOSE_RELAYS_DELAY_MS 250U |
| #define | SOC_OCV_TABLE_SIZE (100) |
| #define | SOC_TABLE_VALUES |
| SOC table initializer list. More... | |
| #define | OCV_TABLE_VALUES |
| OCV table initializer list. More... | |
| #define | THERMISTOR_TABLE_SIZE 102 |
Enumerations | |
| enum | RearControllerState { REAR_CONTROLLER_STATE_IDLE , REAR_CONTROLLER_STATE_DRIVE , REAR_CONTROLLER_STATE_CHARGE , REAR_CONTROLLER_STATE_FAULT } |
| enum | RearControllerEvent { REAR_CONTROLLER_EVENT_NONE = 0 , REAR_CONTROLLER_EVENT_INIT_COMPLETE , REAR_CONTROLLER_EVENT_DRIVE_REQUEST , REAR_CONTROLLER_EVENT_CHARGE_REQUEST , REAR_CONTROLLER_EVENT_NEUTRAL_REQUEST , REAR_CONTROLLER_EVENT_CHARGER_REMOVED , REAR_CONTROLLER_EVENT_FAULT , REAR_CONTROLLER_EVENT_RESET } |
Functions | |
| StatusCode | bps_fault_init (RearControllerStorage *storage) |
| Initialize the BPS fault memory. More... | |
| StatusCode | bps_fault_commit (void) |
| Commit a new BPS fault to persist memory and CAN data. More... | |
| StatusCode | trigger_bps_fault (BpsFault fault) |
| Trigger a BPS fault. This opens the relays and updates rear controller storage. More... | |
| StatusCode | bps_fault_clear () |
| Clear the BPS fault. More... | |
| StatusCode | cell_sense_init (RearControllerStorage *storage) |
| Initializes the cell sense sub-system. More... | |
| StatusCode | log_cell_sense () |
| Logs the newest cell sense readings. More... | |
| StatusCode | current_sense_init (RearControllerStorage *rear_controller_storage) |
| Initializes the current sense sub-system. More... | |
| StatusCode | current_sense_run () |
| Run a current sensing cycle to update pack voltage and pack current readings. More... | |
| StatusCode | fans_init (RearControllerStorage *storage) |
| Initializes the fan sub-system. More... | |
| StatusCode | fans_run (void) |
| Checks the max board and cell temperatures in storage, compares them against the fan threshold, and turns on or off accordingly. More... | |
| StatusCode | killswitch_init (Event event, const Task *task) |
| StatusCode | power_path_manager_init (RearControllerStorage *storage) |
| Initialize the power path manager. More... | |
| StatusCode | power_path_manager_run (void) |
| Run power path manager calculations. More... | |
| StatusCode | precharge_init (Event event, const Task *task) |
| StatusCode | rear_controller_init (RearControllerStorage *storage, RearControllerConfig *config) |
| StatusCode | rear_controller_state_manager_init (RearControllerStorage *storage) |
| Initialize the state machine. More... | |
| StatusCode | rear_controller_state_manager_step (RearControllerEvent event) |
| Advance the state machine based on inputs/events. More... | |
| RearControllerState | rear_controller_state_manager_get_state (void) |
| Get current state. More... | |
| StatusCode | relays_init (RearControllerStorage *storage) |
| Initialize the relay control module. More... | |
| StatusCode | relays_reset () |
| Reset relays by disengaging all relays. More... | |
| StatusCode | relays_enable_ws22_lv (void) |
| Enable the low voltage for the Wavesculptor 22. More... | |
| StatusCode | relays_disable_ws22_lv (void) |
| Disable the low voltage for the Wavesculptor 22. More... | |
| StatusCode | relays_close_pos (void) |
| Close the high-side (POS) relay. More... | |
| StatusCode | relays_open_pos (void) |
| Open the high-side (POS) relay. More... | |
| StatusCode | relays_close_neg (void) |
| Close the low-side (NEG) relay. More... | |
| StatusCode | relays_open_neg (void) |
| Open the low-side (NEG) relay. More... | |
| StatusCode | relays_close_motor (void) |
| Close the motor HV relay. More... | |
| StatusCode | relays_open_motor (void) |
| Open the motor HV relay. More... | |
| StatusCode | relays_close_solar (void) |
| Close the solar array relay. More... | |
| StatusCode | relays_open_solar (void) |
| Open the solar array relay. More... | |
| StatusCode | state_of_charge_init (RearControllerStorage *storage) |
| Initialize the state of charge EKF. More... | |
| StatusCode | state_of_charge_run () |
| Run state of charge calculation. More... | |
| uint16_t | calculate_board_thermistor_temperature (uint16_t thermistor_voltage_mv) |
| fid, '#pragma once\n\n' | fprintf () |
| fprintf (fid, '#define SOC_TABLE_VALUES { \\\n') | |
Variables | |
| const ThermistorDataPoint | thermistor_table [] |
| for | i |
| normalize to cell capacity Downsample to points for embedded target params | SOC_OCV_table_size = 100 |
Rear Controller Board Firmware.
'); fprintf(fid, ' * fprintf(fid, ' * Rear Controller Board Firmware
'); fprintf(fid, ' *
'); fprintf(fid, '
| #define CELL_OVERTEMP_CHARGE_LIMIT_C 60 |
Max temperature for charge
| #define CELL_OVERTEMP_DISCHARGE_LIMIT_C 60 |
Max temperature for discharge
| #define CELL_OVERVOLTAGE_LIMIT_mV 4200 |
Over-voltage cutoff
| #define CELL_UNBALANCED_LIMIT_mV 500 |
Cell imbalance cutoff
| #define CELL_UNDERTEMP_CHARGE_LIMIT_C 0 |
Min temperature for charge
| #define CELL_UNDERVOLTAGE_LIMIT_mV 2500 |
Under-voltage cutoff
| #define OCV_TABLE_VALUES |
OCV table initializer list.
| #define OVERCURRENT_RESPONSE_LOOPS 2 |
Delay before over-current trips
| #define OVERTEMP_RESPONSE_MS 500U |
Delay before over-temp trips
| #define OVERVOLTAGE_RESPONSE_MS 1000U |
Delay before over-voltage trips
| #define PACK_MAX_CHARGE_CURRENT_A 80.0 |
Maximum allowed charge current
| #define PACK_MAX_DISCHARGE_CURRENT_A -80.0 |
Maximum allowed discharge current
| #define PACK_SHORT_CIRCUIT_CURRENT_A 60000 |
Instantaneous short-circuit threshold
| #define SHORT_CIRCUIT_RESPONSE_MS 1U |
HW trip reaction time
| #define SOC_TABLE_VALUES |
SOC table initializer list.
| #define UNDERVOLTAGE_RESPONSE_MS 1000U |
Delay before under-voltage trips
| enum RearControllerState |
| StatusCode bps_fault_clear | ( | ) |
Clear the BPS fault.
| fault | BPS Fault event |
| StatusCode bps_fault_commit | ( | void | ) |
Commit a new BPS fault to persist memory and CAN data.
| StatusCode bps_fault_init | ( | RearControllerStorage * | storage | ) |
Initialize the BPS fault memory.
| storage | Pointer to the rear controller storage |
| StatusCode cell_sense_init | ( | RearControllerStorage * | storage | ) |
Initializes the cell sense sub-system.
| storage | Pointer to the rear controller storage |
| StatusCode current_sense_init | ( | RearControllerStorage * | rear_controller_storage | ) |
Initializes the current sense sub-system.
| storage | Pointer to the rear controller storage |
| StatusCode current_sense_run | ( | ) |
Run a current sensing cycle to update pack voltage and pack current readings.
| StatusCode fans_init | ( | RearControllerStorage * | storage | ) |
Initializes the fan sub-system.
| storage | Pointer to the rear controller storage |
| StatusCode fans_run | ( | void | ) |
Checks the max board and cell temperatures in storage, compares them against the fan threshold, and turns on or off accordingly.
| StatusCode log_cell_sense | ( | ) |
Logs the newest cell sense readings.
| StatusCode power_path_manager_init | ( | RearControllerStorage * | storage | ) |
Initialize the power path manager.
| storage | Pointer to the rear controller storage |
| StatusCode power_path_manager_run | ( | void | ) |
Run power path manager calculations.
| RearControllerState rear_controller_state_manager_get_state | ( | void | ) |
Get current state.
| StatusCode rear_controller_state_manager_init | ( | RearControllerStorage * | storage | ) |
Initialize the state machine.
| storage | Pointer to the rear controller storage |
| StatusCode rear_controller_state_manager_step | ( | RearControllerEvent | event | ) |
Advance the state machine based on inputs/events.
| event | The triggering event |
| StatusCode relays_close_motor | ( | void | ) |
Close the motor HV relay.
| StatusCode relays_close_neg | ( | void | ) |
Close the low-side (NEG) relay.
| StatusCode relays_close_pos | ( | void | ) |
Close the high-side (POS) relay.
| StatusCode relays_close_solar | ( | void | ) |
Close the solar array relay.
| StatusCode relays_disable_ws22_lv | ( | void | ) |
Disable the low voltage for the Wavesculptor 22.
| StatusCode relays_enable_ws22_lv | ( | void | ) |
Enable the low voltage for the Wavesculptor 22.
| StatusCode relays_init | ( | RearControllerStorage * | storage | ) |
Initialize the relay control module.
| storage | Pointer to the rear controller storage |
| StatusCode relays_open_motor | ( | void | ) |
Open the motor HV relay.
| StatusCode relays_open_neg | ( | void | ) |
Open the low-side (NEG) relay.
| StatusCode relays_open_pos | ( | void | ) |
Open the high-side (POS) relay.
| StatusCode relays_open_solar | ( | void | ) |
Open the solar array relay.
| StatusCode relays_reset | ( | ) |
Reset relays by disengaging all relays.
| StatusCode state_of_charge_init | ( | RearControllerStorage * | storage | ) |
Initialize the state of charge EKF.
| storage | Pointer to the rear controller storage |
| StatusCode state_of_charge_run | ( | ) |
Run state of charge calculation.
| StatusCode trigger_bps_fault | ( | BpsFault | fault | ) |
Trigger a BPS fault. This opens the relays and updates rear controller storage.
| fault | BPS Fault event |
| for i |