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
Changes from 4 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
240 changes: 161 additions & 79 deletions Core/Src/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,89 +546,171 @@ 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];
// }
// }
uint16_t ocv_value = 0;
uint16_t avg_ocv = 0;

// If there is no previous data point, set inital open cell voltage to current reading
EhlOps marked this conversation as resolved.
Show resolved Hide resolved
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++) {
// Actual OCV value in the cell
ocv_value = bmsdata->chip_data[chip]
.cell_voltages[cell];

// Set OCV values
bmsdata->chip_data[chip]
.open_cell_voltage[cell] = ocv_value;
}
}
is_first_reading_ = false;
return;
}

// If we are within the current threshold for open voltage measurments (1.5 mA)
else if (bmsdata->pack_current < (OCV_CURR_THRESH / 1000) &&
EhlOps marked this conversation as resolved.
Show resolved Hide resolved
bmsdata->pack_current > (-OCV_CURR_THRESH / 1000)) {
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
ocv_value =
bmsdata->chip_data[chip]
.cell_voltages[cell];

if (ocv_value < MAX_VOLT ||
EhlOps marked this conversation as resolved.
Show resolved Hide resolved
ocv_value > MIN_VOLT) {
// Set current OCV value
bmsdata->chip_data[chip]
.open_cell_voltage[cell] =
ocv_value;

// Find max and min OCV values
if (ocv_value >
bmsdata->max_ocv.val) {
bmsdata->max_ocv.val =
ocv_value;
bmsdata->max_ocv
.cellNum = cell;
bmsdata->max_ocv
.chipIndex =
chip;
} else if (ocv_value <
bmsdata->min_ocv.val) {
bmsdata->min_ocv.val =
ocv_value;
bmsdata->min_ocv
.cellNum = cell;
bmsdata->min_ocv
.chipIndex =
chip;
}

avg_ocv +=
ocv_value / NUM_CELLS;
}
}
}
bmsdata->delt_ocv = avg_ocv - bmsdata->avg_ocv;
EhlOps marked this conversation as resolved.
Show resolved Hide resolved
bmsdata->avg_ocv = avg_ocv;
bmsdata->pack_ocv = avg_ocv * 10;
} 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