![]() |
Midnight Sun Firmware
|
bms_carrier Firmware More...
Classes | |
struct | AuxSenseStorage |
Aux sense storage. More... | |
struct | BmsConfig |
Battery management system configuration data. More... | |
struct | BmsStorage |
Battery management system storage. More... | |
struct | FanSettings |
Fan settings. More... | |
struct | FaultBpsStorage |
Fault storage for battery-protection system. More... | |
struct | RelayStorage |
Relay storage. More... | |
struct | StateOfChargeStorage |
State of charge storage. More... | |
Macros | |
#define | BMS_CAN_RX { .port = GPIO_PORT_B, .pin = 8 } |
BMS CAN RX Port. | |
#define | BMS_CAN_TX { .port = GPIO_PORT_B, .pin = 9 } |
BMS CAN TX Port. | |
#define | CURRENT_SENSE_I2C_PORT I2C_PORT_1 |
Current sense I2C port. | |
#define | CURRENT_SENSE_I2C_SDA_GPIO { .port = GPIO_PORT_B, .pin = 11 } |
Current sense I2C serial data pin. | |
#define | CURRENT_SENSE_I2C_SCL_GPIO { .port = GPIO_PORT_B, .pin = 10 } |
Current sense I2C clock pin. | |
#define | CURRENT_SENSE_MAX17261_I2C_ADDR (0x36U) |
Current sense slave address. | |
#define | LTC_AFE_SPI_PORT SPI_PORT_2 |
AFE SPI port. | |
#define | LTC_AFE_SPI_SDO_GPIO { .port = GPIO_PORT_B, .pin = 15 } |
AFE SPI Serial data out. | |
#define | LTC_AFE_SPI_SDI_GPIO { .port = GPIO_PORT_B, .pin = 14 } |
AFE SPI Serial data in. | |
#define | LTC_AFE_SPI_SCK_GPIO { .port = GPIO_PORT_B, .pin = 13 } |
AFE SPI Serial clock line. | |
#define | LTC_AFE_SPI_CS_GPIO { .port = GPIO_PORT_B, .pin = 12 } |
AFE SPI Chip select line. | |
#define | MCP2515_SPI_PORT SPI_PORT_3 |
MCP2515 SPI port. | |
#define | MCP2515_SPI_SDO_GPIO { .port = GPIO_PORT_B, .pin = 5 } |
MCP2515 SPI Serial data out. | |
#define | MCP2515_SPI_SDI_GPIO { .port = GPIO_PORT_B, .pin = 4 } |
MCP2515 SPI Serial data in. | |
#define | MCP2515_SPI_SCK_GPIO { .port = GPIO_PORT_B, .pin = 3 } |
MCP2515 SPI Serial clock line. | |
#define | MCP2515_SPI_CS_GPIO { .port = GPIO_PORT_A, .pin = 15 } |
MCP2515 SPI Chip select line. | |
#define | BMS_PRECHARGE_STATUS_GPIO { .port = GPIO_PORT_A, .pin = 3 } |
Precharge status pin for sensing precharge completion. | |
#define | BMS_PRECHARGE_RELAY_ENABLE_GPIO { .port = GPIO_PORT_A, .pin = 9 } |
Motor relay enable pin. | |
#define | BMS_PRECHARGE_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 10 } |
Motor relay sense pin. | |
#define | BMS_POS_RELAY_ENABLE_GPIO { .port = GPIO_PORT_A, .pin = 4 } |
Positive relay enable pin. | |
#define | BMS_POS_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 15 } |
Positive relay sense pin. | |
#define | BMS_NEG_RELAY_ENABLE_GPIO { .port = GPIO_PORT_A, .pin = 13 } |
Negative relay enable pin. | |
#define | BMS_NEG_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 12 } |
Negtaive relay sense pin. | |
#define | BMS_SOLAR_RELAY_ENABLE_GPIO { .port = GPIO_PORT_C, .pin = 13 } |
Solar relay enable pin. | |
#define | BMS_SOLAR_RELAY_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 6 } |
Solar relay sense pin. | |
#define | BMS_KILLSWITCH_SENSE_GPIO { .port = GPIO_PORT_A, .pin = 11 } |
Killswitch sense pin. | |
#define | BMS_AUX_BATT_VOLTAGE_ADC { .port = GPIO_PORT_A, .pin = 5 } |
Aux sense ADC pin. | |
#define | BMS_FAN_SENSE_1_GPIO { .port = GPIO_PORT_B, .pin = 0 } |
Fan sense pin. | |
#define | BMS_FAN_SENSE_2_GPIO { .port = GPIO_PORT_B, .pin = 1 } |
Fan sense pin. | |
#define | BMS_FAN_PWM_GPIO { .port = GPIO_PORT_A, .pin = 8 } |
Fan PWM control pin. | |
#define | NUM_SERIES_MODULES 9U |
Number of modules in series. | |
#define | NUM_SERIES_CELLS_IN_MODULE 4U |
Number of series cells in a module. | |
#define | NUM_SERIES_CELLS (NUM_SERIES_CELLS_IN_MODULE * NUM_SERIES_MODULES) |
Number of series cells. | |
#define | NUM_PARALLEL_CELLS 8U |
Number of parallel cells. | |
#define | CELL_CAPACITY_MAH 4850U |
Cell capacity in milliamp hours. | |
#define | PACK_CAPACITY_MAH (CELL_CAPACITY_MAH * NUM_PARALLEL_CELLS) |
Pack capacity in milliamp hours. | |
#define | CONV_DELAY_MS 10 |
#define | AUX_CONV_DELAY_MS 3 |
#define | RETRY_DELAY_MS 1 |
#define | CELL_SENSE_CONVERSIONS 0 |
#define | CELL_OVERVOLTAGE 42500 |
#define | CELL_UNDERVOLTAGE 25000 |
#define | CELL_UNBALANCED 5000 |
#define | CELL_MAX_TEMPERATURE_DISCHARGE 60 |
#define | CELL_MAX_TEMPERATURE_CHARGE 50 |
#define | SOLAR_VOLTAGE_THRESHOLD 42000 |
#define | AFE_BALANCING_UPPER_THRESHOLD 41500 |
#define | AFE_BALANCING_LOWER_THRESHOLD 40000 |
#define | BMS_FAN_PERIOD_MS 40U |
Period in ms. Frequency = 25,000 Hz. | |
#define | BMS_FAN_TEMP_UPPER_THRESHOLD 50U |
Threshold before fan is full strength. | |
#define | BMS_FAN_TEMP_LOWER_THRESHOLD 40U |
Threshold before fan is full strength. | |
#define | BMS_FAN_BASE_DUTY_CYCLE 50U |
Base fan duty cycle when minimum temperature threshold is passed. | |
#define | BMS_CLOSE_RELAYS_DELAY_MS 250U |
Delay between consecutive relays being closed. | |
#define | NUM_BMS_RELAYS 3U |
Number of BMS relays. | |
#define | KILLSWITCH_EVENT_IT 3U |
Killswitch interrupt notification. | |
#define | CELL_INTERNAL_RESISTANCE_mOHMS 22U |
Internal resistance of cells from testing. | |
#define | PACK_INTERNAL_RESISTANCE_mOHMS (CELL_INTERNAL_RESISTANCE_mOHMS * 9U * 4U) / 8U |
9 modules, each module is 8P4S | |
#define | VOLTS_TO_mV 1000U |
Volts to millivolts conversion. | |
#define | LUT_SIZE 41U |
Lookup table size. | |
Functions | |
StatusCode | aux_sense_init (BmsStorage *storage) |
Initialize the aux sense interface. More... | |
StatusCode | aux_sense_run (void) |
Run the aux sense interface. More... | |
StatusCode | bms_carrier_init (BmsStorage *storage, BmsConfig *config) |
Initialize the battery-management system. More... | |
StatusCode | cell_sense_init (BmsStorage *storage) |
StatusCode | cell_discharge (LtcAfeStorage *afe) |
StatusCode | fans_init (BmsStorage *storage) |
Initialize the BMS fans. More... | |
void | update_fans (void) |
Update the BMS fans output. | |
uint8_t | calculate_fan_dc (uint16_t temperature) |
Calculate the fan duty cycle. More... | |
StatusCode | fault_bps_init (BmsStorage *storage) |
Initialize the Battery protection system faults. More... | |
StatusCode | fault_bps_set (uint8_t fault_bitmask) |
Initialize the Battery protection system faults. More... | |
StatusCode | fault_bps_clear (uint8_t fault_bitmask) |
Initialize the Battery protection system faults. More... | |
uint16_t | fault_bps_get (void) |
Initialize the Battery protection system faults. More... | |
StatusCode | relays_init (BmsStorage *storage) |
Close POS, NEG, and SOLAR relays in sequence. More... | |
void | bms_open_solar () |
Open the SOLAR relay. More... | |
void | bms_close_solar () |
Close the SOLAR relay. More... | |
void | bms_relay_fault (void) |
Open the POS, NEG and SOLAR relay. More... | |
StatusCode | state_of_charge_init (BmsStorage *storage) |
Initializes the state of charge. More... | |
StatusCode | update_state_of_chrage () |
Updates the state of charge value. More... | |
void | coulomb_counting_soc () |
Coulomb counting state of charge. More... | |
void | ocv_voltage_soc () |
Open circuit voltage state of charge. More... | |
float | perdict_ocv_voltage () |
Perdicts the open-circuit voltage. More... | |
bms_carrier Firmware
StatusCode aux_sense_init | ( | BmsStorage * | storage | ) |
Initialize the aux sense interface.
storage | Pointer to the BMS storage |
StatusCode aux_sense_run | ( | void | ) |
Run the aux sense interface.
StatusCode bms_carrier_init | ( | BmsStorage * | storage, |
BmsConfig * | config | ||
) |
Initialize the battery-management system.
storage | Pointer to the BMS storage |
config | Pointer to the BMS config |
|
inline |
Close the SOLAR relay.
This is used to recover from overcharging of the pack
|
inline |
Open the SOLAR relay.
This is used to prevent overcharging of the pack
void bms_relay_fault | ( | void | ) |
Open the POS, NEG and SOLAR relay.
This is called when any BMS fault occurs to disconnect the main pack
uint8_t calculate_fan_dc | ( | uint16_t | temperature | ) |
Calculate the fan duty cycle.
temperature | Maximum temperature to calculate fan duty cycle |
void coulomb_counting_soc | ( | ) |
Coulomb counting state of charge.
Uses trapezoidal rule for integrating the current over discrete-time
StatusCode fans_init | ( | BmsStorage * | storage | ) |
Initialize the BMS fans.
storage | Pointer to the BMS storage |
StatusCode fault_bps_clear | ( | uint8_t | fault_bitmask | ) |
Initialize the Battery protection system faults.
fault_bitmask | Fault bitmask to clear |
uint16_t fault_bps_get | ( | void | ) |
Initialize the Battery protection system faults.
StatusCode fault_bps_init | ( | BmsStorage * | storage | ) |
Initialize the Battery protection system faults.
bms_storage | Pointer to the BMS storage |
StatusCode fault_bps_set | ( | uint8_t | fault_bitmask | ) |
Initialize the Battery protection system faults.
fault_bitmask | Fault bitmask to set |
void ocv_voltage_soc | ( | ) |
Open circuit voltage state of charge.
Uses lookup table to determine state of charge
float perdict_ocv_voltage | ( | ) |
Perdicts the open-circuit voltage.
StatusCode relays_init | ( | BmsStorage * | storage | ) |
Close POS, NEG, and SOLAR relays in sequence.
There shall be a delay of BMS_CLOSE_RELAYS_DELAY_MS between each relay closure The killswitch interrupt will also be configured, and if it is already pressed, a fault shall be thrown
storage | Pointer to the BMS storage |
StatusCode state_of_charge_init | ( | BmsStorage * | storage | ) |
Initializes the state of charge.
storage | Pointer to the BMS storage |
StatusCode update_state_of_chrage | ( | ) |
Updates the state of charge value.