Skip to content

Commit 8b34702

Browse files
authored
Update mkr-battery-app-note.md
Added previous fix in all places.
1 parent 0887ca0 commit 8b34702

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

content/hardware/01.mkr/01.boards/mkr-wifi-1010/tutorials/mkr-battery-app-note/mkr-battery-app-note.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ void loop()
185185
**13.** In order to convert `rawADC` into a voltage reading (`voltADC`) we will divide `rawADC` by 4095 and then multiply it by the analog reference voltage (3.3V).
186186

187187
```arduino
188-
voltADC = rawADC * (3.3/4095.0);
188+
voltADC = rawADC * 3.3 / 4096.0;
189189
```
190190

191191
**14.** The `voltADC` variable gives us the voltage sensed directly on the PB09 pin. This voltage is passed through the voltage divider, so it is a fraction of the actual battery voltage. We can then calculate the equivilanet battery voltage as follows.
192192
```arduino
193-
voltBat = voltADC * (max_Source_voltage/3.3);
193+
voltBat = max_Source_voltage * rawADC / 4096.0;
194194
```
195195

196196
**15.** We can approximate the battery voltage to be proportional to the capacity level. Since the `map()` function does not work with float variables, we will manually map the values.
@@ -266,7 +266,7 @@ float voltBat; //calculated voltage on battery
266266
int R1 = 330000; // resistor between battery terminal and SAMD pin PB09
267267
int R2 = 1000000; // resistor between SAMD pin PB09 and ground
268268
269-
int max_Source_voltage; // upper source voltage for the battery
269+
float max_Source_voltage; // upper source voltage for the battery
270270
271271
// define voltage at which battery is full/empty
272272
float batteryFullVoltage = 4.2; //upper voltage limit for battery

0 commit comments

Comments
 (0)