Mercurial > public > ostc4
comparison Small_CPU/Src/batteryCharger.c @ 686:b1e24513b83e Betatest
Bugfix Battery charge complete event:
In previous version it could happen that the battery charge state was set to 100% even the battery was not completly charged. Rootcause was that the external charger IC signals sometimes completion because e.g. the connection between charger unit and OSTC is disconnected within a short time slot. This may happen while the user is trying to get the OSTC in a good charging position. To avoid this the state machine now checks the voltage everytime for valid charging complete range before a charging complete is signaled.
author | Ideenmodellierer |
---|---|
date | Fri, 05 Aug 2022 14:56:17 +0200 |
parents | 079bb5b22c06 |
children | d32901746950 |
comparison
equal
deleted
inserted
replaced
685:980d7f8d5530 | 686:b1e24513b83e |
---|---|
149 | 149 |
150 #ifdef ENABLE_CHARGER_STATUS_V2 | 150 #ifdef ENABLE_CHARGER_STATUS_V2 |
151 | 151 |
152 if(batteryChargerState == Charger_ColdStart) /* wait for the first valid voltage meassurement */ | 152 if(batteryChargerState == Charger_ColdStart) /* wait for the first valid voltage meassurement */ |
153 { | 153 { |
154 if(global.lifeData.battery_voltage != BATTERY_DEFAULT_VOLTAGE) | 154 if((global.lifeData.battery_voltage != BATTERY_DEFAULT_VOLTAGE) && (global.lifeData.battery_voltage < BATTERY_CHARGER_CONNECTED_VOLTAGE)) |
155 { | 155 { |
156 if(global.lifeData.battery_voltage > BATTERY_ENDOF_CHARGE_VOLTAGE) /* Voltage close to full state => maybe new battery inserted */ | 156 if(global.lifeData.battery_voltage > BATTERY_ENDOF_CHARGE_VOLTAGE) /* Voltage close to full state => maybe new battery inserted */ |
157 { | 157 { |
158 battery_gas_gauge_set_charge_full(); | 158 battery_gas_gauge_set_charge_full(); |
159 } | 159 } |
164 { /* on disconnection or while disconnected */ | 164 { /* on disconnection or while disconnected */ |
165 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN)) | 165 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN)) |
166 { | 166 { |
167 switch(batteryChargerState) | 167 switch(batteryChargerState) |
168 { | 168 { |
169 case Charger_WarmUp: | |
169 case Charger_Active: global.dataSendToMaster.chargeStatus = CHARGER_lostConnection; | 170 case Charger_Active: global.dataSendToMaster.chargeStatus = CHARGER_lostConnection; |
170 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection; | 171 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection; |
171 batteryChargerState = Charger_LostConnection; | 172 batteryChargerState = Charger_LostConnection; |
172 battery_charger_counter = CHARGER_DEBOUNCE_SECONDS; | 173 if(cycleTimeBase > CHARGER_DEBOUNCE_SECONDS) /* adapt connection lost detection to sleep mode */ |
173 break; | 174 { |
175 battery_charger_counter = cycleTimeBase + 1; | |
176 } | |
177 else | |
178 { | |
179 battery_charger_counter = CHARGER_DEBOUNCE_SECONDS; | |
180 } | |
181 break; | |
182 case Charger_Finished: battery_charger_counter = 0; | |
183 batteryChargerState = Charger_LostConnection; | |
184 /* no break */ | |
174 case Charger_LostConnection: /* the charger stops charging when charge current is 1/10 */ | 185 case Charger_LostConnection: /* the charger stops charging when charge current is 1/10 */ |
175 /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ | 186 /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ |
176 if(((battery_gas_gauge_isChargeValueValid() == 0) || (global.lifeData.battery_charge < 90)) && (get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE)) | 187 if(((battery_gas_gauge_isChargeValueValid() == 0) || (global.lifeData.battery_charge < 90)) && (get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE) && (get_voltage() < BATTERY_CHARGER_CONNECTED_VOLTAGE)) |
177 { | 188 { |
178 batteryChargerState = Charger_Finished; | |
179 global.dataSendToMaster.chargeStatus = CHARGER_complete; | |
180 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete; | |
181 notifyChargeComplete = 1; | 189 notifyChargeComplete = 1; |
182 battery_charger_counter = 0; | 190 } |
183 } | 191 else |
184 /* no break */ | 192 { |
185 case Charger_WarmUp: | 193 notifyChargeComplete = 0; |
186 case Charger_Finished: if(battery_charger_counter >= cycleTimeBase) | 194 } |
195 if(battery_charger_counter >= cycleTimeBase) | |
187 { | 196 { |
188 battery_charger_counter -= cycleTimeBase; | 197 battery_charger_counter -= cycleTimeBase; |
189 global.dataSendToMaster.chargeStatus = CHARGER_lostConnection; | |
190 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection; | |
191 batteryChargerState = Charger_LostConnection; | |
192 } | 198 } |
193 else | 199 else |
194 { | 200 { |
195 battery_charger_counter = 0; | 201 battery_charger_counter = 0; |
196 battery_i_charge_status = 0; | 202 battery_i_charge_status = 0; |
200 if(notifyChargeComplete) | 206 if(notifyChargeComplete) |
201 { | 207 { |
202 battery_gas_gauge_set_charge_full(); | 208 battery_gas_gauge_set_charge_full(); |
203 scheduleUpdateDeviceDataChargerFull(); | 209 scheduleUpdateDeviceDataChargerFull(); |
204 notifyChargeComplete = 0; | 210 notifyChargeComplete = 0; |
205 if(cycleTimeBase > 2) | |
206 { | |
207 HAL_Delay(50); /* I2C operations are pending in the background. Wait to avoid data loose in caused to potential change to sleep state */ | |
208 } | |
209 } | 211 } |
210 batteryChargerState = Charger_NotConnected; | 212 batteryChargerState = Charger_NotConnected; |
211 } | 213 } |
212 break; | 214 break; |
213 default: break; | 215 default: break; |