Mercurial > public > ostc4
diff Small_CPU/Src/batteryCharger.c @ 668:079bb5b22c06 Betatest
Rework charge cycle:
The charge counter is increasing decreasing also if the real value is maybe not defined (definition is done for example by a completed charging cycle). This caused some problems with invalid displayed charge per centage values. To avoid this the state of an unknow counter value was introduced. The indication is done by converting the counter into a negativ value.
author | Ideenmodellierer |
---|---|
date | Sat, 12 Mar 2022 22:48:45 +0100 |
parents | 1b995079c045 |
children | b1e24513b83e |
line wrap: on
line diff
--- a/Small_CPU/Src/batteryCharger.c Sat Mar 12 22:42:56 2022 +0100 +++ b/Small_CPU/Src/batteryCharger.c Sat Mar 12 22:48:45 2022 +0100 @@ -39,8 +39,8 @@ #define CHARGER_DEBOUNCE_SECONDS (6u) /* 6 seconds used to avoid problems with charger interrupts / disconnections */ -uint8_t battery_i_charge_status = 0; -uint16_t battery_charger_counter = 0; +static uint8_t battery_i_charge_status = 0; +static uint16_t battery_charger_counter = 0; #ifdef ENABLE_CHARGER_STATUS_V2 static chargerState_t batteryChargerState = Charger_NotConnected; @@ -141,7 +141,6 @@ { #ifdef ENABLE_CHARGER_STATUS_V2 static uint8_t notifyChargeComplete = 0; - static float chargeValueAtStart = 0; #endif #ifdef OSTC_ON_DISCOVERY_HARDWARE @@ -158,10 +157,6 @@ { battery_gas_gauge_set_charge_full(); } - else /* unknown state => reset to 0% */ - { - battery_gas_gauge_set(0); - } batteryChargerState = Charger_NotConnected; } } @@ -176,13 +171,15 @@ batteryChargerState = Charger_LostConnection; battery_charger_counter = CHARGER_DEBOUNCE_SECONDS; break; - case Charger_LostConnection: if(get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE) /* the charger stops charging when charge current is 1/10 */ - /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ + case Charger_LostConnection: /* the charger stops charging when charge current is 1/10 */ + /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ + if(((battery_gas_gauge_isChargeValueValid() == 0) || (global.lifeData.battery_charge < 90)) && (get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE)) { batteryChargerState = Charger_Finished; global.dataSendToMaster.chargeStatus = CHARGER_complete; global.deviceDataSendToMaster.chargeStatus = CHARGER_complete; notifyChargeComplete = 1; + battery_charger_counter = 0; } /* no break */ case Charger_WarmUp: @@ -210,13 +207,6 @@ HAL_Delay(50); /* I2C operations are pending in the background. Wait to avoid data loose in caused to potential change to sleep state */ } } - else - { - if(chargeValueAtStart < 1.0) /* charging started with unknown value => reset charge state reported by charger */ - { - battery_gas_gauge_set(0); - } - } batteryChargerState = Charger_NotConnected; } break; @@ -232,7 +222,6 @@ case Charger_NotConnected: battery_i_charge_status = 1; battery_charger_counter = 0; batteryChargerState = Charger_WarmUp; - chargeValueAtStart = global.lifeData.battery_charge; break; case Charger_LostConnection: batteryChargerState = Charger_Active; break; @@ -268,6 +257,10 @@ } else { + if(global.lifeData.battery_charge > 100.0) /* still charging but indicator is set to full => decrease to 99% to keep count increasing */ + { + battery_gas_gauge_set(99.0); + } if(batteryChargerState == Charger_Finished) /* voltage dropped below the hysteresis again => charging restarted */ { batteryChargerState = Charger_Active;