diff --git a/Software/src/battery/MEB-BATTERY.cpp b/Software/src/battery/MEB-BATTERY.cpp index 20bbb96e..87a309d2 100644 --- a/Software/src/battery/MEB-BATTERY.cpp +++ b/Software/src/battery/MEB-BATTERY.cpp @@ -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] = diff --git a/Software/src/communication/precharge_control/precharge_control.cpp b/Software/src/communication/precharge_control/precharge_control.cpp index 9a2fdf47..f2942afc 100644 --- a/Software/src/communication/precharge_control/precharge_control.cpp +++ b/Software/src/communication/precharge_control/precharge_control.cpp @@ -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); diff --git a/Software/src/devboard/utils/types.h b/Software/src/devboard/utils/types.h index 0d1195a2..55c4a4a5 100644 --- a/Software/src/devboard/utils/types.h +++ b/Software/src/devboard/utils/types.h @@ -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 };