Only set precharge bit when almost done precharging.

To prevent battery errors due to precharge taking too long, we now only set the precharge bit when voltages internal and external voltages are already close.
This commit is contained in:
mvgalen 2025-04-15 21:07:57 +02:00
parent 4b8bf6afec
commit 3bd5287d02
3 changed files with 12 additions and 9 deletions

View file

@ -1725,8 +1725,8 @@ void transmit_can_battery() {
logging.printf("MEB: Requesting HV\n");
}
if ((MEB_503.data.u8[1] & 0x80) !=
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00)) {
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING) {
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL ? 0x80 : 0x00)) {
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL) {
logging.printf("MEB: Precharge bit set to active\n");
} else {
logging.printf("MEB: Precharge bit set to inactive\n");
@ -1734,7 +1734,7 @@ void transmit_can_battery() {
}
#endif
MEB_503.data.u8[1] =
0x30 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00);
0x30 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL ? 0x80 : 0x00);
MEB_503.data.u8[3] = BMS_TARGET_AC_CHARGING;
MEB_503.data.u8[5] = 0x82; // Bordnetz Active
MEB_503.data.u8[6] = 0xE0; // Request emergency shutdown HV system == 0, false
@ -1751,8 +1751,8 @@ void transmit_can_battery() {
logging.printf("MEB: Requesting HV_OFF\n");
}
if ((MEB_503.data.u8[1] & 0x80) !=
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00)) {
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING) {
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL ? 0x80 : 0x00)) {
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL) {
logging.printf("MEB: Precharge bit set to active\n");
} else {
logging.printf("MEB: Precharge bit set to inactive\n");
@ -1760,7 +1760,7 @@ void transmit_can_battery() {
}
#endif
MEB_503.data.u8[1] =
0x10 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00);
0x10 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL ? 0x80 : 0x00);
MEB_503.data.u8[3] = BMS_TARGET_HV_OFF;
MEB_503.data.u8[5] = 0x80; // Bordnetz Inactive
MEB_503.data.u8[6] =

View file

@ -77,15 +77,17 @@ void handle_precharge_control() {
break;
case AUTO_PRECHARGE_PRECHARGING:
case AUTO_PRECHARGE_PRECHARGING_FINAL:
// Check if external voltage measurement changed, for instance with the MEB batteries, the external voltage is only updated every 100ms.
if (prev_external_voltage != external_voltage && external_voltage != 0) {
prev_external_voltage = external_voltage;
if (labs(target_voltage - external_voltage) > 150) {
/*if (labs(target_voltage - external_voltage) > 150) {
delta_freq = 2000;
} else if (labs(target_voltage - external_voltage) > 80) {
} else*/ if (labs(target_voltage - external_voltage) > 80) {
delta_freq = labs(target_voltage - external_voltage) * 6;
} else {
datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING_FINAL;
delta_freq = labs(target_voltage - external_voltage) * 3;
}
if (target_voltage > external_voltage) {
@ -98,7 +100,7 @@ void handle_precharge_control() {
if (freq < Precharge_min_PWM_Freq)
freq = Precharge_min_PWM_Freq;
#ifdef DEBUG_LOG
logging.printf("Precharge: Target: %d V Extern: %d V Frequency: %u\n", target_voltage / 10,
logging.printf("Precharge: Target: %d V Extern: %d V New frequency: %u Hz\n", target_voltage / 10,
external_voltage / 10, freq);
#endif
ledcWriteTone(PRECHARGE_PIN, freq);

View file

@ -12,6 +12,7 @@ enum PrechargeState {
AUTO_PRECHARGE_IDLE,
AUTO_PRECHARGE_START,
AUTO_PRECHARGE_PRECHARGING,
AUTO_PRECHARGE_PRECHARGING_FINAL,
AUTO_PRECHARGE_OFF,
AUTO_PRECHARGE_COMPLETED
};