Skip to content

Commit

Permalink
Fix recover from overvoltage/undervoltage state in bms_bq769x0.c (#18)
Browse files Browse the repository at this point in the history
BMS with BQ76930 did not recover from state "overvoltage" or "undervoltage"
and needed a reset to enable CHG/DSG MOSFETs again.

The SYS_STAT register should be checked each time as an alert interrupt
is only generated once if the error persists. (ALERT pin stays high)

Also fixing MOSFET "switch on" to use ov_reset and uv_reset.

Fixes #19
  • Loading branch information
xsider authored Aug 12, 2021
1 parent 1f256e6 commit be7f58a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/bq769x0/bms_bq769x0.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void bms_update(BmsConfig *conf, BmsStatus *status)
bms_read_current(conf, status);
bms_read_temperatures(conf, status);
bms_check_cell_temp(conf, status); // bq769x0 doesn't support temperature settings
bms_update_error_flags(conf, status);
bms_apply_balancing(conf, status);
}

Expand Down Expand Up @@ -516,15 +517,15 @@ void bms_handle_errors(BmsConfig *conf, BmsStatus *status)
static uint32_t sec_since_error = 0;

// ToDo: Handle also temperature and chg errors (incl. temp hysteresis)
SYS_STAT_Type sys_stat;
sys_stat.byte = bq769x0_read_byte(BQ769X0_SYS_STAT);
error_status = sys_stat.byte;

if (!bq769x0_alert_flag() && error_status == 0) {
return;
}
else {

SYS_STAT_Type sys_stat;
sys_stat.byte = bq769x0_read_byte(BQ769X0_SYS_STAT);

// first check, if only a new CC reading is available
if (sys_stat.CC_READY == 1) {
//printf("Interrupt: CC ready");
Expand All @@ -537,7 +538,6 @@ void bms_handle_errors(BmsConfig *conf, BmsStatus *status)
if (bq769x0_alert_flag() == true) {
sec_since_error = 0;
}
error_status = sys_stat.byte;

unsigned int sec_since_interrupt = uptime() - bq769x0_alert_timestamp();

Expand Down Expand Up @@ -571,7 +571,7 @@ void bms_handle_errors(BmsConfig *conf, BmsStatus *status)
}
if (sys_stat.byte & 0b00001000) { // UV error
bms_read_voltages(status);
if (status->cell_voltage_min > conf->cell_uv_limit) {
if (status->cell_voltage_min > conf->cell_uv_reset) {
#if BMS_DEBUG
printf("Attempting to clear UV error");
#endif
Expand All @@ -581,7 +581,7 @@ void bms_handle_errors(BmsConfig *conf, BmsStatus *status)
}
if (sys_stat.byte & 0b00000100) { // OV error
bms_read_voltages(status);
if (status->cell_voltage_max < conf->cell_ov_limit) {
if (status->cell_voltage_max < conf->cell_ov_reset) {
#if BMS_DEBUG
printf("Attempting to clear OV error");
#endif
Expand Down

2 comments on commit be7f58a

@xsider
Copy link
Contributor Author

@xsider xsider commented on be7f58a Aug 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch is working successful on real-world application.

@martinjaeger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Please sign in to comment.