LiPo Battery Voltage Monitor
.
To monitor a battery's voltage you need to set up a voltage divider to reduce the voltage to within the ADC range.
The example below is for a 7.4V 2cell LiPo Battery. LiPo batteries should not be discharged below 3V/cell or they will be destroyed. A 2cell LiPo will range from 8.4V (completely charged) down to around 6.4V (safe discharge). If the battery ever reaches 6V or less the battery is destroyed. This code lights a LED when the voltage drops below 6.4 V to warn the user to remove the battery.
Vbat(Vin) - R1 - p19 - R2 - GND
The voltage sensed on p19 is determined by the battery voltage and the resistor values R1 and R2. Vout = Vbat * R2 / (R1 + R2)
I chose resistors with the values R1 = 1k Ohm and R2 = 470 Ohm, resulting in R2 / (R1 + R2) = 0.320 Plugging in some values you get:
- 8.4V -> 2.687 V
- 8.0V -> 2.558 V
- 7.0V -> 2.238 V
- 6.4V -> 2.046 V
The read() function of AnalogIn outputs a value from 0.0 to 1.0 to represent the range 0.0V to 3.3V. This means that to calculate the voltage seen by the ADC pin you need to first multiply by 3.3. Then to reach the battery voltage you need to divide by 0.320.
Vbat = read() * 3.3 / 0.320 = read() * 10.3125
p24 - (LED) - R3 - Vout
R3 is a current limiting resistor to avoid damaging the LED. The formula for calculating is: R3 = (3.3 - Vd) / I Typical Values are Vd = 2 V and I = 20 mA, resulting in R3 = 65 Ohm
Import program
00001 #include "mbed.h" 00002 00003 DigitalOut myled(LED1); 00004 AnalogIn battery(p19); 00005 DigitalOut battery_warning(p24); 00006 Serial pc(USBTX, USBRX); 00007 00008 int main() { 00009 pc.baud(9600); 00010 const float BAT_MUL = 10.26; 00011 float sample; 00012 00013 while(1) { 00014 sample = battery.read(); 00015 pc.printf("VBat: %4.3f, ADC: %4.3f, Vadc: %4.3f\r\n", sample*BAT_MUL, sample, sample*3.3); 00016 if(sample*BAT_MUL < 6.4) 00017 battery_warning = 0; 00018 else 00019 battery_warning = 1; 00020 wait(1); 00021 } 00022 }
4 comments on LiPo Battery Voltage Monitor:
Please log in to post comments.
Can you chow me schematic of battery monitoring circuit with mbed please.