Skip to content

Commit

Permalink
Merge branch 'develop' into p45b-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz authored Feb 2, 2025
2 parents 4c3a137 + 30a3874 commit 881f0d9
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define CHARGE_VOLT_TIMEOUT 300000 // 5 minutes, may need adjustment
#define VOLT_SAG_MARGIN \
0.45 // Volts above the minimum cell voltage we would like to aim for
#define OCV_CURR_THRESH 1.5
#define OCV_CURR_THRESH 0.0015 /* 1.5 mA */

#define OCV_AVG 3

Expand Down
189 changes: 110 additions & 79 deletions Core/Src/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,89 +546,120 @@ void calc_cont_ccl(acc_data_t *bmsdata)
}
}

//TODO: Make it actually calc OCVs. Revise algorithm and stuff.
//TODO: Change for new cells (probs not needed).
void calc_open_cell_voltage(acc_data_t *bmsdata)
{
//TODO: MAKE NOT SHIT :)

// static chipdata_t prev_chipdata[12];

// /* if there is no previous data point, set inital open cell voltage to current reading */
// if (is_first_reading_) {
// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// uint8_t num_cells =
// get_num_cells(&bmsdata->chip_data[chip]);
// for (uint8_t cell = 0; cell < num_cells; cell++) {
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// bmsdata->chip_data[chip]
// .cell_voltages[cell];
// prev_chipdata[chip].open_cell_voltage[cell] =
// bmsdata->chip_data[chip]
// .cell_voltages[cell];
// }
// }
// return;
// }
// /* If we are within the current threshold for open voltage measurments */
// else if (bmsdata->pack_current < (OCV_CURR_THRESH * 10) &&
// bmsdata->pack_current > (-OCV_CURR_THRESH * 10)) {
// if (is_timer_expired(&ocvTimer) ||
// !is_timer_active(&ocvTimer)) {
// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// uint8_t num_cells = get_num_cells(
// &bmsdata->chip_data[chip]);
// for (uint8_t cell = 0; cell < num_cells;
// cell++) {
// /* Sets open cell voltage to a moving average of OCV_AVG values */
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// ((bmsdata->chip_data[chip].cell_voltages[cell];
// ((prev_chipdata[chip].open_cell_voltage
// [cell]) *
// (OCV_AVG - 1))) /
// OCV_AVG;
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// bmsdata->chips[chip]
// .fcell.fc_codes[cell];

// if (bmsdata->chip_data[chip]
// .open_cell_voltage[cell] >
// MAX_VOLT * 10000) {
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// prev_chipdata[chip]
// .open_cell_voltage
// [cell];
// } else if (bmsdata->chip_data[chip]
// .open_cell_voltage
// [cell] <
// MIN_VOLT * 10000) {
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// prev_chipdata[chip]
// .open_cell_voltage
// [cell];
// }
// }
// }
// return;
// }
// } else {
// start_timer(&ocvTimer, 1000);
// }
// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// uint8_t num_cells = get_num_cells(&bmsdata->chip_data[chip]);
// for (uint8_t cell = 0; cell < num_cells; cell++) {
// /* Set OCV to the previous/existing OCV */
// bmsdata->chip_data[chip].open_cell_voltage[cell] =
// prev_chipdata[chip].open_cell_voltage[cell];
// }
// }
// If we are within the current threshold for open voltage measurments (1.5 mA)
if (bmsdata->pack_current < OCV_CURR_THRESH &&
bmsdata->pack_current > -1 * OCV_CURR_THRESH) {
// Timer expired or not active
if (is_timer_expired(&ocvTimer) ||
!is_timer_active(&ocvTimer)) {
for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// Number of cells in the chip
uint8_t num_cells = get_num_cells(
&bmsdata->chip_data[chip]);
for (uint8_t cell = 0; cell < num_cells;
cell++) {
// This is the actual OCV value in the cell
uint16_t ocv_value =
bmsdata->chip_data[chip]
.cell_voltages[cell];

// Set current OCV value
bmsdata->chip_data[chip]
.open_cell_voltage[cell] =
ocv_value;
}
}
} else {
start_timer(&ocvTimer, 1000);
}
}
}

//TODO: Make it actually calc OCVs. Revise algorithm and stuff.
//TODO: Change for new cells (probs not needed).
//void calc_open_cell_voltage(acc_data_t *bmsdata)
//{
//TODO: MAKE NOT SHIT :)

// static chipdata_t prev_chipdata[12];

// /* if there is no previous data point, set inital open cell voltage to current reading */
// if (is_first_reading_) {
// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// uint8_t num_cells =
// get_num_cells(&bmsdata->chip_data[chip]);
// for (uint8_t cell = 0; cell < num_cells; cell++) {
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// bmsdata->chip_data[chip]
// .cell_voltages[cell];
// prev_chipdata[chip].open_cell_voltage[cell] =
// bmsdata->chip_data[chip]
// .cell_voltages[cell];
// }
// }
// return;
// }
// /* If we are within the current threshold for open voltage measurments */
// else if (bmsdata->pack_current < (OCV_CURR_THRESH * 10) &&
// bmsdata->pack_current > (-OCV_CURR_THRESH * 10)) {
// if (is_timer_expired(&ocvTimer) ||
// !is_timer_active(&ocvTimer)) {
// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// uint8_t num_cells = get_num_cells(
// &bmsdata->chip_data[chip]);
// for (uint8_t cell = 0; cell < num_cells;
// cell++) {
// /* Sets open cell voltage to a moving average of OCV_AVG values */
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// ((bmsdata->chip_data[chip].cell_voltages[cell];
// ((prev_chipdata[chip].open_cell_voltage
// [cell]) *
// (OCV_AVG - 1))) /
// OCV_AVG;
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// bmsdata->chips[chip]
// .fcell.fc_codes[cell];

// if (bmsdata->chip_data[chip]
// .open_cell_voltage[cell] >
// MAX_VOLT * 10000) {
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// prev_chipdata[chip]
// .open_cell_voltage
// [cell];
// } else if (bmsdata->chip_data[chip]
// .open_cell_voltage
// [cell] <
// MIN_VOLT * 10000) {
// bmsdata->chip_data[chip]
// .open_cell_voltage[cell] =
// prev_chipdata[chip]
// .open_cell_voltage
// [cell];
// }
// }
// }
// return;
// }
// } else {
// start_timer(&ocvTimer, 1000);
// }
// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
// uint8_t num_cells = get_num_cells(&bmsdata->chip_data[chip]);
// for (uint8_t cell = 0; cell < num_cells; cell++) {
// /* Set OCV to the previous/existing OCV */
// bmsdata->chip_data[chip].open_cell_voltage[cell] =
// prev_chipdata[chip].open_cell_voltage[cell];
// }
// }
//}

//TODO: Change for new fans and cell temps
// uint8_t analyzer_calc_fan_pwm(acc_data_t *bmsdata)
// {
Expand Down

0 comments on commit 881f0d9

Please sign in to comment.