From a0ff59705f26ca5725a7ee007dac4fce6f275bad Mon Sep 17 00:00:00 2001 From: Dylan Donahue Date: Thu, 11 Apr 2024 22:09:16 -0400 Subject: [PATCH 1/2] remapped segment --- Core/Inc/bmsConfig.h | 2 +- Core/Src/main.c | 7 +++---- Core/Src/segment.c | 36 +++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Core/Inc/bmsConfig.h b/Core/Inc/bmsConfig.h index b070d58..24dd17f 100644 --- a/Core/Inc/bmsConfig.h +++ b/Core/Inc/bmsConfig.h @@ -4,7 +4,7 @@ // Hardware definition #define NUM_SEGMENTS 6 #define NUM_CHIPS NUM_SEGMENTS* 2 -#define NUM_CELLS_PER_CHIP 10 +#define NUM_CELLS_PER_CHIP 9 #define NUM_THERMS_PER_CHIP 32 #define NUM_RELEVANT_THERMS 5 diff --git a/Core/Src/main.c b/Core/Src/main.c index f2f2b68..298e73e 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -267,9 +267,8 @@ int main(void) * Not state specific */ segment_retrieve_data(acc_data->chip_data); - acc_data->pack_current = (int16_t)compute_get_pack_current(); - //volatile float temp = compute_get_pack_current(); - printf("Pack Current: %d\r\n", acc_data->pack_current); + acc_data->pack_current = compute_get_pack_current(); + @@ -286,7 +285,7 @@ int main(void) HAL_GPIO_WritePin(Watchdog_Out_GPIO_Port, Watchdog_Out_Pin, GPIO_PIN_RESET); #ifdef DEBUG_STATS - //print_bms_stats(acc_data); + print_bms_stats(acc_data); #endif // TODO - possibly optimize timing, every loop might be excessive diff --git a/Core/Src/segment.c b/Core/Src/segment.c index 283865e..27f3962 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -102,6 +102,10 @@ int pull_voltages() * just copy over the contents of the last good reading and the fault status * from the most recent attempt */ + + /* our segments are mapped backwards and in pairs, so they are read in 1,0 then 3,2, etc*/ + int mapping_correction[12] = {1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10}; + 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_reading, previous_data[i].voltage_reading, @@ -121,31 +125,41 @@ int pull_voltages() */ if (LTC6804_rdcv(ltc68041, 0, NUM_CHIPS, segment_voltages) == -1) { for (uint8_t i = 0; i < NUM_CHIPS; i++) { - memcpy(segment_data[i].voltage_reading, previous_data[i].voltage_reading, - sizeof(segment_data[i].voltage_reading)); + int corrected_index = mapping_correction[i]; + memcpy(segment_data[corrected_index].voltage_reading, previous_data[i].voltage_reading, + sizeof(segment_data[corrected_index].voltage_reading)); } return 1; } /* If the read was successful, copy the voltage data */ for (uint8_t i = 0; i < NUM_CHIPS; i++) { - for (uint8_t j = 0; j < NUM_CELLS_PER_CHIP; j++) { - if (abs(segment_voltages[i][j] - previous_data[i].voltage_reading[j]) + int corrected_index = mapping_correction[i]; + /* correction to account for missing index, see more info below */ + int dest_index = 0; + for (uint8_t j = 0; j < NUM_CELLS_PER_CHIP + 1; j++) { + + + if (abs(segment_voltages[i][dest_index] - previous_data[i].voltage_reading[dest_index]) > MAX_VOLT_DELTA) { - segment_data[i].voltage_reading[j] = previous_data[i].voltage_reading[j]; - segment_data[i].bad_volt_diff_count[j]++; + segment_data[corrected_index].voltage_reading[dest_index] = previous_data[i].voltage_reading[dest_index]; + segment_data[corrected_index].bad_volt_diff_count[dest_index]++; - if (segment_data[i].bad_volt_diff_count[j] > MAX_VOLT_DELTA_COUNT) { - segment_data[i].bad_volt_diff_count[j] = 0; - segment_data[i].voltage_reading[j] = segment_voltages[i][j]; + if (segment_data[corrected_index].bad_volt_diff_count[dest_index] > MAX_VOLT_DELTA_COUNT) { + segment_data[corrected_index].bad_volt_diff_count[dest_index] = 0; + segment_data[corrected_index].voltage_reading[dest_index] = segment_voltages[i][j]; } } else { - segment_data[i].bad_volt_diff_count[j] = 0; - segment_data[i].voltage_reading[j] = segment_voltages[i][j]; + segment_data[corrected_index].bad_volt_diff_count[dest_index] = 0; + segment_data[corrected_index].voltage_reading[dest_index] = segment_voltages[i][dest_index]; } } + + /* cell 6 on every chip is not a real reading, we need to have the array skip this */ + if (dest_index != 5) dest_index++; } + /* Start the timer between readings if successful */ start_timer(&voltage_reading_timer, VOLTAGE_WAIT_TIME); return 0; From c4dbf7a1016a28fe49838bd5f1f5e114559568f4 Mon Sep 17 00:00:00 2001 From: Dylan Donahue Date: Thu, 11 Apr 2024 22:56:37 -0400 Subject: [PATCH 2/2] fixed mapping --- Core/Src/main.c | 4 ++-- Core/Src/segment.c | 17 ++++++++++++----- Core/Src/stateMachine.c | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 298e73e..6368783 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -142,7 +142,7 @@ const void print_bms_stats(acc_data_t *acc_data) if (current_state == 0) printf("BOOT\r\n"); else if (current_state == 1) printf("READY\r\n"); else if (current_state == 2) printf("CHARGING\r\n"); - else if (current_state == 1) printf("FAULTED\r\n"); + else if (current_state == 3) printf("FAULTED\r\n"); printf("Raw Cell Voltage:\r\n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { @@ -153,7 +153,7 @@ const void print_bms_stats(acc_data_t *acc_data) printf("\r\n"); } - printf("Open Cell Voltage:\n"); + printf("Open Cell Voltage:\r\n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) diff --git a/Core/Src/segment.c b/Core/Src/segment.c index 27f3962..180385c 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -135,10 +135,14 @@ int pull_voltages() /* If the read was successful, copy the voltage data */ for (uint8_t i = 0; i < NUM_CHIPS; i++) { int corrected_index = mapping_correction[i]; + /* correction to account for missing index, see more info below */ 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*/ + if (j == 5) continue; if (abs(segment_voltages[i][dest_index] - previous_data[i].voltage_reading[dest_index]) > MAX_VOLT_DELTA) { @@ -151,12 +155,13 @@ int pull_voltages() } } else { segment_data[corrected_index].bad_volt_diff_count[dest_index] = 0; - segment_data[corrected_index].voltage_reading[dest_index] = segment_voltages[i][dest_index]; + segment_data[corrected_index].voltage_reading[dest_index] = segment_voltages[i][j]; } + + dest_index++; } - /* cell 6 on every chip is not a real reading, we need to have the array skip this */ - if (dest_index != 5) dest_index++; + } @@ -219,10 +224,12 @@ int pull_thermistors() } } start_timer(&therm_timer, THERM_WAIT_TIME); /* Start timer for next reading */ - variance_therm_check(); + + /* 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(); + //discard_neutrals(); return 0; /* Read successfully */ } diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index f17a103..469b86f 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -77,7 +77,7 @@ void init_ready() void handle_ready(acc_data_t* bmsdata) { /* check for charger connection */ - if (compute_charger_connected()) { + if (NULL/*compute_charger_connected()*/) { //TODO Fix once charger works request_transition(CHARGING_STATE); } else { sm_broadcast_current_limit(bmsdata); @@ -163,7 +163,7 @@ void sm_handle_state(acc_data_t* bmsdata) bmsdata->max_temp.val = 75; bmsdata->fault_code = sm_fault_return(bmsdata); - calculate_pwm(bmsdata); + //calculate_pwm(bmsdata); if (bmsdata->fault_code != FAULTS_CLEAR) {