Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/segment mapping #92

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 5 additions & 6 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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++)
Expand Down 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
47 changes: 34 additions & 13 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,46 @@ 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++) {

/* 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) {
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][j];
}

dest_index++;
}


}


/* Start the timer between readings if successful */
start_timer(&voltage_reading_timer, VOLTAGE_WAIT_TIME);
return 0;
Expand Down Expand Up @@ -205,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 */
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Loading