diff --git a/Core/Inc/datastructs.h b/Core/Inc/datastructs.h index d95eeb6..e39e4e8 100644 --- a/Core/Inc/datastructs.h +++ b/Core/Inc/datastructs.h @@ -6,6 +6,7 @@ #include "bmsConfig.h" #include "timer.h" #include "cmsis_os2.h" +#include "adBms6830Data.h" /** * @brief Individual chip data @@ -84,6 +85,9 @@ typedef struct { /* Array of data from all chips in the system */ chipdata_t chip_data[NUM_CHIPS]; + /* Array of structs containing raw data from and configurations for the ADBMS6830 chips */ + cell_asic chips[NUM_CHIPS]; + int fault_status; int16_t pack_current; /* this value is multiplied by 10 to account for decimal precision */ diff --git a/Core/Inc/segment.h b/Core/Inc/segment.h index 607259d..9e49ae9 100644 --- a/Core/Inc/segment.h +++ b/Core/Inc/segment.h @@ -15,14 +15,15 @@ void segment_init(); * * @todo make sure that retrieving cell data doesn't block code too much */ -void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]); +void segment_retrieve_data(acc_data_t *bmsdata); /** * @brief Enables/disables balancing for all cells * - * @param balance_enable + * @param chips Array of ADBMS6830 data structs. + * @param balance_enable False to disable balancing, true to enable. */ -void segment_enable_balancing(bool balance_enable); +void segment_enable_balancing(cell_asic chips[NUM_CHIPS], bool balance_enable); /** * @brief Enables/disables balancing for a specific cell @@ -35,11 +36,13 @@ void cell_enable_balancing(uint8_t chip_num, uint8_t cell_num, bool balance_enable); /** - * @brief Sets each cell to whatever state is passed in the boolean config area - * - * @param discharge_config + * @brief Set the cell balancing configuration and send it to the segments. + * + * @param chips Array of ADBMS6830 data structs. + * @param discharge_config Configuration for which cells to discharge. */ void segment_configure_balancing( + cell_asic chips[NUM_CHIPS], bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP]); /** diff --git a/Core/Src/analyzer.c b/Core/Src/analyzer.c index 3635a28..da1e46e 100644 --- a/Core/Src/analyzer.c +++ b/Core/Src/analyzer.c @@ -122,22 +122,6 @@ const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS] = {6 + MUX_OFFSET, 8 + MUX_OFFSET, NO_THERM}, }; -uint8_t THERM_DISABLE[NUM_CHIPS][NUM_THERMS_PER_CHIP] = -{ - {1,0,1,0,0,1,0,1,1,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,1,0 }, - {1,0,1,0,0,1,0,0,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1 }, - {1,0,1,0,0,1,0,0,1,0,0,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0 }, - {1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,0,0,0,1,1,1,0,1,0,0,1,0,0,0,0 }, - {1,0,1,0,0,1,0,1,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1 }, - {1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0 }, - {1,0,1,0,0,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,0,0,0,0,0,1,0 }, - {1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,1,1,1,1 }, - {1,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0 }, - {1,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0 }, - {1,1,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0 }, - {1,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0 } -}; - /* * List of therms that we actually read from, NOT reordered by cell */ @@ -225,9 +209,11 @@ void calc_pack_temps(acc_data_t *bmsdata) bmsdata->min_temp.val = MAX_TEMP; bmsdata->min_temp.cellNum = 0; bmsdata->min_temp.chipIndex = 0; + int total_temp = 0; int total_seg_temp = 0; int total_accepted = 0; + for (uint8_t c = 0; c < NUM_CHIPS; c++) { for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) { /* finds out the maximum cell temp and location */ @@ -638,29 +624,29 @@ uint8_t analyzer_calc_fan_pwm(acc_data_t *bmsdata) (2 * 5); } -void disable_therms(acc_data_t *bmsdata) -{ - int8_t tmp_temp = - 25; /* Iniitalize to room temp (necessary to stabilize when the BMS first boots up/has null values) */ - if (!is_first_reading_) - tmp_temp = - bmsdata->avg_temp; /* Set to actual average temp of the pack */ - - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) { - /* If 2D LUT shows therm should be disable */ - if (THERM_DISABLE[c][therm]) { - /* Nullify thermistor by setting to pack average */ - bmsdata->chip_data[c].thermistor_value[therm] = - tmp_temp; - } else { - bmsdata->chip_data[c].thermistor_value[therm] = - bmsdata->chip_data[c] - .thermistor_reading[therm]; - } - } - } -} +// void disable_therms(acc_data_t *bmsdata) +// { +// int8_t tmp_temp = +// 25; /* Iniitalize to room temp (necessary to stabilize when the BMS first boots up/has null values) */ +// if (!is_first_reading_) +// tmp_temp = +// bmsdata->avg_temp; /* Set to actual average temp of the pack */ + +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) { +// /* If 2D LUT shows therm should be disable */ +// if (THERM_DISABLE[c][therm]) { +// /* Nullify thermistor by setting to pack average */ +// bmsdata->chip_data[c].thermistor_value[therm] = +// tmp_temp; +// } else { +// bmsdata->chip_data[c].thermistor_value[therm] = +// bmsdata->chip_data[c] +// .thermistor_reading[therm]; +// } +// } +// } +// } void calc_state_of_charge(acc_data_t *bmsdata) { diff --git a/Core/Src/main.c b/Core/Src/main.c index 8ff76e3..f3aca11 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -347,7 +347,7 @@ int main(void) HAL_Delay(500); init_both_can(&hcan1, &hcan2); - segment_init(); + segment_init(acc_data->chip_data); compute_init(); printf("Init passed\n"); /* USER CODE END 2 */ diff --git a/Core/Src/segment.c b/Core/Src/segment.c index e180c7d..ba6c625 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -27,9 +27,6 @@ typedef enum { MUTE_ACTIVATED_DISCHARGE_DISABLED = 1 } MUTE_ST; -#define TOTAL_IC 1 -cell_asic IC[TOTAL_IC]; - RD REDUNDANT_MEASUREMENT = RD_OFF; CH AUX_CH_TO_CONVERT = AUX_ALL; CONT CONTINUOUS_MEASUREMENT = SINGLE; @@ -71,7 +68,6 @@ extern SPI_HandleTypeDef hspi1; uint8_t therm_avg_counter = 0; -chipdata_t *segment_data = NULL; chipdata_t previous_data[NUM_CHIPS] = {}; uint16_t discharge_commands[NUM_CHIPS] = {}; @@ -110,9 +106,9 @@ const int32_t VOLT_TEMP_CALIB_OFFSET = 0; void serialize_i2c_msg(uint8_t data_to_write[][3], uint8_t comm_output[][6]); int8_t steinhart_est(uint16_t V); void variance_therm_check(void); -void discard_neutrals(void); +void discard_neutrals(chipdata_t segment_data[NUM_CHIPS]); void pull_chip_configuration(void); -int16_t calc_average(void); +int16_t calc_average(chipdata_t segment_data[NUM_CHIPS]); int8_t calc_therm_standard_dev(int16_t avg_temp); void init_chip(cell_asic *chip); void set_cell_discharge(cell_asic *chip, uint8_t cell, bool discharge); @@ -130,6 +126,10 @@ inline uint16_t set_uint16_bit(uint16_t number, uint16_t n, bool x) return (number & ~((uint16_t)1 << n)) | ((uint16_t)x << n); } +/** + * @brief Wake every ADBMS6830 IC in the daisy chain. Takes NUM_CHIPS * 8 ms to finish. + * + */ void adbms_wake() { adBmsWakeupIc(NUM_CHIPS); @@ -264,13 +264,13 @@ inline void write_config_regs(cell_asic chips[NUM_CHIPS]) * @brief Initialize chips with default values. * */ -void segment_init() +void segment_init(cell_asic chips[NUM_CHIPS]) { printf("Initializing Segments..."); for (int chip = 0; chip < NUM_CHIPS; chip++) { - init_chip(&IC[chip]); + init_chip(&chips[chip]); } - write_config_regs(IC); + write_config_regs(chips); } /** @@ -419,24 +419,39 @@ void adBms6830_read_status_registers(cell_asic chips[NUM_CHIPS]) read_adbms_data(chips, RDSTATE, Status, E); } -int pull_voltages() +int pull_voltages(acc_data_t *bmsdata) { /** * If we haven't waited long enough between pulling voltage data * just copy over the contents of the last good reading and the fault status * from the most recent attempt */ + + // TODO: should probably get rid of this if (!is_timer_expired(&voltage_reading_timer) && voltage_reading_timer.active) { for (uint8_t i = 0; i < NUM_CHIPS; i++) { - memcpy(segment_data[i].voltage, - previous_data[i].voltage, - sizeof(segment_data[i].voltage)); + memcpy(&bmsdata->chips[i], &previous_data[i], + sizeof(bmsdata->chips[i])); } return voltage_error; } - get_c_adc_voltages(IC); + get_c_adc_voltages(bmsdata->chips); + + // TODO: Change number of cells per chip for alpha and beta + // or not cuz we can just copy all the values here and handle this in analyzer + + // NOTE: Its kind of silly to just copy voltages like this. We should consolidate + // chip data and chips later, or design analyzer to read voltages from chips rather + // than chipdata + + for (int chip = 0; chip < NUM_CHIPS; chip++) { + for (int cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + bmsdata->chip_data->voltage[cell] = + bmsdata->chips->cell.c_codes[cell]; + } + } /* @@ -570,27 +585,17 @@ int pull_voltages() return 0; } -void pull_thermistors() -{ - read_aux_registers(IC); - - // TODO: Convert voltages to temperatures, store in a data structure -} - -void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]) +void segment_retrieve_data(acc_data_t *bmsdata) { - segment_data = databuf; - /* Pull voltages and thermistors and indiacate if there was a problem during * retrieval */ - voltage_error = pull_voltages(); - pull_thermistors(); + voltage_error = pull_voltages(bmsdata); + read_aux_registers(bmsdata->chips); /* Save the contents of the reading so that we can use it to fill in missing * data */ - memcpy(previous_data, segment_data, sizeof(chipdata_t) * NUM_CHIPS); - - segment_data = NULL; + memcpy(previous_data, bmsdata->chip_data, + sizeof(chipdata_t) * NUM_CHIPS); } bool segment_is_balancing() @@ -599,12 +604,12 @@ bool segment_is_balancing() return false; } -void segment_enable_balancing(bool balance_enable) +void segment_enable_balancing(cell_asic chips[NUM_CHIPS], bool balance_enable) { if (!balance_enable) { // Initializes all array elements to zero bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP] = { 0 }; - segment_configure_balancing(discharge_config); + segment_configure_balancing(chips, discharge_config); } else { /* this func is never called with an arg of true (and shouldn't be given its function) TODO: change this func to just be "segment disable balancing". Kept for now for compatibility with old system @@ -618,17 +623,18 @@ void segment_enable_balancing(bool balance_enable) * @param discharge_config Array containing the discharge configuration. true = discharge, false = do not discharge. */ void segment_configure_balancing( + cell_asic chips[NUM_CHIPS], bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP]) { // DEBUG: Untested // TODO: Test for (int chip = 0; chip < NUM_CHIPS; chip++) { for (int cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { - set_cell_discharge(&IC[chip], cell, + set_cell_discharge(&chips[chip], cell, discharge_config[chip][cell]); } } - write_config_regs(IC); + write_config_regs(chips); } int8_t steinhart_est(uint16_t V) @@ -643,7 +649,7 @@ int8_t steinhart_est(uint16_t V) return 80; } -void averaging_therm_check() +void averaging_therm_check(chipdata_t segment_data[NUM_CHIPS]) { for (int therm = 1; therm <= 16; therm++) { for (int c = 0; c < NUM_CHIPS; c++) { @@ -716,48 +722,48 @@ void averaging_therm_check() } } -void standard_dev_therm_check() -{ - if (previous_data == NULL) - return; - int16_t avg_temp = calc_average(); - uint8_t standard_dev = calc_therm_standard_dev(avg_temp); - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 17; therm < 28; therm++) { - /* - * If difference between thermistor and average is more than - * MAX_STANDARD_DEV set the therm to pack average - */ - if (abs(segment_data[c].thermistor_value[therm] - - avg_temp) > (MAX_STANDARD_DEV * standard_dev)) { - /* Nullify thermistor by setting to pack average */ - segment_data[c].thermistor_value[therm] = - previous_data[c].thermistor_value[therm]; - } - } - } -} - -int8_t calc_therm_standard_dev(int16_t avg_temp) -{ - uint16_t sum_diff_sqrd = 0; - for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { - for (uint8_t therm = 17; therm < 28; therm++) { - uint16_t sum_diff = - abs(segment_data[chip].thermistor_value[therm] - - avg_temp); - sum_diff_sqrd += sum_diff * sum_diff; - } - } - - uint8_t standard_dev = sqrt(sum_diff_sqrd / 88); - if (standard_dev < 8) { - standard_dev = 8; - } - return standard_dev; -} - -int16_t calc_average() +// void standard_dev_therm_check(chipdata_t segment_data[NUM_CHIPS]) +// { +// if (previous_data == NULL) +// return; +// int16_t avg_temp = calc_average(segment_data); +// uint8_t standard_dev = calc_therm_standard_dev(avg_temp); +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// /* +// * If difference between thermistor and average is more than +// * MAX_STANDARD_DEV set the therm to pack average +// */ +// if (abs(segment_data[c].thermistor_value[therm] - +// avg_temp) > (MAX_STANDARD_DEV * standard_dev)) { +// /* Nullify thermistor by setting to pack average */ +// segment_data[c].thermistor_value[therm] = +// previous_data[c].thermistor_value[therm]; +// } +// } +// } +// } + +// int8_t calc_therm_standard_dev(chipdata_t segment_data[NUM_CHIPS], int16_t avg_temp) +// { +// uint16_t sum_diff_sqrd = 0; +// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// uint16_t sum_diff = +// abs(segment_data[chip].thermistor_value[therm] - +// avg_temp); +// sum_diff_sqrd += sum_diff * sum_diff; +// } +// } + +// uint8_t standard_dev = sqrt(sum_diff_sqrd / 88); +// if (standard_dev < 8) { +// standard_dev = 8; +// } +// return standard_dev; +// } + +int16_t calc_average(chipdata_t segment_data[NUM_CHIPS]) { int16_t avg = 0; for (int chip = 0; chip < NUM_CHIPS; chip++) { @@ -770,40 +776,40 @@ int16_t calc_average() return avg; } -void variance_therm_check() -{ - if (previous_data == NULL) { - start_timer(&variance_timer, 1000); - return; - } - - if (is_timer_expired(&variance_timer)) { - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 17; therm < 28; therm++) { - if (abs(segment_data[c] - .thermistor_reading[therm] - - previous_data[c] - .thermistor_reading[therm]) > - 5 && - (segment_data[c].thermistor_reading[therm] < - 10 || - segment_data[c].thermistor_reading[therm] > - 30)) { - segment_data[c] - .thermistor_reading[therm] = - previous_data[c] - .thermistor_reading - [therm]; - segment_data[c].thermistor_value[therm] = - previous_data[c] - .thermistor_value[therm]; - } - } - } - } -} - -void discard_neutrals() +// void variance_therm_check() +// { +// if (previous_data == NULL) { +// start_timer(&variance_timer, 1000); +// return; +// } + +// if (is_timer_expired(&variance_timer)) { +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// if (abs(segment_data[c] +// .thermistor_reading[therm] - +// previous_data[c] +// .thermistor_reading[therm]) > +// 5 && +// (segment_data[c].thermistor_reading[therm] < +// 10 || +// segment_data[c].thermistor_reading[therm] > +// 30)) { +// segment_data[c] +// .thermistor_reading[therm] = +// previous_data[c] +// .thermistor_reading +// [therm]; +// segment_data[c].thermistor_value[therm] = +// previous_data[c] +// .thermistor_value[therm]; +// } +// } +// } +// } +// } + +void discard_neutrals(chipdata_t segment_data[NUM_CHIPS]) { for (uint8_t c = 0; c < NUM_CHIPS; c++) { for (uint8_t therm = 17; therm < 28; therm++) { diff --git a/Core/Src/shep_tasks.c b/Core/Src/shep_tasks.c index 2e04369..60db88f 100644 --- a/Core/Src/shep_tasks.c +++ b/Core/Src/shep_tasks.c @@ -29,7 +29,7 @@ void vGetSegmentData(void *pv_params) { acc_data_t *bmsdata = (acc_data_t *)pv_params; for (;;) { - segment_retrieve_data(bmsdata->chip_data); + segment_retrieve_data(bmsdata); osThreadFlagsSet(analyzer_thread, ANALYZER_FLAG); osDelay(1000 / SAMPLE_RATE); } @@ -47,7 +47,7 @@ void vAnalyzer(void *pv_params) osThreadFlagsWait(ANALYZER_FLAG, osFlagsWaitAny, osWaitForever); osMutexAcquire(bmsdata->mutex, osWaitForever); - disable_therms(bmsdata); + // disable_therms(bmsdata); calc_cell_temps(bmsdata); calc_pack_temps(bmsdata); diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index e59f0a2..802c84b 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -36,18 +36,18 @@ const bool valid_transition_from_to[NUM_STATES][NUM_STATES] = { }; /* private function prototypes */ -void init_boot(void); -void init_ready(void); -void init_charging(void); -void init_faulted(void); +void init_boot(acc_data_t *bmsdata); +void init_ready(acc_data_t *bmsdata); +void init_charging(acc_data_t *bmsdata); +void init_faulted(acc_data_t *bmsdata); void handle_boot(acc_data_t *bmsdata); void handle_ready(acc_data_t *bmsdata); void handle_charging(acc_data_t *bmsdata); void handle_faulted(acc_data_t *bmsdata); -void request_transition(BMSState_t next_state); +void request_transition(acc_data_t *bmsdata, BMSState_t next_state); typedef void (*HandlerFunction_t)(acc_data_t *bmsdata); -typedef void (*InitFunction_t)(); +typedef void (*InitFunction_t)(acc_data_t *bmsdata); const InitFunction_t init_LUT[NUM_STATES] = { &init_boot, &init_ready, &init_charging, &init_faulted }; @@ -56,7 +56,7 @@ const HandlerFunction_t handler_LUT[NUM_STATES] = { &handle_boot, &handle_ready, &handle_charging, &handle_faulted }; -void init_boot() +void init_boot(acc_data_t *bmsdata) { return; } @@ -64,7 +64,7 @@ void init_boot() void handle_boot(acc_data_t *bmsdata) { prevAccData = NULL; - segment_enable_balancing(false); + segment_enable_balancing(bmsdata->chips, false); compute_enable_charging(false); start_timer(&bootup_timer, 10000); printf("Bootup timer started\r\n"); @@ -72,13 +72,13 @@ void handle_boot(acc_data_t *bmsdata) compute_set_fault(1); // bmsdata->fault_code = FAULTS_CLEAR; - request_transition(READY_STATE); + request_transition(bmsdata, READY_STATE); return; } -void init_ready() +void init_ready(acc_data_t *bmsdata) { - segment_enable_balancing(false); + segment_enable_balancing(bmsdata->chips, false); compute_enable_charging(false); return; } @@ -88,14 +88,14 @@ void handle_ready(acc_data_t *bmsdata) /* check for charger connection */ if (compute_charger_connected() && is_timer_expired(&bootup_timer)) { // TODO Fix once charger works - request_transition(READY_STATE); + request_transition(bmsdata, READY_STATE); } else { sm_broadcast_current_limit(bmsdata); return; } } -void init_charging() +void init_charging(acc_data_t *bmsdata) { cancel_timer(&charger_settle_countup); return; @@ -104,7 +104,7 @@ void init_charging() void handle_charging(acc_data_t *bmsdata) { if (!compute_charger_connected()) { - request_transition(READY_STATE); + request_transition(bmsdata, READY_STATE); return; } else { @@ -120,7 +120,7 @@ void handle_charging(acc_data_t *bmsdata) if (sm_balancing_check(bmsdata)) sm_balance_cells(bmsdata); else - segment_enable_balancing(false); + segment_enable_balancing(bmsdata->chips, false); /* Send CAN message, but not too often */ if (is_timer_expired(&charger_message_timer) || @@ -135,9 +135,9 @@ void handle_charging(acc_data_t *bmsdata) } } -void init_faulted() +void init_faulted(acc_data_t *bmsdata) { - segment_enable_balancing(false); + segment_enable_balancing(bmsdata->chips, false); compute_enable_charging(false); entered_faulted = true; return; @@ -152,7 +152,7 @@ void handle_faulted(acc_data_t *bmsdata) if (bmsdata->fault_code == FAULTS_CLEAR) { compute_set_fault(1); - request_transition(BOOT_STATE); + request_transition(bmsdata, BOOT_STATE); return; } @@ -173,7 +173,7 @@ void sm_handle_state(acc_data_t *bmsdata) if (bmsdata->fault_code != FAULTS_CLEAR) { bmsdata->discharge_limit = 0; - request_transition(FAULTED_STATE); + request_transition(bmsdata, FAULTED_STATE); } handler_LUT[current_state](bmsdata); @@ -183,14 +183,14 @@ void sm_handle_state(acc_data_t *bmsdata) sm_broadcast_current_limit(bmsdata); } -void request_transition(BMSState_t next_state) +void request_transition(acc_data_t *bmsdata, BMSState_t next_state) { if (current_state == next_state) return; if (!valid_transition_from_to[current_state][next_state]) return; - init_LUT[next_state](); + init_LUT[next_state](bmsdata); current_state = next_state; } @@ -472,7 +472,7 @@ void sm_balance_cells(acc_data_t *bms_data) } #endif - segment_configure_balancing(balanceConfig); + segment_configure_balancing(bms_data->chips, balanceConfig); } void calculate_pwm(acc_data_t *bmsdata)