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

Ocv fix #167

Merged
merged 5 commits into from
Feb 2, 2025
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 @@ -44,7 +44,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