mirror of
https://github.com/doppelhub/Honda_Insight_LiBCM.git
synced 2026-06-10 23:47:28 -04:00
Moved power functions from SoC.c to powerSave.c
This commit is contained in:
@@ -61,7 +61,7 @@ void loop()
|
||||
{
|
||||
LTC68042cell_acquireAllCellVoltages();
|
||||
SoC_updateUsingLatestOpenCircuitVoltage();
|
||||
SoC_turnOffLiBCM_ifPackEmpty();
|
||||
powerSave_turnOffLiBCM_ifPackEmpty();
|
||||
debugUSB_printLatest_data_gridCharger();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -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
|
||||
//Wait at least ten minutes after keyOff for most accurate results
|
||||
#ifdef BATTERY_TYPE_5AhG3
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
void SoC_updateUsingLatestOpenCircuitVoltage(void);
|
||||
|
||||
void SoC_turnOffLiBCM_ifPackEmpty(void);
|
||||
|
||||
bool SoC_isThermalManagementAllowed(void);
|
||||
|
||||
void SoC_handler(void);
|
||||
|
||||
#ifdef BATTERY_TYPE_5AhG3
|
||||
|
||||
@@ -237,7 +237,7 @@ void fan_handler(void)
|
||||
|
||||
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
|
||||
{
|
||||
if ((fanSpeed_now != fanSpeed_goal) &&
|
||||
|
||||
@@ -74,7 +74,7 @@ bool heater_isPackTooHot(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_isPackTooHot() == YES) ) //pack is too hot
|
||||
{ gpio_turnPackHeater_off(); } //heater not allowed
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
PCIFR |= (1 << PCIF0 ); //clear pending interrupt flag, if set
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
void powerSave_init(void);
|
||||
|
||||
void powerSave_turnOffIfAllowed(void);
|
||||
|
||||
void powerSave_sleepIfAllowed(void);
|
||||
|
||||
void powerSave_turnOffLiBCM_ifPackEmpty(void);
|
||||
|
||||
bool powerSave_isThermalManagementAllowed(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user