add minimum duration of 1 sec for precharge

This commit is contained in:
Kilian Bracher 2025-05-16 23:10:07 +02:00
parent aa85867083
commit 4be1355c40
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
2 changed files with 9 additions and 1 deletions

View File

@ -11,6 +11,8 @@
// Time to wait after reaching 95% of battery voltage before exiting precharge
// Set this to 1000 in scruti to demonstrate the voltage on the multimeter
#define PRECHARGE_95_DURATION 0 // ms
// Minimum precharge time
#define PRECHARGE_MIN_DURATION 1000 // ms
// Time to wait for discharge
#define DISCHARGE_DURATION 5000 // ms
// Time to wait after there is no more error condition before exiting TS_ERROR

View File

@ -12,6 +12,7 @@
TSStateHandle ts_state;
static uint32_t precharge_95_reached_timestamp = 0;
static uint32_t precharge_start_timestamp = 0;
static uint32_t charging_check_timestamp = 0;
static uint32_t discharge_begin_timestamp = 0;
static uint32_t precharge_opened_timestamp = 0;
@ -104,15 +105,20 @@ TSState ts_sm_update_precharge() {
discharge_begin_timestamp = HAL_GetTick();
return TS_DISCHARGE;
}
if (precharge_start_timestamp == 0) {
precharge_start_timestamp = HAL_GetTick();
}
if (shunt_data.voltage_veh > MIN_VEHICLE_SIDE_VOLTAGE &&
shunt_data.voltage_veh > 0.95 * shunt_data.voltage_bat) {
const uint32_t now = HAL_GetTick();
if (precharge_95_reached_timestamp == 0) {
precharge_95_reached_timestamp = now;
} else if ((now - precharge_95_reached_timestamp) >=
PRECHARGE_95_DURATION) {
PRECHARGE_95_DURATION &&
(now - precharge_start_timestamp) >= PRECHARGE_MIN_DURATION) {
precharge_95_reached_timestamp = 0;
precharge_opened_timestamp = 0;
precharge_start_timestamp = 0;
//precharge_opened = 0;
return TS_ACTIVE;
}