Moved power functions from SoC.c to powerSave.c

This commit is contained in:
doppelhub
2024-11-01 21:55:05 -04:00
parent 0b5b5e3858
commit 634ad20d5c
7 changed files with 43 additions and 42 deletions

View File

@@ -61,7 +61,7 @@ void loop()
{ {
LTC68042cell_acquireAllCellVoltages(); LTC68042cell_acquireAllCellVoltages();
SoC_updateUsingLatestOpenCircuitVoltage(); SoC_updateUsingLatestOpenCircuitVoltage();
SoC_turnOffLiBCM_ifPackEmpty(); powerSave_turnOffLiBCM_ifPackEmpty();
debugUSB_printLatest_data_gridCharger(); debugUSB_printLatest_data_gridCharger();
} }
else else

View File

@@ -114,41 +114,6 @@ void SoC_updateUsingLatestOpenCircuitVoltage(void)
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
//turn LiBCM off if any cell voltage is too low
//LiBCM remains off until the next keyON occurs
//prevents over-discharge during extended keyOFF
void SoC_turnOffLiBCM_ifPackEmpty(void)
{
if (LTC68042result_loCellVoltage_get() < CELL_VMIN_GRIDCHARGER)
{
Serial.print(F("\nBattery is empty"));
gpio_turnLiBCM_off(); //game over, thanks for playing
}
else if ((LTC68042result_loCellVoltage_get() < CELL_VMIN_KEYOFF) && //battery is low
(time_hasKeyBeenOffLongEnough_toTurnOffLiBCM() == true) && //give user time to plug in charger
(gpio_isGridChargerChargingNow() == NO) ) //grid charger isn't charging
{
Serial.print(F("\nBattery is low"));
gpio_turnLiBCM_off(); //game over, thanks for playing
}
}
/////////////////////////////////////////////////////////////////////////////////////////
bool SoC_isThermalManagementAllowed(void)
{
bool enoughEnergy = NO;
if ((key_getSampledState() == KEYSTATE_ON) ||
((gpio_isGridChargerPluggedInNow() == YES) && (SoC_getBatteryStateNow_percent() > 3)) ||
(SoC_getBatteryStateNow_percent() > KEYOFF_DISABLE_THERMAL_MANAGEMENT_BELOW_SoC_PERCENT) )
{ enoughEnergy = YES; }
return enoughEnergy;
}
/////////////////////////////////////////////////////////////////////////////////////////
//Calling this function when battery is sourcing/sinking current will cause estimation error //Calling this function when battery is sourcing/sinking current will cause estimation error
//Wait at least ten minutes after keyOff for most accurate results //Wait at least ten minutes after keyOff for most accurate results
#ifdef BATTERY_TYPE_5AhG3 #ifdef BATTERY_TYPE_5AhG3

View File

@@ -16,10 +16,6 @@
void SoC_updateUsingLatestOpenCircuitVoltage(void); void SoC_updateUsingLatestOpenCircuitVoltage(void);
void SoC_turnOffLiBCM_ifPackEmpty(void);
bool SoC_isThermalManagementAllowed(void);
void SoC_handler(void); void SoC_handler(void);
#ifdef BATTERY_TYPE_5AhG3 #ifdef BATTERY_TYPE_5AhG3

View File

@@ -237,7 +237,7 @@ void fan_handler(void)
determineFastestFanSpeedRequest(); //result stored in fanSpeed_goal determineFastestFanSpeedRequest(); //result stored in fanSpeed_goal
if (SoC_isThermalManagementAllowed() == NO) { fanSpeed_now = FAN_OFF; } //not enough energy to run fans if (powerSave_isThermalManagementAllowed() == NO) { fanSpeed_now = FAN_OFF; } //not enough energy to run fans
else else
{ {
if ((fanSpeed_now != fanSpeed_goal) && if ((fanSpeed_now != fanSpeed_goal) &&

View File

@@ -74,7 +74,7 @@ bool heater_isPackTooHot(void)
void heater_handler(void) void heater_handler(void)
{ {
if ((SoC_isThermalManagementAllowed() == NO) || //not enough energy to heat pack if ((powerSave_isThermalManagementAllowed() == NO) || //not enough energy to heat pack
(heater_isConnected() == HEATER_NOT_CONNECTED) || //heater not installed (heater_isConnected() == HEATER_NOT_CONNECTED) || //heater not installed
(heater_isPackTooHot() == YES) ) //pack is too hot (heater_isPackTooHot() == YES) ) //pack is too hot
{ gpio_turnPackHeater_off(); } //heater not allowed { gpio_turnPackHeater_off(); } //heater not allowed

View File

@@ -15,6 +15,41 @@ volatile uint8_t interruptSource = USB_INTERRUPT; //see ISR(PCINT1_vect) for mor
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
//turn LiBCM off if any cell voltage is too low
//LiBCM remains off until the next keyON occurs
//prevents over-discharge during extended keyOFF
void powerSave_turnOffLiBCM_ifPackEmpty(void)
{
if (LTC68042result_loCellVoltage_get() < CELL_VMIN_GRIDCHARGER)
{
Serial.print(F("\nBattery is empty"));
gpio_turnLiBCM_off(); //game over, thanks for playing
}
else if ((LTC68042result_loCellVoltage_get() < CELL_VMIN_KEYOFF) && //battery is low
(time_hasKeyBeenOffLongEnough_toTurnOffLiBCM() == true) && //give user time to plug in charger
(gpio_isGridChargerChargingNow() == NO) ) //grid charger isn't charging
{
Serial.print(F("\nBattery is low"));
gpio_turnLiBCM_off(); //game over, thanks for playing
}
}
/////////////////////////////////////////////////////////////////////////////////////////
bool powerSave_isThermalManagementAllowed(void)
{
bool enoughEnergy = NO;
if ((key_getSampledState() == KEYSTATE_ON) ||
((gpio_isGridChargerPluggedInNow() == YES) && (SoC_getBatteryStateNow_percent() > 3)) ||
(SoC_getBatteryStateNow_percent() > KEYOFF_DISABLE_THERMAL_MANAGEMENT_BELOW_SoC_PERCENT) )
{ enoughEnergy = YES; }
return enoughEnergy;
}
/////////////////////////////////////////////////////////////////////////////////////////
void wakeupInterrupts_keyOn_enable(void) void wakeupInterrupts_keyOn_enable(void)
{ {
PCIFR |= (1 << PCIF0 ); //clear pending interrupt flag, if set PCIFR |= (1 << PCIF0 ); //clear pending interrupt flag, if set

View File

@@ -17,6 +17,11 @@
void powerSave_init(void); void powerSave_init(void);
void powerSave_turnOffIfAllowed(void); void powerSave_turnOffIfAllowed(void);
void powerSave_sleepIfAllowed(void); void powerSave_sleepIfAllowed(void);
void powerSave_turnOffLiBCM_ifPackEmpty(void);
bool powerSave_isThermalManagementAllowed(void);
#endif #endif