Go into discharge for 5s

The discharge circuit is only active while the SDC is open. If the SDC
never opens (or opens for a very short time only), but we go to
TS_INACTIVE, then the discharge circuit will never be active. Going into
a discharge state for 5s allows the PDU to open the SDC for long enough
to reach <60V.
This commit is contained in:
Jasper Blanckenburg 2023-04-15 16:58:40 +02:00
parent 0b2010797e
commit 66d9baba7a
2 changed files with 13 additions and 3 deletions

View File

@ -9,6 +9,8 @@
#define MIN_VEHICLE_SIDE_VOLTAGE 150000 // mV
// Time to wait after reaching 95% of battery voltage before exiting precharge
#define PRECHARGE_95_DURATION 500 // 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
#define NO_ERROR_TIME 1000 // ms
// Time to wait for charger voltage before going to TS_ERROR

View File

@ -10,6 +10,7 @@ TSStateHandle ts_state;
static uint32_t precharge_95_reached_timestamp = 0;
static uint32_t charging_check_timestamp = 0;
static uint32_t discharge_begin_timestamp = 0;
void ts_sm_init() {
ts_state.current_state = TS_INACTIVE;
@ -63,6 +64,7 @@ TSState ts_sm_update_inactive() {
TSState ts_sm_update_active() {
if (ts_state.target_state == TS_INACTIVE) {
discharge_begin_timestamp = HAL_GetTick();
return TS_DISCHARGE;
}
@ -71,6 +73,7 @@ TSState ts_sm_update_active() {
TSState ts_sm_update_precharge() {
if (ts_state.target_state == TS_INACTIVE) {
discharge_begin_timestamp = HAL_GetTick();
return TS_DISCHARGE;
}
if (shunt_data.voltage2 > MIN_VEHICLE_SIDE_VOLTAGE &&
@ -88,8 +91,11 @@ TSState ts_sm_update_precharge() {
}
TSState ts_sm_update_discharge() {
// TODO: Actually wait for discharge
return TS_INACTIVE;
if (HAL_GetTick() - discharge_begin_timestamp >= DISCHARGE_DURATION) {
return TS_INACTIVE;
} else {
return TS_DISCHARGE;
}
}
TSState ts_sm_update_error() {
@ -109,6 +115,7 @@ TSState ts_sm_update_error() {
TSState ts_sm_update_charging_check() {
if (ts_state.target_state == TS_INACTIVE) {
discharge_begin_timestamp = HAL_GetTick();
return TS_DISCHARGE;
}
@ -124,6 +131,7 @@ TSState ts_sm_update_charging_check() {
TSState ts_sm_update_charging() {
if (ts_state.target_state == TS_INACTIVE) {
discharge_begin_timestamp = HAL_GetTick();
return TS_DISCHARGE;
}
if (shunt_data.current < 0) {
@ -136,6 +144,7 @@ TSState ts_sm_update_charging() {
void ts_sm_set_relay_positions(TSState state) {
switch (state) {
case TS_INACTIVE:
case TS_DISCHARGE:
case TS_ERROR:
ts_sm_set_relay_position(RELAY_NEG, 0);
ts_sm_set_relay_position(RELAY_POS, 0);
@ -143,7 +152,6 @@ void ts_sm_set_relay_positions(TSState state) {
break;
case TS_ACTIVE:
case TS_CHARGING:
case TS_DISCHARGE:
ts_sm_set_relay_position(RELAY_NEG, 1);
ts_sm_set_relay_position(RELAY_POS, 1);
ts_sm_set_relay_position(RELAY_PRECHARGE, 1);