comparison Small_CPU/Src/batteryCharger.c @ 645:e58f81cb25a7

Small changes in charger state handling: Charger debounce time has been reduced to 5 seconds and the detection time of charger removal has been reduced to 15 second to be able to provide a faster feedback to the user. In addition the battery stage reset has been added (only relevant for a getState function which is not used within the firmware at the moment.
author Ideenmodellierer
date Tue, 13 Apr 2021 19:18:32 +0200
parents ebe3fc302ab8
children 1b995079c045
comparison
equal deleted inserted replaced
644:ebe3fc302ab8 645:e58f81cb25a7
43 43
44 #define CHARGE_OUT_PIN GPIO_PIN_1 44 #define CHARGE_OUT_PIN GPIO_PIN_1
45 #define CHARGE_OUT_GPIO_PORT GPIOC 45 #define CHARGE_OUT_GPIO_PORT GPIOC
46 #define CHARGE_OUT_GPIO_ENABLE() __GPIOC_CLK_ENABLE() 46 #define CHARGE_OUT_GPIO_ENABLE() __GPIOC_CLK_ENABLE()
47 47
48 #define CHARGER_DEBOUNCE_SECONDS (120u) /* 120 seconds used to avoid problems with charger interrupts / disconnections */ 48 #define CHARGER_DEBOUNCE_SECONDS (5u) /* 5 seconds used to avoid problems with charger interrupts / disconnections */
49 49
50 uint8_t battery_i_charge_status = 0; 50 uint8_t battery_i_charge_status = 0;
51 uint16_t battery_charger_counter = 0; 51 uint16_t battery_charger_counter = 0;
52 52
53 #ifdef ENABLE_CHARGER_STATUS_V2 53 #ifdef ENABLE_CHARGER_STATUS_V2
163 if(get_voltage() >= 4.1f) /* the charger stops charging when charge current is 1/10. */ 163 if(get_voltage() >= 4.1f) /* the charger stops charging when charge current is 1/10. */
164 { /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ 164 { /* Basically it is OK to rate a charging as complete if a defined voltage is reached */
165 batteryChargerState = Charger_Finished; 165 batteryChargerState = Charger_Finished;
166 global.dataSendToMaster.chargeStatus = CHARGER_complete; 166 global.dataSendToMaster.chargeStatus = CHARGER_complete;
167 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete; 167 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete;
168 battery_charger_counter = 30; 168 battery_charger_counter = 15;
169 notifyChargeComplete = 1; 169 notifyChargeComplete = 1;
170 } 170 }
171 break; 171 break;
172 case Charger_WarmUp: 172 case Charger_WarmUp:
173 case Charger_Finished: 173 case Charger_Finished:
179 batteryChargerState = Charger_LostConnection; 179 batteryChargerState = Charger_LostConnection;
180 } 180 }
181 else 181 else
182 { 182 {
183 battery_charger_counter = 0; 183 battery_charger_counter = 0;
184 battery_i_charge_status = 0;
184 global.dataSendToMaster.chargeStatus = CHARGER_off; 185 global.dataSendToMaster.chargeStatus = CHARGER_off;
185 global.deviceDataSendToMaster.chargeStatus = CHARGER_off; 186 global.deviceDataSendToMaster.chargeStatus = CHARGER_off;
186 187
187 if(notifyChargeComplete) 188 if(notifyChargeComplete)
188 { 189 {
251 GPIO_InitStructure.Pin = CHARGE_OUT_PIN; 252 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
252 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; 253 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
253 GPIO_InitStructure.Pull = GPIO_NOPULL; 254 GPIO_InitStructure.Pull = GPIO_NOPULL;
254 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; 255 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
255 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure); 256 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
257 HAL_Delay(1);
256 break; 258 break;
257 259
258 default: /* wait for disconnection */ 260 default: /* wait for disconnection */
259 break; 261 break;
260 } 262 }