overload: exponential backoff for retry

Whenever overload is detected, the time that must pass before the load is
turned on again is doubled. If the load was on for 5 minutes, the retry time is
reset to the configured value.
This commit is contained in:
Thomas Kolb 2023-06-18 16:43:41 +02:00
parent e8dff1f017
commit 19735ee550
2 changed files with 20 additions and 3 deletions

View file

@ -67,6 +67,8 @@ static fxp_t external_temperature_recovery;
static fxp_t sleep_solar_current; static fxp_t sleep_solar_current;
static fxp_t sleep_solar_excess_voltage; static fxp_t sleep_solar_excess_voltage;
static uint32_t overload_retry_time;
static enum ChargeState control_solar_charging( static enum ChargeState control_solar_charging(
fxp_t corridor_high, fxp_t corridor_high,
@ -305,6 +307,13 @@ static void load_fsm_update(uint64_t uptime_ms, struct MeasurementResult *meas)
} }
} }
if((overload_retry_time != FLASH_CONFIG_OVERLOAD_RETRY_TIME) &&
(discharge_time_in_state > 300000)) {
// overload did not trigger for 5 minutes, so we assume its stable and
// reset the retry time delay.
overload_retry_time = FLASH_CONFIG_OVERLOAD_RETRY_TIME;
}
if(meas->avg_u_bat < u_bat_load_off) { if(meas->avg_u_bat < u_bat_load_off) {
discharge_state = DISCHARGE_VOLTAGE_LOW; discharge_state = DISCHARGE_VOLTAGE_LOW;
} }
@ -341,7 +350,12 @@ static void load_fsm_update(uint64_t uptime_ms, struct MeasurementResult *meas)
} }
// Overload recovery // Overload recovery
if(discharge_time_in_state >= FLASH_CONFIG_OVERLOAD_RETRY_TIME) { if(discharge_time_in_state >= overload_retry_time) {
// double the overload retry time for the next turn if it is less than 7 days
if(overload_retry_time < (7*24*3600*1000)) {
overload_retry_time *= 2;
}
discharge_state = DISCHARGE_WAIT_CHARGEPUMP; discharge_state = DISCHARGE_WAIT_CHARGEPUMP;
} }
break; break;
@ -389,6 +403,8 @@ void charge_control_init(void)
sleep_solar_current = fxp_div(FXP_FROM_INT(FLASH_CONFIG_SLEEP_SOLAR_CURRENT), FXP_FROM_INT(1000)); sleep_solar_current = fxp_div(FXP_FROM_INT(FLASH_CONFIG_SLEEP_SOLAR_CURRENT), FXP_FROM_INT(1000));
sleep_solar_excess_voltage = fxp_div(FXP_FROM_INT(FLASH_CONFIG_SLEEP_SOLAR_EXCESS_VOLTAGE), FXP_FROM_INT(1000)); sleep_solar_excess_voltage = fxp_div(FXP_FROM_INT(FLASH_CONFIG_SLEEP_SOLAR_EXCESS_VOLTAGE), FXP_FROM_INT(1000));
overload_retry_time = FLASH_CONFIG_OVERLOAD_RETRY_TIME;
} }

View file

@ -84,8 +84,9 @@ config:
FLASH_CONFIG_OVERLOAD_DELAY_TIME: 10 FLASH_CONFIG_OVERLOAD_DELAY_TIME: 10
# Overload retry time (in ms). Load is switched on again after this time if # Overload retry time (in ms). Load is switched on again after this time if
# overload condition has triggered. # overload condition has triggered. If overload immediately triggers again,
FLASH_CONFIG_OVERLOAD_RETRY_TIME: 1800000 # this time is doubled.
FLASH_CONFIG_OVERLOAD_RETRY_TIME: 10000
# Minimum voltage that the charge pump must produce above U_bat before any # Minimum voltage that the charge pump must produce above U_bat before any
# power FET is switched on (in mV). # power FET is switched on (in mV).