1
0
mirror of https://github.com/sjlongland/cluster-powerctl.git synced 2025-09-13 12:03:14 +10:00

Add shutdown delay on "high" threshold.

We should delay our shutdown in case the charger decides to ramp down
itself.  Otherwise we can get the situation where a smart charger starts
high, tripping the high threshold immediately, leading to the controller
and charger oscillating between on and off.
This commit is contained in:
Stuart Longland 2016-11-05 17:01:19 +10:00
parent d91ec8d786
commit d29d15308b
Signed by: stuartl
GPG Key ID: 4DFA191410BDE3B7
2 changed files with 22 additions and 2 deletions

View File

@ -79,6 +79,10 @@ static volatile uint8_t batt_state_counter = 0;
* How long before we can consider switching sources. * How long before we can consider switching sources.
*/ */
static volatile uint8_t src_timeout = 0; static volatile uint8_t src_timeout = 0;
/*!
* How long during a "high voltage" condition before we shut down?
*/
static volatile uint8_t high_timeout = 0;
/*! /*!
* How long before we change LED states? * How long before we change LED states?
@ -299,6 +303,10 @@ int main(void) {
last_batt_state = batt_state; last_batt_state = batt_state;
} }
if (adc_batt < VBATT_HIGH)
/* Battery is below high threshold */
high_timeout = HIGH_TIMEOUT;
/* Battery control */ /* Battery control */
uint8_t state = FET_PORT & FET_SRC_MASK; uint8_t state = FET_PORT & FET_SRC_MASK;
switch (state) { switch (state) {
@ -307,6 +315,7 @@ int main(void) {
#ifdef DEBUG #ifdef DEBUG
uart_tx('I'); uart_tx('I');
#endif #endif
if ((adc_batt < VBATT_CRIT) if ((adc_batt < VBATT_CRIT)
&& (adc_mains > adc_batt)) { && (adc_mains > adc_batt)) {
/* Charger urgently needed. */ /* Charger urgently needed. */
@ -343,7 +352,10 @@ int main(void) {
#ifdef DEBUG #ifdef DEBUG
uart_tx('H'); uart_tx('H');
#endif #endif
select_src(SRC_NONE); if (high_timeout)
high_timeout--;
else
select_src(SRC_NONE);
} else if ((adc_batt < VBATT_CRIT) } else if ((adc_batt < VBATT_CRIT)
&& (adc_mains > adc_solar) && (adc_mains > adc_solar)
&& (adc_mains > adc_batt)) { && (adc_mains > adc_batt)) {
@ -379,7 +391,10 @@ int main(void) {
#ifdef DEBUG #ifdef DEBUG
uart_tx('H'); uart_tx('H');
#endif #endif
select_src(SRC_NONE); if (high_timeout)
high_timeout--;
else
select_src(SRC_NONE);
/* Are we still critical? */ /* Are we still critical? */
} else if (adc_batt < VBATT_CRIT) { } else if (adc_batt < VBATT_CRIT) {
#ifdef DEBUG #ifdef DEBUG

View File

@ -29,6 +29,11 @@
*/ */
#define SRC_TIMEOUT (15) #define SRC_TIMEOUT (15)
/*!
* How long to wait at high battery before shutdown?
*/
#define HIGH_TIMEOUT (5)
/*! /*!
* How long before we change LED states? * How long before we change LED states?
*/ */