diff Small_CPU/Src/batteryGasGauge.c @ 433:aa286a4926c2 Improve_BatteryGasGauge

Detect startup after power off: Introduced a variable in memory area which is not initialized during startup. In case of a start from power off the memory cell will be initialized (persistant as long as RTE is powered) and charge counter is set to 0 signaling the user to do a complete charge to calibrate the counter.
author ideenmodellierer
date Sun, 23 Feb 2020 21:09:56 +0100
parents 2fc08a0d1ec3
children 1b995079c045
line wrap: on
line diff
--- a/Small_CPU/Src/batteryGasGauge.c	Tue Feb 18 12:41:45 2020 +0100
+++ b/Small_CPU/Src/batteryGasGauge.c	Sun Feb 23 21:09:56 2020 +0100
@@ -64,7 +64,7 @@
 	buffer[0] = 0x01;
 
 	// F8 = 11111000:
-	// Vbat 3.0V (11)
+	// ADC auto mode (11)
 	// Prescale M = 128 (111)
 	// AL/CC pin disable (0)
 	// Shutdown (0)
@@ -127,8 +127,8 @@
 		// max/full: 0.085 mAh * 1 * 65535 = 5570 mAh
 		battery_f_charge_percent_local =  (float)(bufferReceive[2] * 256);
 		battery_f_charge_percent_local += (float)(bufferReceive[3]);
-		battery_f_charge_percent_local -= BGG_BATTERY_OFFSET;
-		battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER;
+		battery_f_charge_percent_local -= BGG_BATTERY_OFFSET;		/* Because of the prescalar 128 the counter assumes a max value of 5570mAh => normalize to 3350mAh*/
+		battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER;		/* transform to percentage */
 
 		if(battery_f_charge_percent_local < 0)
 			battery_f_charge_percent_local = 0;