diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index 1673096..ae9763f 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -184,6 +184,10 @@ void compute_send_cell_temp_message(acc_data_t *bmsdata); void compute_send_segment_temp_message(acc_data_t *bmsdata); void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl); + +void compute_send_debug_message(uint8_t debug0, uint8_t debug1, uint16_t debug2, + uint32_t debug3); + void compute_send_voltage_noise_message(acc_data_t *bmsdata); #endif // COMPUTE_H diff --git a/Core/Inc/stateMachine.h b/Core/Inc/stateMachine.h index d68e73e..9e20cda 100644 --- a/Core/Inc/stateMachine.h +++ b/Core/Inc/stateMachine.h @@ -1,74 +1,79 @@ #ifndef BMS_STATES_H #define BMS_STATES_H +#include "analyzer.h" +#include "compute.h" #include "datastructs.h" #include "segment.h" -#include "compute.h" -#include "analyzer.h" #include "timer.h" /* global that can be read for debugging in main */ extern BMSState_t current_state; +/* global defined in segment.c that keeps an eye on the number of crc errors */ +extern uint16_t crc_error_check; + #define NUM_FAULTS 8 /** -* @brief Returns if we want to balance cells during a particular frame -* -* @param bmsdata -* @return true -* @return false -*/ + * @brief Returns if we want to balance cells during a particular frame + * + * @param bmsdata + * @return true + * @return false + */ bool sm_balancing_check(acc_data_t *bmsdata); /** -* @brief Returns if we want to charge cells during a particular frame -* -* @param bmsdata -* @return true -* @return false -*/ + * @brief Returns if we want to charge cells during a particular frame + * + * @param bmsdata + * @return true + * @return false + */ bool sm_charging_check(acc_data_t *bmsdata); /** -* @brief Returns any new faults or current faults that have come up -* @note Should be bitwise OR'ed with the current fault status -* -* @param accData -* @return uint32_t -*/ + * @brief Returns any new faults or current faults that have come up + * @note Should be bitwise OR'ed with the current fault status + * + * @param accData + * @return uint32_t + */ uint32_t sm_fault_return(acc_data_t *accData); /** - * @brief Used in parellel to faultReturn(), calculates each fault to append the fault status - * + * @brief Used in parellel to faultReturn(), calculates each fault to append the + * fault status + * * @param index * @return fault_code */ uint32_t sm_fault_eval(fault_eval_t *index); /** - * @brief handles the state machine, calls the appropriate handler function and runs every loop functions - * - * @param bmsdata + * @brief handles the state machine, calls the appropriate handler function and + * runs every loop functions + * + * @param bmsdata */ void sm_handle_state(acc_data_t *bmsdata); /** -* @brief Algorithm behind determining which cells we want to balance -* @note Directly interfaces with the segments -* -* @param bms_data -*/ + * @brief Algorithm behind determining which cells we want to balance + * @note Directly interfaces with the segments + * + * @param bms_data + */ void sm_balance_cells(acc_data_t *bms_data); void sm_broadcast_current_limit(acc_data_t *bmsdata); /** * @brief algorithm to calculate and set fan speed based on temperature - * - * @param bmsdata * -*/ + * @param bmsdata + * + */ void calculate_pwm(acc_data_t *bmsdata); -#endif //BMS_STATES_H \ No newline at end of file +#endif // BMS_STATES_H \ No newline at end of file diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 7ba5999..472ea4d 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -1,12 +1,12 @@ #include "compute.h" -#include "can_handler.h" -#include "can.h" #include "c_utils.h" +#include "can.h" +#include "can_handler.h" #include "main.h" -#include #include "stm32f405xx.h" -#include +#include #include +#include #define MAX_CAN1_STORAGE 10 #define MAX_CAN2_STORAGE 10 @@ -14,7 +14,7 @@ #define REF_CHANNEL 0 #define VOUT_CHANNEL 1 -//#define CHARGING_ENABLED +// #define CHARGING_ENABLED uint8_t fan_speed; bool is_charging_enabled; @@ -50,14 +50,14 @@ uint8_t compute_init() can1.hcan = &hcan1; can1.id_list = can1_id_list; can1.id_list_len = sizeof(can1_id_list) / sizeof(can1_id_list[0]); - //can1.callback = can_receive_callback; + // can1.callback = can_receive_callback; can1_rx_queue = ringbuffer_create(MAX_CAN1_STORAGE, sizeof(can_msg_t)); can_init(&can1); can2.hcan = &hcan2; can2.id_list = can2_id_list; can2.id_list_len = sizeof(can2_id_list) / sizeof(can2_id_list[0]); - //can2.callback = can_receive_callback; + // can2.callback = can_receive_callback; can2_rx_queue = ringbuffer_create(MAX_CAN2_STORAGE, sizeof(can_msg_t)); can_init(&can2); @@ -95,8 +95,10 @@ int compute_send_charging_message(uint16_t voltage_to_set, uint16_t current_to_set, acc_data_t *bms_data) { struct __attribute__((__packed__)) { - uint16_t charger_voltage; // Note the charger voltage sent over should be 10*desired voltage - uint16_t charger_current; // Note the charge current sent over should be 10*desired current + uint16_t charger_voltage; // Note the charger voltage sent over should be + // 10*desired voltage + uint16_t charger_current; // Note the charge current sent over should be + // 10*desired current uint8_t charger_control; uint8_t reserved_1; uint16_t reserved_23; @@ -106,7 +108,7 @@ int compute_send_charging_message(uint16_t voltage_to_set, charger_msg_data.charger_current = current_to_set * 10; if (is_charging_enabled) { - charger_msg_data.charger_control = 0x00; //0:Start charging. + charger_msg_data.charger_control = 0x00; // 0:Start charging. } else { charger_msg_data.charger_control = 0xFF; // 1:battery protection, stop charging @@ -139,15 +141,15 @@ int compute_send_charging_message(uint16_t voltage_to_set, bool compute_charger_connected() { - //TODO need to set up CAN msg that actually toggles this bool - return false; //bmsdata->is_charger_connected; + // TODO need to set up CAN msg that actually toggles this bool + return false; // bmsdata->is_charger_connected; } -//TODO add this back -// void compute_charger_callback(const CAN_message_t& msg) -// { -// return; -// } +// TODO add this back +// void compute_charger_callback(const CAN_message_t& msg) +// { +// return; +// } uint8_t compute_set_fan_speed(TIM_HandleTypeDef *pwmhandle, fan_select_t fan_select, uint8_t duty_cycle) @@ -170,9 +172,9 @@ uint8_t compute_set_fan_speed(TIM_HandleTypeDef *pwmhandle, void compute_set_fault(int fault_state) { - //TODO work with charger fw on this + // TODO work with charger fw on this HAL_GPIO_WritePin(GPIOA, Fault_Output_Pin, !fault_state); - //if (true) digitalWrite(CHARGE_SAFETY_RELAY, 1); + // if (true) digitalWrite(CHARGE_SAFETY_RELAY, 1); } int16_t compute_get_pack_current() @@ -192,13 +194,13 @@ int16_t compute_get_pack_current() // int16_t current = (vout - ref_voltage - OFFSET) / (GAIN); // convert to V // /* Low Pass Filter of Current*/ - // current = ((current_accumulator * (num_samples - 1)) + current) / num_samples; - // current_accumulator = current; + // current = ((current_accumulator * (num_samples - 1)) + current) / + // num_samples; current_accumulator = current; // return current; - static const float CURRENT_LOWCHANNEL_MAX = 75.0; //Amps - static const float CURRENT_LOWCHANNEL_MIN = -75.0; //Amps + static const float CURRENT_LOWCHANNEL_MAX = 75.0; // Amps + static const float CURRENT_LOWCHANNEL_MIN = -75.0; // Amps // static const float CURRENT_SUPPLY_VOLTAGE = 5.038; static const float CURRENT_ADC_RESOLUTION = 5.0 / MAX_ADC_RESOLUTION; @@ -250,15 +252,16 @@ int16_t compute_get_pack_current() (1000 * CURRENT_LOWCHANNEL_OFFSET)) * (1 / 26.7); //* (LOWCHANNEL_GAIN/100.0f))/1000; - // If the current is scoped within the range of the low channel, use the low channel + // If the current is scoped within the range of the low channel, use the low + // channel if ((low_current < CURRENT_LOWCHANNEL_MAX - 5.0 && low_current >= 0) || (low_current > CURRENT_LOWCHANNEL_MIN + 5.0 && low_current < 0)) { - //printf("\rLow Current: %d\n", -low_current); + // printf("\rLow Current: %d\n", -low_current); return -low_current; } - //printf("\rHigh Current: %d\n", -high_current); + // printf("\rHigh Current: %d\n", -high_current); return -high_current; } @@ -666,6 +669,40 @@ void compute_send_voltage_noise_message(acc_data_t *bmsdata) can_send_msg(line, &acc_msg); } + +void compute_send_debug_message(uint8_t debug0, uint8_t debug1, uint16_t debug2, + uint32_t debug3) +{ + struct __attribute__((__packed__)) { + uint8_t debug0; + uint8_t debug1; + uint16_t debug2; + uint32_t debug3; + } debug_msg_data; + + debug_msg_data.debug0 = debug0; + debug_msg_data.debug1 = debug1; + debug_msg_data.debug2 = debug2; + debug_msg_data.debug3 = debug3; + + can_msg_t debug_msg; + debug_msg.id = 0x702; + debug_msg.len = 8; // yaml decodes this msg as 8 bytes + + endian_swap(&debug_msg_data.debug2, sizeof(debug_msg_data.debug2)); + endian_swap(&debug_msg_data.debug3, sizeof(debug_msg_data.debug3)); + + memcpy(debug_msg.data, &debug_msg_data, 8); + +#ifdef CHARGING_ENABLED + can_t *line = &can2; +#else + can_t *line = &can1; +#endif + + can_send_msg(line, &debug_msg); +} + void change_adc1_channel(uint8_t channel) { ADC_ChannelConfTypeDef sConfig = { 0 }; diff --git a/Core/Src/segment.c b/Core/Src/segment.c index 921edf7..7faf314 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -1,9 +1,9 @@ #include "segment.h" -#include -#include -#include #include "main.h" #include +#include +#include +#include #define THERM_WAIT_TIME 500 /* ms */ #define VOLTAGE_WAIT_TIME 100 /* ms */ @@ -13,7 +13,7 @@ #define GPIO_EXPANDER_ADDR 0x40 #define GPIO_REGISTER_ADDR 0x09 -//TODO ensure spi 1 is correct for talking to segs +// TODO ensure spi 1 is correct for talking to segs extern SPI_HandleTypeDef hspi1; ltc_config *ltc68041; @@ -28,10 +28,12 @@ nertimer_t therm_timer; nertimer_t voltage_reading_timer; nertimer_t variance_timer; -int voltage_error = 0; //not faulted -int therm_error = 0; //not faulted +int voltage_error = 0; // not faulted +int therm_error = 0; // not faulted +uint16_t crc_error_check = 0; -/* our segments are mapped backwards and in pairs, so they are read in 1,0 then 3,2, etc*/ +/* our segments are mapped backwards and in pairs, so they are read in 1,0 then + * 3,2, etc*/ const int mapping_correction[12] = { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10 }; uint16_t therm_settle_time_ = 0; @@ -131,12 +133,13 @@ void select_therm(uint8_t therm) int pull_voltages() { /** - * 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 - */ + * 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 + */ - //int test_v[12] = {800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800}; + // int test_v[12] = {800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, + // 800}; if (!is_timer_expired(&voltage_reading_timer) && voltage_reading_timer.active) { for (uint8_t i = 0; i < NUM_CHIPS; i++) { @@ -153,15 +156,16 @@ int pull_voltages() LTC6804_adcv(ltc68041); /** - * If we received an incorrect PEC indicating a bad read - * copy over the data from the last good read and indicate an error - */ + * If we received an incorrect PEC indicating a bad read + * copy over the data from the last good read and indicate an error + */ if (LTC6804_rdcv(ltc68041, 0, NUM_CHIPS, raw_voltages) == -1) { for (uint8_t i = 0; i < NUM_CHIPS; i++) { memcpy(segment_data[i].voltage, previous_data[i].voltage, sizeof(segment_data[i].voltage)); + crc_error_check++; printf("Bad voltage read\n"); } return 1; @@ -175,7 +179,8 @@ int pull_voltages() int dest_index = 0; for (uint8_t j = 0; j < NUM_CELLS_PER_CHIP + 1; j++) { - /* cell 6 on every chip is not a real reading, we need to have the array skip this, and shift the remaining readings up one index*/ + /* cell 6 on every chip is not a real reading, we need to have the array + * skip this, and shift the remaining readings up one index*/ if (j == 5) continue; @@ -186,7 +191,9 @@ int pull_voltages() (int)(10000 * (MAX_VOLT + 0.5)) || raw_voltages[i][j] < (int)(10000 * (MIN_VOLT - 0.5))) { - //if (previous_data[corrected_index].voltage[dest_index] > 45000 || previous_data[corrected_index].voltage[dest_index] < 20000) printf("poop\r\n"); + // if (previous_data[corrected_index].voltage[dest_index] > 45000 || + // previous_data[corrected_index].voltage[dest_index] < 20000) + // printf("poop\r\n"); segment_data[corrected_index] .voltage[dest_index] = previous_data[corrected_index] @@ -195,16 +202,21 @@ int pull_voltages() .noise_reading[dest_index] = 1; segment_data[corrected_index] .consecutive_noise[dest_index]++; - //printf("New data: %d\r\n", segment_data[corrected_index].voltage[dest_index]); - // if (segment_data[corrected_index].consecutive_noise[dest_index] > MAX_CONSEC_NOISE) { - // segment_data[corrected_index].noise_reading[dest_index] = 0; - // segment_data[corrected_index].consecutive_noise[dest_index] = 0; - // segment_data[corrected_index].voltage[dest_index] = raw_voltages[i][j]; - // } + // printf("New data: %d\r\n", + // segment_data[corrected_index].voltage[dest_index]); + // if (segment_data[corrected_index].consecutive_noise[dest_index] > + // MAX_CONSEC_NOISE) { + // segment_data[corrected_index].noise_reading[dest_index] = 0; + // segment_data[corrected_index].consecutive_noise[dest_index] = 0; + // segment_data[corrected_index].voltage[dest_index] = + // raw_voltages[i][j]; + // } } else { - //printf("previous: %d\r\n", previous_data[corrected_index].voltage[dest_index]); - //if (previous_data[corrected_index].voltage[dest_index] > 45000 || previous_data[corrected_index].voltage[dest_index] < 20000) printf("pee\r\n"); - //else printf("wiping\r\n"); + // printf("previous: %d\r\n", + // previous_data[corrected_index].voltage[dest_index]); if + // (previous_data[corrected_index].voltage[dest_index] > 45000 || + // previous_data[corrected_index].voltage[dest_index] < 20000) + // printf("pee\r\n"); else printf("wiping\r\n"); segment_data[corrected_index] .consecutive_noise[dest_index] = 0; segment_data[corrected_index] @@ -216,8 +228,9 @@ int pull_voltages() previous_data[corrected_index] .voltage[dest_index] = raw_voltages[i][j]; - //printf("previous: %d\r\n", previous_data[corrected_index].voltage[dest_index]); - //printf("raw: %d\r\n", segment_data[corrected_index].voltage[dest_index]); + // printf("previous: %d\r\n", + // previous_data[corrected_index].voltage[dest_index]); printf("raw: + // %d\r\n", segment_data[corrected_index].voltage[dest_index]); } } dest_index++; @@ -255,7 +268,7 @@ int pull_thermistors() /* Sets multiplexors to select thermistors */ select_therm(current_therm); HAL_Delay(200); - //push_chip_configuration(); + // push_chip_configuration(); LTC6804_clraux(ltc68041); LTC6804_adax(ltc68041); /* Run ADC for AUX (GPIOs and refs) */ HAL_Delay(3); @@ -265,9 +278,9 @@ int pull_thermistors() for (uint8_t c = 0; c < NUM_CHIPS; c++) { int corrected_index = mapping_correction[c]; /* - * Get current temperature LUT. Voltage is adjusted to account for 5V reg - * fluctuations (index 2 is a reading of the ADC 5V ref) - */ + * Get current temperature LUT. Voltage is adjusted to account for 5V reg + * fluctuations (index 2 is a reading of the ADC 5V ref) + */ if (therm == current_therm) { /* see "thermister decoding" in confluence in shepherd software 22A */ uint16_t steinhart_input_low = @@ -291,7 +304,7 @@ int pull_thermistors() steinhart_est(steinhart_input_high); /* Directly update for a set time from start up due to therm voltages - * needing to settle */ + * needing to settle */ segment_data[corrected_index] .thermistor_value[therm - 1] = segment_data[corrected_index] @@ -354,11 +367,12 @@ int pull_thermistors() start_timer(&therm_timer, 100 /*THERM_WAIT_TIME*/); /* Start timer for next reading */ - /* the following algorithms were used to eliminate noise on Car 17D - keep them off if possible */ - //variance_therm_check(); - //standard_dev_therm_check(); - //averaging_therm_check(); - //discard_neutrals(); + /* the following algorithms were used to eliminate noise on Car 17D - keep + * them off if possible */ + // variance_therm_check(); + // standard_dev_therm_check(); + // averaging_therm_check(); + // discard_neutrals(); return 0; /* Read successfully */ } @@ -368,12 +382,12 @@ void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]) segment_data = databuf; /* Pull voltages and thermistors and indiacate if there was a problem during - * retrieval */ + * retrieval */ voltage_error = pull_voltages(); therm_error = pull_thermistors(); /* Save the contents of the reading so that we can use it to fill in missing - * data */ + * data */ memcpy(previous_data, segment_data, sizeof(chipdata_t) * NUM_CHIPS); segment_data = NULL; @@ -382,15 +396,15 @@ void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]) void configure_discharge(uint8_t chip, uint16_t cells) { /* - * chipConfigurations[chip][4] == chipConfigurations[Literally what chip you - * want][register] 4 and 5 are registers to discharge chips - */ + * chipConfigurations[chip][4] == chipConfigurations[Literally what chip you + * want][register] 4 and 5 are registers to discharge chips + */ local_config[chip][4] = (uint8_t)(cells & 0x00FF); /* - * Register 5 is split in half, so we maintain the upper half and add in the - * bottom half to discharge cells - */ + * Register 5 is split in half, so we maintain the upper half and add in the + * bottom half to discharge cells + */ local_config[chip][5] = (local_config[chip][5] & 0xF0) + (uint8_t)(cells >> 8); } @@ -398,9 +412,9 @@ void configure_discharge(uint8_t chip, uint16_t cells) void segment_enable_balancing(bool balance_enable) { /* - * Discharging all cells in series - * Making the discharge command all 1's for all cells per chip - */ + * Discharging all cells in series + * Making the discharge command all 1's for all cells per chip + */ static const uint16_t DICHARGE_ALL_COMMAND = 0xFFFF >> (16 - NUM_CELLS_PER_CHIP); @@ -554,7 +568,7 @@ void averaging_therm_check() for (int therm = 1; therm <= 16; therm++) { for (int c = 0; c < NUM_CHIPS; c++) { /* Directly update for a set time from start up due to therm voltages - * needing to settle */ + * needing to settle */ if (therm_avg_counter < THERM_AVG * 10) { segment_data[c].thermistor_value[therm - 1] = segment_data[c] @@ -570,7 +584,7 @@ void averaging_therm_check() .thermistor_reading[therm - 1] != 33) { /* If measured value is larger than current "averaged" value, - * increment value */ + * increment value */ if (segment_data[c] .thermistor_reading[therm - 1] > @@ -581,7 +595,7 @@ void averaging_therm_check() .thermistor_value[therm - 1]++; /* If measured value is smaller than current "averaged" value, - * decrement value */ + * decrement value */ } else if (segment_data[c] .thermistor_reading [therm - 1] < @@ -631,9 +645,9 @@ void standard_dev_therm_check() 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 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 */ diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index 45ae75f..f8e0ec0 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -1,6 +1,6 @@ #include "stateMachine.h" -#include #include +#include #define MIN(a, b) (((a) < (b)) ? (a) : (b)) extern UART_HandleTypeDef huart4; @@ -87,7 +87,7 @@ 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 + is_timer_expired(&bootup_timer)) { // TODO Fix once charger works request_transition(READY_STATE); } else { sm_broadcast_current_limit(bmsdata); @@ -159,8 +159,8 @@ void handle_faulted(acc_data_t *bmsdata) else { compute_set_fault(0); - //TODO update to HAL - //digitalWrite(CHARGE_SAFETY_RELAY, 0); + // TODO update to HAL + // digitalWrite(CHARGE_SAFETY_RELAY, 0); } return; } @@ -177,12 +177,13 @@ void sm_handle_state(acc_data_t *bmsdata) SEGMENT_TEMP, MC_DISCHARGE, MC_CHARGE, + CAN_DEBUG, MAX_MSGS }; bmsdata->fault_code = sm_fault_return(bmsdata); - //calculate_pwm(bmsdata); + // calculate_pwm(bmsdata); if (bmsdata->fault_code != FAULTS_CLEAR) { bmsdata->discharge_limit = 0; @@ -224,6 +225,9 @@ void sm_handle_state(acc_data_t *bmsdata) case MC_CHARGE: compute_send_mc_charge_message(bmsdata); break; + + case CAN_DEBUG: + compute_send_debug_message(0,0, crc_error_check, 0); default: break; @@ -263,7 +267,8 @@ uint32_t sm_fault_return(acc_data_t *accData) fault_data = accData; if (!fault_table) { - /* Note that we are only allocating this table once at runtime, so there is no need to free it */ + /* Note that we are only allocating this table once at runtime, so there is + * no need to free it */ fault_table = (fault_eval_t *)malloc(NUM_FAULTS * sizeof(fault_eval_t)); // clang-format off @@ -308,7 +313,7 @@ uint32_t sm_fault_return(acc_data_t *accData) fault_status |= sm_fault_eval(&fault_table[incr]); incr++; } - //TODO: Remove This !!!! + // TODO: Remove This !!!! fault_status &= ~DISCHARGE_LIMIT_ENFORCEMENT_FAULT; return fault_status; } @@ -380,16 +385,20 @@ uint32_t sm_fault_eval(fault_eval_t *index) return 0; } /* if (index->code == CELL_VOLTAGE_TOO_LOW) { - printf("\t\t\t*******Not fautled!!!!!\t%d\r\n", !is_timer_active(&index->timer) && condition1 && condition2); - printf("More stats...\t:%d\t%d\r\n", is_timer_expired(&index->timer), index->timer.active); - } */ + printf("\t\t\t*******Not fautled!!!!!\t%d\r\n", + !is_timer_active(&index->timer) && condition1 && condition2); printf("More + stats...\t:%d\t%d\r\n", is_timer_expired(&index->timer), index->timer.active); + } */ printf("err should not get here"); return 0; } -/* charger settle countup = 1 minute pause to let readings settle and get good OCV */ -/* charger settle countdown = 5 minute interval between 1 minute settle pauses */ -/* charger_max_volt_timer = interval of time when voltage is too high before trying to start again */ +/* charger settle countup = 1 minute pause to let readings settle and get good + * OCV */ +/* charger settle countdown = 5 minute interval between 1 minute settle pauses + */ +/* charger_max_volt_timer = interval of time when voltage is too high before + * trying to start again */ bool sm_charging_check(acc_data_t *bmsdata) { if (!compute_charger_connected()) { @@ -494,8 +503,8 @@ void sm_balance_cells(acc_data_t *bms_data) { bool balanceConfig[NUM_CHIPS][NUM_CELLS_PER_CHIP]; - /* For all cells of all the chips, figure out if we need to balance by comparing the difference - * in voltages */ + /* For all cells of all the chips, figure out if we need to balance by + * comparing the difference in voltages */ for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { uint16_t delta =