mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
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:
parent
4b8bf6afec
commit
3bd5287d02
3 changed files with 12 additions and 9 deletions
|
@ -1725,8 +1725,8 @@ void transmit_can_battery() {
|
||||||
logging.printf("MEB: Requesting HV\n");
|
logging.printf("MEB: Requesting HV\n");
|
||||||
}
|
}
|
||||||
if ((MEB_503.data.u8[1] & 0x80) !=
|
if ((MEB_503.data.u8[1] & 0x80) !=
|
||||||
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00)) {
|
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL ? 0x80 : 0x00)) {
|
||||||
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING) {
|
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL) {
|
||||||
logging.printf("MEB: Precharge bit set to active\n");
|
logging.printf("MEB: Precharge bit set to active\n");
|
||||||
} else {
|
} else {
|
||||||
logging.printf("MEB: Precharge bit set to inactive\n");
|
logging.printf("MEB: Precharge bit set to inactive\n");
|
||||||
|
@ -1734,7 +1734,7 @@ void transmit_can_battery() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
MEB_503.data.u8[1] =
|
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[3] = BMS_TARGET_AC_CHARGING;
|
||||||
MEB_503.data.u8[5] = 0x82; // Bordnetz Active
|
MEB_503.data.u8[5] = 0x82; // Bordnetz Active
|
||||||
MEB_503.data.u8[6] = 0xE0; // Request emergency shutdown HV system == 0, false
|
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");
|
logging.printf("MEB: Requesting HV_OFF\n");
|
||||||
}
|
}
|
||||||
if ((MEB_503.data.u8[1] & 0x80) !=
|
if ((MEB_503.data.u8[1] & 0x80) !=
|
||||||
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00)) {
|
(datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL ? 0x80 : 0x00)) {
|
||||||
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING) {
|
if (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING_FINAL) {
|
||||||
logging.printf("MEB: Precharge bit set to active\n");
|
logging.printf("MEB: Precharge bit set to active\n");
|
||||||
} else {
|
} else {
|
||||||
logging.printf("MEB: Precharge bit set to inactive\n");
|
logging.printf("MEB: Precharge bit set to inactive\n");
|
||||||
|
@ -1760,7 +1760,7 @@ void transmit_can_battery() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
MEB_503.data.u8[1] =
|
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[3] = BMS_TARGET_HV_OFF;
|
||||||
MEB_503.data.u8[5] = 0x80; // Bordnetz Inactive
|
MEB_503.data.u8[5] = 0x80; // Bordnetz Inactive
|
||||||
MEB_503.data.u8[6] =
|
MEB_503.data.u8[6] =
|
||||||
|
|
|
@ -77,15 +77,17 @@ void handle_precharge_control() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUTO_PRECHARGE_PRECHARGING:
|
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.
|
// 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) {
|
if (prev_external_voltage != external_voltage && external_voltage != 0) {
|
||||||
prev_external_voltage = external_voltage;
|
prev_external_voltage = external_voltage;
|
||||||
|
|
||||||
if (labs(target_voltage - external_voltage) > 150) {
|
/*if (labs(target_voltage - external_voltage) > 150) {
|
||||||
delta_freq = 2000;
|
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;
|
delta_freq = labs(target_voltage - external_voltage) * 6;
|
||||||
} else {
|
} else {
|
||||||
|
datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING_FINAL;
|
||||||
delta_freq = labs(target_voltage - external_voltage) * 3;
|
delta_freq = labs(target_voltage - external_voltage) * 3;
|
||||||
}
|
}
|
||||||
if (target_voltage > external_voltage) {
|
if (target_voltage > external_voltage) {
|
||||||
|
@ -98,7 +100,7 @@ void handle_precharge_control() {
|
||||||
if (freq < Precharge_min_PWM_Freq)
|
if (freq < Precharge_min_PWM_Freq)
|
||||||
freq = Precharge_min_PWM_Freq;
|
freq = Precharge_min_PWM_Freq;
|
||||||
#ifdef DEBUG_LOG
|
#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);
|
external_voltage / 10, freq);
|
||||||
#endif
|
#endif
|
||||||
ledcWriteTone(PRECHARGE_PIN, freq);
|
ledcWriteTone(PRECHARGE_PIN, freq);
|
||||||
|
|
|
@ -12,6 +12,7 @@ enum PrechargeState {
|
||||||
AUTO_PRECHARGE_IDLE,
|
AUTO_PRECHARGE_IDLE,
|
||||||
AUTO_PRECHARGE_START,
|
AUTO_PRECHARGE_START,
|
||||||
AUTO_PRECHARGE_PRECHARGING,
|
AUTO_PRECHARGE_PRECHARGING,
|
||||||
|
AUTO_PRECHARGE_PRECHARGING_FINAL,
|
||||||
AUTO_PRECHARGE_OFF,
|
AUTO_PRECHARGE_OFF,
|
||||||
AUTO_PRECHARGE_COMPLETED
|
AUTO_PRECHARGE_COMPLETED
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue