fix: clear OV/UV flags after trigger

This commit is contained in:
Kilian Bracher 2025-03-23 15:51:25 +01:00
parent 273ad047bd
commit 3ffad99284
4 changed files with 10 additions and 1 deletions

View File

@ -42,6 +42,7 @@ HAL_StatusTypeDef amsCheckUnderOverVoltage(Cell_Module (*module)[N_BMS]);
HAL_StatusTypeDef amsClearFlag(); HAL_StatusTypeDef amsClearFlag();
HAL_StatusTypeDef amsClearAux(); HAL_StatusTypeDef amsClearAux();
HAL_StatusTypeDef amsClearOVUV();
HAL_StatusTypeDef amsReadCellVoltages(Cell_Module (*module)[N_BMS]); HAL_StatusTypeDef amsReadCellVoltages(Cell_Module (*module)[N_BMS]);

View File

@ -294,6 +294,11 @@ HAL_StatusTypeDef amsClearFlag() {
HAL_StatusTypeDef amsClearAux() { return writeCMD(CLRAUX, CMD_EMPTY_BUFFER, 0); } HAL_StatusTypeDef amsClearAux() { return writeCMD(CLRAUX, CMD_EMPTY_BUFFER, 0); }
HAL_StatusTypeDef amsClearOVUV() {
uint8_t buffer[CMD_BUFFER_SIZE(6)] = {[0 ... CMD_BUFFER_SIZE(6) - 1] = 0xFF};
return writeCMD(CLOVUV, buffer, 6);
}
HAL_StatusTypeDef amsReadCellVoltages(Cell_Module (*module)[N_BMS]) { HAL_StatusTypeDef amsReadCellVoltages(Cell_Module (*module)[N_BMS]) {
uint8_t rxbuffer[CMD_BUFFER_SIZE(CV_GROUP_A_SIZE)] = {}; uint8_t rxbuffer[CMD_BUFFER_SIZE(CV_GROUP_A_SIZE)] = {};

View File

@ -99,10 +99,12 @@ ADBMS_DetailedStatus AMS_Idle_Loop() {
} }
if ((match = any(module.overVoltage))) { if ((match = any(module.overVoltage))) {
amsClearOVUV();
return (ADBMS_DetailedStatus){ADBMS_OVERVOLT, match - 1}; return (ADBMS_DetailedStatus){ADBMS_OVERVOLT, match - 1};
} }
if ((match = any(module.underVoltage))) { if ((match = any(module.underVoltage))) {
amsClearOVUV();
return (ADBMS_DetailedStatus){ADBMS_UNDERVOLT, match - 1}; return (ADBMS_DetailedStatus){ADBMS_UNDERVOLT, match - 1};
} }

View File

@ -117,7 +117,7 @@ int main(void)
int error_count = 0; int error_count = 0;
while (1) while (1)
{ {
if (error_count > 10) { if (error_count > 25) {
debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS..."); debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS...");
status = AMS_Init(&hspi1); status = AMS_Init(&hspi1);
if (status.status != ADBMS_NO_ERROR) { if (status.status != ADBMS_NO_ERROR) {
@ -125,6 +125,7 @@ int main(void)
HAL_Delay(2000); HAL_Delay(2000);
continue; continue;
} }
error_count = 0;
} }
status = AMS_Idle_Loop(); status = AMS_Idle_Loop();
if (status.status != ADBMS_NO_ERROR) { if (status.status != ADBMS_NO_ERROR) {