charge_control: delay overload trigger by a configurable time

This commit is contained in:
Thomas Kolb 2023-06-18 16:18:13 +02:00
parent 2cedcb712a
commit bd08440584
5 changed files with 51 additions and 4 deletions

View file

@ -27,7 +27,8 @@ static const char *DISCHARGE_STATE_TEXT[DISCHARGE_NUM_STATES] = {
"WAIT_CHARGEPUMP", "WAIT_CHARGEPUMP",
"OK", "OK",
"VOLTAGE_LOW", "VOLTAGE_LOW",
"OVERCURRENT" "OVERCURRENT",
"OVERCURRENT_DELAY"
}; };
static enum ChargeState charge_state; static enum ChargeState charge_state;
@ -55,6 +56,7 @@ static fxp_t u_bat_load_on;
static fxp_t u_bat_load_off; static fxp_t u_bat_load_off;
static fxp_t load_current_limit; static fxp_t load_current_limit;
static fxp_t load_current_limit_delay;
static fxp_t internal_temperature_limit; static fxp_t internal_temperature_limit;
static fxp_t internal_temperature_recovery; static fxp_t internal_temperature_recovery;
@ -294,7 +296,13 @@ static void load_fsm_update(uint64_t uptime_ms, struct MeasurementResult *meas)
if((meas->i_load > load_current_limit) if((meas->i_load > load_current_limit)
&& (discharge_time_in_state > FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME)) { && (discharge_time_in_state > FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME)) {
if(load_current_limit_delay == 0) {
// switch off immediately
power_switch_load_off();
discharge_state = DISCHARGE_OVERCURRENT; discharge_state = DISCHARGE_OVERCURRENT;
} else {
discharge_state = DISCHARGE_OVERCURRENT_DELAY;
}
} }
if(meas->avg_u_bat < u_bat_load_off) { if(meas->avg_u_bat < u_bat_load_off) {
@ -311,17 +319,31 @@ static void load_fsm_update(uint64_t uptime_ms, struct MeasurementResult *meas)
// Can only switch on again after a specific amount of time has passed // Can only switch on again after a specific amount of time has passed
if((meas->avg_u_bat > u_bat_load_on) if((meas->avg_u_bat > u_bat_load_on)
&& (discharge_time_in_state > FLASH_CONFIG_LOAD_ON_DELAY)) { && (discharge_time_in_state > FLASH_CONFIG_LOAD_ON_DELAY)) {
discharge_state = DISCHARGE_WAIT_CHARGEPUMP;
}
break;
case DISCHARGE_OVERCURRENT_DELAY:
if(meas->i_load < load_current_limit) {
// current recovered
discharge_state = DISCHARGE_OK; discharge_state = DISCHARGE_OK;
} else if(discharge_time_in_state >= FLASH_CONFIG_OVERLOAD_DELAY_TIME) {
// switch off immediately
power_switch_load_off();
discharge_state = DISCHARGE_OVERCURRENT;
} }
break; break;
case DISCHARGE_OVERCURRENT: case DISCHARGE_OVERCURRENT:
// Battery voltage is too low, so keep the load switched off // Current limit reached
if(discharge_state_entered) { if(discharge_state_entered) {
power_switch_load_off(); power_switch_load_off();
} }
// no way out except reset // Overload recovery
if(discharge_time_in_state >= FLASH_CONFIG_OVERLOAD_RETRY_TIME) {
discharge_state = DISCHARGE_WAIT_CHARGEPUMP;
}
break; break;
default: default:

View file

@ -27,6 +27,7 @@ enum DischargeState
DISCHARGE_OK, DISCHARGE_OK,
DISCHARGE_VOLTAGE_LOW, DISCHARGE_VOLTAGE_LOW,
DISCHARGE_OVERCURRENT, DISCHARGE_OVERCURRENT,
DISCHARGE_OVERCURRENT_DELAY,
DISCHARGE_NUM_STATES DISCHARGE_NUM_STATES
}; };

View file

@ -86,6 +86,10 @@ extern uint8_t __conf_start;
* time after load power-on. */ * time after load power-on. */
#define FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0144)) #define FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0144))
/* Inrush tolerance time (in ms). Overload protection is not enforced for this
* time after load power-on. */
#define FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0144))
/* 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). */
#define FLASH_CONFIG_MIN_CHARGE_PUMP_EXCESS_VOLTAGE (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0148)) #define FLASH_CONFIG_MIN_CHARGE_PUMP_EXCESS_VOLTAGE (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0148))
@ -93,6 +97,14 @@ extern uint8_t __conf_start;
/* The minimum time the load must be off before it can be switched on again (in ms). */ /* The minimum time the load must be off before it can be switched on again (in ms). */
#define FLASH_CONFIG_LOAD_ON_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x014c)) #define FLASH_CONFIG_LOAD_ON_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x014c))
/* Overload delay time (in ms). If load current is too high for this duration,
* load is switched permanently off. */
#define FLASH_CONFIG_OVERLOAD_DELAY_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0170))
/* Overload retry time (in ms). Load is switched on again after this time if
* overload condition has triggered. */
#define FLASH_CONFIG_OVERLOAD_RETRY_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0174))
/* Measurement Averaging: /* Measurement Averaging:
* Alpha is specified in units of 1/1000. 1000 means that only the latest * Alpha is specified in units of 1/1000. 1000 means that only the latest
@ -123,6 +135,8 @@ extern uint8_t __conf_start;
/* Deep sleep duration (in seconds). */ /* Deep sleep duration (in seconds). */
#define FLASH_CONFIG_DEEPSLEEP_DURATION (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x016c)) #define FLASH_CONFIG_DEEPSLEEP_DURATION (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x016c))
/* FIXME: next free memory location: 0x178. Update when adding a value! */
/* Functions */ /* Functions */

View file

@ -79,6 +79,14 @@ config:
# time after load power-on. # time after load power-on.
LOAD_CURRENT_INRUSH_TIME: 10 LOAD_CURRENT_INRUSH_TIME: 10
# Overload delay time (in ms). If load current is too high for this duration,
# load is switched permanently off.
FLASH_CONFIG_OVERLOAD_DELAY_TIME: 10
# Overload retry time (in ms). Load is switched on again after this time if
# overload condition has triggered.
FLASH_CONFIG_OVERLOAD_RETRY_TIME: 1800000
# 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).
MIN_CHARGE_PUMP_EXCESS_VOLTAGE: 10000 MIN_CHARGE_PUMP_EXCESS_VOLTAGE: 10000

View file

@ -45,6 +45,8 @@ CONFIG_KEY_TO_OFFSET = {
"AVG_ALPHA_TEMP": 0x0164, "AVG_ALPHA_TEMP": 0x0164,
"DEEPSLEEP_DELAY": 0x0168, "DEEPSLEEP_DELAY": 0x0168,
"DEEPSLEEP_DURATION": 0x016c, "DEEPSLEEP_DURATION": 0x016c,
"FLASH_CONFIG_OVERLOAD_DELAY_TIME": 0x0170,
"FLASH_CONFIG_OVERLOAD_RETRY_TIME": 0x0174
} }