Skip to content

Commit

Permalink
remapped segment
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Apr 12, 2024
1 parent fa2114a commit a0ff597
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();




Expand All @@ -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
Expand Down
36 changes: 25 additions & 11 deletions Core/Src/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit a0ff597

Please sign in to comment.