Merge pull request #1439 from dalathegreat/bugfix/precharge-osc

Precharge: Avoid oscillation in precharge pin incase it fails/timeouts
This commit is contained in:
Daniel Öster 2025-08-30 22:10:45 +03:00 committed by GitHub
commit 01f03d6726
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View file

@ -64,6 +64,14 @@ void handle_precharge_control(unsigned long currentMillis) {
auto hia4v1_pin = esp32hal->HIA4V1_PIN(); auto hia4v1_pin = esp32hal->HIA4V1_PIN();
auto inverter_disconnect_contactor_pin = esp32hal->INVERTER_DISCONNECT_CONTACTOR_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 target_voltage = datalayer.battery.status.voltage_dV;
int32_t external_voltage = datalayer_extended.meb.BMS_voltage_intermediate_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); pinMode(hia4v1_pin, OUTPUT);
digitalWrite(hia4v1_pin, LOW); digitalWrite(hia4v1_pin, LOW);
digitalWrite(inverter_disconnect_contactor_pin, ON); 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 #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 #endif
set_event(EVENT_AUTOMATIC_PRECHARGE_FAILURE, 0); set_event(EVENT_AUTOMATIC_PRECHARGE_FAILURE, 0);
// Force stop any further precharge attempts
datalayer.system.settings.start_precharging = false;
// Add event // Add event
} else if (datalayer.system.status.battery_allows_contactor_closing) { } else if (datalayer.system.status.battery_allows_contactor_closing) {

View file

@ -263,7 +263,7 @@ String get_event_message_string(EVENTS_ENUM_TYPE event) {
case EVENT_PRECHARGE_FAILURE: case EVENT_PRECHARGE_FAILURE:
return "Battery failed to precharge. Check that capacitor is seated on high voltage output."; return "Battery failed to precharge. Check that capacitor is seated on high voltage output.";
case EVENT_AUTOMATIC_PRECHARGE_FAILURE: case EVENT_AUTOMATIC_PRECHARGE_FAILURE:
return "Automatic precharge failed to reach target voltae."; return "Automatic precharge FAILURE. Failed to reach target voltage or BMS timeout. Reboot emulator to retry!";
case EVENT_INTERNAL_OPEN_FAULT: case EVENT_INTERNAL_OPEN_FAULT:
return "High voltage cable removed while battery running. Opening contactors!"; return "High voltage cable removed while battery running. Opening contactors!";
case EVENT_INVERTER_OPEN_CONTACTOR: case EVENT_INVERTER_OPEN_CONTACTOR:

View file

@ -27,7 +27,8 @@ enum PrechargeState {
AUTO_PRECHARGE_START, AUTO_PRECHARGE_START,
AUTO_PRECHARGE_PRECHARGING, AUTO_PRECHARGE_PRECHARGING,
AUTO_PRECHARGE_OFF, AUTO_PRECHARGE_OFF,
AUTO_PRECHARGE_COMPLETED AUTO_PRECHARGE_COMPLETED,
AUTO_PRECHARGE_FAILURE
}; };
#define DISCHARGING 1 #define DISCHARGING 1