LiBCM now turns off 5 days after keyOff

LiBCM turns back on with keyOn, USB power, or toggling IMA switch.
This commit is contained in:
doppelhub
2024-10-08 03:10:48 -04:00
parent f50667f763
commit d12e8d5a21
5 changed files with 37 additions and 14 deletions

View File

@@ -7,8 +7,8 @@
#define config_h #define config_h
#include "src/libcm.h" #include "src/libcm.h"
#define FW_VERSION "0.9.4e" #define FW_VERSION "0.9.5"
#define BUILD_DATE "2024AUG19" #define BUILD_DATE "2024OCT07"
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@@ -114,7 +114,7 @@
//power saving //power saving
#define KEYOFF_DISABLE_THERMAL_MANAGEMENT_BELOW_SoC_PERCENT 50 //when keyOFF (unless grid charger plugged in) //set to 100 to disable when keyOFF #define KEYOFF_DISABLE_THERMAL_MANAGEMENT_BELOW_SoC_PERCENT 50 //when keyOFF (unless grid charger plugged in) //set to 100 to disable when keyOFF
#define POWEROFF_DELAY_AFTER_KEYOFF_PACK_EMPTY_MINUTES 10 //When SoC is below 10%, LiBCM will remain on for this many minutes after keyOFF. #define POWEROFF_DELAY_AFTER_KEYOFF_PACK_EMPTY_MINUTES 10 //When SoC is below 10%, LiBCM will remain on for this many minutes after keyOFF.
#define POWEROFF_DELAY_AFTER_KEYOFF_DAYS 5 //LiBCM turns off this many days after keyOff, unless grid charger powered #define POWEROFF_DELAY_AFTER_KEYOFF_DAYS 5 //LiBCM turns off this many days after keyOff, unless grid charger powered //comment line to disable
//to turn LiBCM back on: turn ignition 'ON', or turn IMA switch off and on, or plug in USB cable //to turn LiBCM back on: turn ignition 'ON', or turn IMA switch off and on, or plug in USB cable
//Choose which sign (±) the LCD displays when the battery is discharging //Choose which sign (±) the LCD displays when the battery is discharging

View File

@@ -64,7 +64,11 @@ void loop()
SoC_turnOffLiBCM_ifPackEmpty(); SoC_turnOffLiBCM_ifPackEmpty();
debugUSB_printLatest_data_gridCharger(); debugUSB_printLatest_data_gridCharger();
} }
else { powerSave_sleepIfAllowed(); } else
{
powerSave_turnOffIfAllowed();
powerSave_sleepIfAllowed();
}
} }
USB_userInterface_handler(); USB_userInterface_handler();

View File

