From d715d169fe50dae9ca996d431168626d22cf9236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Tue, 19 Aug 2025 21:27:29 +0300 Subject: [PATCH] Avoid oscillation in precharge incase it fails/timeoutus --- .../precharge_control/precharge_control.cpp | 14 ++++++++++++-- Software/src/devboard/utils/types.h | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Software/src/communication/precharge_control/precharge_control.cpp b/Software/src/communication/precharge_control/precharge_control.cpp index efdf3ff9..3557c95e 100644 --- a/Software/src/communication/precharge_control/precharge_control.cpp +++ b/Software/src/communication/precharge_control/precharge_control.cpp @@ -64,6 +64,14 @@ void handle_precharge_control(unsigned long currentMillis) { auto hia4v1_pin = esp32hal->HIA4V1_PIN(); auto inverter_disconnect_contactor_pin = esp32hal->INVERTER_DISCONNECT_CONTACTOR_PIN(); + // If we're in FAILURE state, completely disable any further precharge attempts + if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_FAILURE) { + pinMode(hia4v1_pin, OUTPUT); + digitalWrite(hia4v1_pin, LOW); + digitalWrite(inverter_disconnect_contactor_pin, ON); + return; // Exit immediately - no further processing allowed. Reboot required to recover + } + int32_t target_voltage = datalayer.battery.status.voltage_dV; int32_t external_voltage = datalayer_extended.meb.BMS_voltage_intermediate_dV; @@ -128,11 +136,13 @@ void handle_precharge_control(unsigned long currentMillis) { pinMode(hia4v1_pin, OUTPUT); digitalWrite(hia4v1_pin, LOW); digitalWrite(inverter_disconnect_contactor_pin, ON); - datalayer.system.status.precharge_status = AUTO_PRECHARGE_OFF; + datalayer.system.status.precharge_status = AUTO_PRECHARGE_FAILURE; #ifdef DEBUG_LOG - logging.printf("Precharge: Disabled (timeout reached / BMS fault) -> AUTO_PRECHARGE_OFF\n"); + logging.printf("Precharge: CRITICAL FAILURE (timeout/BMS fault) -> REQUIRES REBOOT\n"); #endif set_event(EVENT_AUTOMATIC_PRECHARGE_FAILURE, 0); + // Force stop any further precharge attempts + datalayer.system.settings.start_precharging = false; // Add event } else if (datalayer.system.status.battery_allows_contactor_closing) { diff --git a/Software/src/devboard/utils/types.h b/Software/src/devboard/utils/types.h index d1e15340..577241e8 100644 --- a/Software/src/devboard/utils/types.h +++ b/Software/src/devboard/utils/types.h @@ -28,7 +28,8 @@ enum PrechargeState { AUTO_PRECHARGE_START, AUTO_PRECHARGE_PRECHARGING, AUTO_PRECHARGE_OFF, - AUTO_PRECHARGE_COMPLETED + AUTO_PRECHARGE_COMPLETED, + AUTO_PRECHARGE_FAILURE }; #define DISCHARGING 1