Mercurial > public > ostc4
comparison Small_CPU/Src/batteryGasGauge.c @ 437:6c824f902934
Merged in Ideenmodellierer/ostc4/Improve_BatteryGasGauge (pull request #40)
Improve BatteryGasGauge
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Mon, 24 Feb 2020 07:58:37 +0000 |
parents | aa286a4926c2 |
children | 1b995079c045 |
comparison
equal
deleted
inserted
replaced
432:2b4440f75434 | 437:6c824f902934 |
---|---|
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; |