@@ -121,7 +121,7 @@ void powerSave_gotoSleep(void)
clock_prescale_set(clock_div_1); //16 MHz clock_prescale_set(clock_div_1); //16 MHz
wakeupInterrupts_disable(); wakeupInterrupts_disable();
} }
interrupts(); interrupts();
USB_begin(); USB_begin();
@@ -136,9 +136,9 @@ void powerSave_gotoSleep(void)
void powerSave_sleepIfAllowed(void) void powerSave_sleepIfAllowed(void)
{ {
if ((cellBalance_areCellsBalancing() == NO) /* LiBCM must stay on for safety */ && if ((cellBalance_areCellsBalancing() == NO) /* LiBCM must stay on for safety */ &&
(gpio_isGridChargerPluggedInNow() == NO) /* LiBCM must stay on for safety */ && (gpio_isGridChargerPluggedInNow() == NO) /* LiBCM must stay on for safety */ &&
(time_sinceLatestUserInputUSB_get_ms() > PERIOD_TO_DISABLE_POWERSAVE_AFTER_USB_DATA_RECEIVED_ms) ) (time_sinceLatestUserInputUSB_get_ms() > PERIOD_TO_DISABLE_SLEEP_AFTER_USB_DATA_RECEIVED_ms) )
{ {
powerSave_gotoSleep(); powerSave_gotoSleep();
} }
@@ -146,6 +146,22 @@ void powerSave_sleepIfAllowed(void)
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
void powerSave_turnOffIfAllowed(void)
{
#ifdef POWEROFF_DELAY_AFTER_KEYOFF_DAYS
uint32_t timeSinceLatestKeyOff_ms = millis() - time_latestKeyOff_ms_get();
if ((gpio_isGridChargerPluggedInNow() == NO) &&
(time_sinceLatestGridChargerUnplug_get_ms() > PERIOD_TO_DISABLE_TURNOFF_AFTER_CHARGER_UNPLUGGED_ms) &&
(timeSinceLatestKeyOff_ms > (POWEROFF_DELAY_AFTER_KEYOFF_DAYS * MILLISECONDS_PER_DAY)) )
{
gpio_turnLiBCM_off();
}
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////
//timer2 wakes LiBCM up every ~1049 ms //timer2 wakes LiBCM up every ~1049 ms
//actual time is: 256_countsToOverflow/(16MHz/clockDiv64/timer2Div1024) //actual time is: 256_countsToOverflow/(16MHz/clockDiv64/timer2Div1024)
//this interrupt disabled when LiBCM is awake //this interrupt disabled when LiBCM is awake

View File

@@ -4,17 +4,19 @@
#ifndef powerSave_h #ifndef powerSave_h
#define powerSave_h #define powerSave_h
#define PERIOD_TO_DISABLE_POWERSAVE_AFTER_USB_DATA_RECEIVED_ms 60000 #define PERIOD_TO_DISABLE_SLEEP_AFTER_USB_DATA_RECEIVED_ms ((uint32_t)60000)
#define PERIOD_TO_DISABLE_TURNOFF_AFTER_CHARGER_UNPLUGGED_hours 4 //prevents turnoff during brief AC power outage
#define PERIOD_TO_DISABLE_TURNOFF_AFTER_CHARGER_UNPLUGGED_ms (((uint32_t)1000 * 60 * 60) * PERIOD_TO_DISABLE_TURNOFF_AFTER_CHARGER_UNPLUGGED_hours)
// UNKNOWN_INTERRUPT 0 //specifically not defined //see explanation in 'ISR(PCINT1_vect)' // UNKNOWN_INTERRUPT 0 //specifically not defined //see explanation in 'ISR(PCINT1_vect)'
#define USB_INTERRUPT 1 #define USB_INTERRUPT 1
#define KEYON_INTERRUPT 2 #define KEYON_INTERRUPT 2
#define TIMER2_INTERRUPT 3 #define TIMER2_INTERRUPT 3
void powerSave_handler(void);
void powerSave_init(void); void powerSave_init(void);
void powerSave_turnOffIfAllowed(void);
void powerSave_sleepIfAllowed(void); void powerSave_sleepIfAllowed(void);
#endif #endif

View File

@@ -42,8 +42,8 @@
#define STOP_TIMER false #define STOP_TIMER false
#define MILLIS_MAXIMUM_VALUE 0xFFFFFFFF //2^32-1 #define MILLIS_MAXIMUM_VALUE 0xFFFFFFFF //2^32-1
#define KEY_OFF_UPDATE_PERIOD_ONE_SECOND_ms ( 1 * 1000) #define KEY_OFF_UPDATE_PERIOD_ONE_SECOND_ms ((uint32_t)1 * 1000)
#define KEY_OFF_UPDATE_PERIOD_TEN_MINUTES_ms (10 * 60000) #define KEY_OFF_UPDATE_PERIOD_TEN_MINUTES_ms ((uint32_t)10 * 60000)
//JTS2doLater: When the key is on - but the IMA switch is off (or fuse blown) - reduce LTC6804 update period to minimize LTC6804 power consumption //JTS2doLater: When the key is on - but the IMA switch is off (or fuse blown) - reduce LTC6804 update period to minimize LTC6804 power consumption
//Tests to determine whether the IMA switch is on or off: //Tests to determine whether the IMA switch is on or off:
//1) compare the VPIN input signal (HVDC voltage inside the PDU) with the pack voltage (as determined by the LTC6804 ICs). //1) compare the VPIN input signal (HVDC voltage inside the PDU) with the pack voltage (as determined by the LTC6804 ICs).
@@ -51,7 +51,8 @@
//2) LiBCM can reset a timer each time the battery current sensor magnitude exceeds 0 amps (which can only happen if the IMA switch is on). //2) LiBCM can reset a timer each time the battery current sensor magnitude exceeds 0 amps (which can only happen if the IMA switch is on).
//2) If the timer overflows (e.g. after an hour with 0 amps through the pack), LiBCM can likely conclude that the IMA switch is off. //2) If the timer overflows (e.g. after an hour with 0 amps through the pack), LiBCM can likely conclude that the IMA switch is off.
#define MILLISECONDS_PER_HOUR 3600000 #define MILLISECONDS_PER_HOUR ((uint32_t)1000 * 60 * 60)
#define MILLISECONDS_PER_DAY ((uint32_t)24 * MILLISECONDS_PER_HOUR)
#define TIME_DEFAULT_LOOP_PERIOD_ms 10 #define TIME_DEFAULT_LOOP_PERIOD_ms 10