comparison 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
comparison
equal deleted inserted replaced
432:2b4440f75434 433:aa286a4926c2
62 62
63 uint8_t buffer[2]; 63 uint8_t buffer[2];
64 buffer[0] = 0x01; 64 buffer[0] = 0x01;
65 65
66 // F8 = 11111000: 66 // F8 = 11111000:
67 // Vbat 3.0V (11) 67 // ADC auto mode (11)
68 // Prescale M = 128 (111) 68 // Prescale M = 128 (111)
69 // AL/CC pin disable (0) 69 // AL/CC pin disable (0)
70 // Shutdown (0) 70 // Shutdown (0)
71 buffer[1] = 0xF8; 71 buffer[1] = 0xF8;
72 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); 72 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
125 battery_f_voltage_local *= (float)6 / (float)0xFFFF; 125 battery_f_voltage_local *= (float)6 / (float)0xFFFF;
126 126
127 // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh 127 // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh
128 battery_f_charge_percent_local = (float)(bufferReceive[2] * 256); 128 battery_f_charge_percent_local = (float)(bufferReceive[2] * 256);
129 battery_f_charge_percent_local += (float)(bufferReceive[3]); 129 battery_f_charge_percent_local += (float)(bufferReceive[3]);
130 battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; 130 battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; /* Because of the prescalar 128 the counter assumes a max value of 5570mAh => normalize to 3350mAh*/
131 battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; 131 battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; /* transform to percentage */
132 132
133 if(battery_f_charge_percent_local < 0) 133 if(battery_f_charge_percent_local < 0)
134 battery_f_charge_percent_local = 0; 134 battery_f_charge_percent_local = 0;
135 135
136 battery_f_voltage = battery_f_voltage_local; 136 battery_f_voltage = battery_f_voltage_local;