Battery Percentage Calculation and interfacing battery with LPC2148

Thread Starter

hanmant

Joined Sep 29, 2017
14
Hi,
Dear All,
I have used 7.4V ,5200mAh battery ,i have interfaced with my controller(lpc2148) ,my battery is connected to controller's ADC input pin via Voltage divider and my divider is R1=10K and R2=4.7K.
As per calculation im getting 2.36V at divider's((R2/R1+R2)xVin) output.and my ADC Highest count is nearly 780 ;so i wanted to calculate percentage of battery .
can you guys please help me out .
 

KeithWalker

Joined Jul 10, 2017
413
Hi,
Dear All,
I have used 7.4V ,5200mAh battery ,i have interfaced with my controller(lpc2148) ,my battery is connected to controller's ADC input pin via Voltage divider and my divider is R1=10K and R2=4.7K.
As per calculation im getting 2.36V at divider's((R2/R1+R2)xVin) output.and my ADC Highest count is nearly 780 ;so i wanted to calculate percentage of battery .
can you guys please help me out .
The voltage discharge curve of a LiPo battery is not very linear. It affected by temperature and discharge rate. The voltage drops off at a fairly linear rate from 100% to about 20% of capacity but then changes rapidly until the discharge point. If you can characterize that curve and apply it to your results, you will have a fairly good indication of the charge as long as the temperature and discharge current are fairly constant.

LiPoDisch.jpg
 

crutschow

Joined Mar 14, 2008
23,310
The easiest would probably to use a lookup table with the values shown in post #3 (say for every 5%) to extrapolate the amount of charge remaining from the battery voltage.
 

Thread Starter

hanmant

Joined Sep 29, 2017
14
If you're trying to make a 'gas gauge' to calculate the level of charge, be aware that the voltage of a lithium battery (which yours appears to be) is not a good indicator. A better method is to use a Coulomb-counter.
Hi @Alec_t ,Thanks for replying ,but its not for 'Gas Gauge'; actually im just trying to display battery percentage on LCD .But Im getting wrong result.my calculation is as,

I have used 7.4V ,I have interfaced battery with controller but in wanted calculate the percentage of battery.

I have interfaced battery via voltage divider with ADC Input ,My divider is as ,
R1=10k,R2=4.7k and i have used 3.3v as vref

as Max Cutoff voltage of battery is Vin 7.4V
=(R2/R1+R2)Vin
=2.36V and My Max ADC count is 800
and if i consider min cuttoff is 5.2 so,
=1.66V
Hence ,
At 100% =2.36-1.66=0.7
at 1% 0.7/100 =0.007

BatteryPercantage = (realvtg-1.66)/0.007
realvtg=ADCCount x(2.36/800)

But My result is Coming wrong ; I dont know where im doing wrong.
Can you Please tell me how can do this.
 

Thread Starter

hanmant

Joined Sep 29, 2017
14
The easiest would probably to use a lookup table with the values shown in post #3 (say for every 5%) to extrapolate the amount of charge remaining from the battery voltage.
@crutschow Hi, Thanks for replying ,my calculation is as
I have used 7.4V ,I have interfaced battery with controller but in wanted calculate the percentage of battery.
I have interfaced battery via voltage divider with ADC Input ,My divider is as ,
R1=10k,R2=4.7k and i have used 3.3v as vref
as Max Cutoff voltage of battery is Vin 7.4V
=(R2/R1+R2)Vin
=2.36V and My Max ADC count is 800
and if i consider min cuttoff is 5.2 so,
=1.66V
Hence ,
At 100% =2.36-1.66=0.7
at 1% 0.7/100 =0.007
BatteryPercantage = (realvtg-1.66)/0.007
realvtg=ADCCount x(2.36/800)
But My result is Coming wrong ; I dont know where im doing wrong.
Can you Please tell me how can do this.
 

Thread Starter

hanmant

Joined Sep 29, 2017
14
Hi,
Dear All,
I have used 7.4V ,5200mAh battery ,i have interfaced with my controller(lpc2148) ,my battery is connected to controller's ADC input pin via Voltage divider and my divider is R1=10K and R2=4.7K.
As per calculation im getting 2.36V at divider's((R2/R1+R2)xVin) output.and my ADC Highest count is nearly 780 ;so i wanted to calculate percentage of battery .
can you guys please help me out .
My calculation for same is as,
I have used 7.4V ,I have interfaced battery with controller but in wanted calculate the percentage of battery.
I have interfaced battery via voltage divider with ADC Input ,My divider is as ,
R1=10k,R2=4.7k and i have used 3.3v as vref
as Max Cutoff voltage of battery is Vin 7.4V
=(R2/R1+R2)Vin
=2.36V and My Max ADC count is 800
and if i consider min cuttoff is 5.2 so,
=1.66V
Hence ,
At 100% =2.36-1.66=0.7
at 1% 0.7/100 =0.007
BatteryPercantage = (realvtg-1.66)/0.007
realvtg=ADCCount x(2.36/800)
But My result is Coming wrong ; I dont know where im doing wrong.
Can you Please tell me how can do this.
 

KeithWalker

Joined Jul 10, 2017
413
My calculation for same is as,
I have used 7.4V ,I have interfaced battery with controller but in wanted calculate the percentage of battery.
I have interfaced battery via voltage divider with ADC Input ,My divider is as ,
R1=10k,R2=4.7k and i have used 3.3v as vref
as Max Cutoff voltage of battery is Vin 7.4V
=(R2/R1+R2)Vin
=2.36V and My Max ADC count is 800
and if i consider min cuttoff is 5.2 so,
=1.66V
Hence ,
At 100% =2.36-1.66=0.7
at 1% 0.7/100 =0.007
BatteryPercantage = (realvtg-1.66)/0.007
realvtg=ADCCount x(2.36/800)
But My result is Coming wrong ; I dont know where im doing wrong.
Can you Please tell me how can do this.
Fully charged, your two cell pack will measure 8.4 volts. If you discharge the pack much below 3 volts per cell you will damage the battery. I am assuming you are using the 10 bit counter on an Arduino using the 3.3 volt reference. This will give you a count of 1023 for full scale of 3,3 volts input. So taking 8.4 volts as 100% and 3 volts as 0:

At max, output at divider = 8.4 x 4.7/14.7 = 2.68 volts
At max, adc count = 2.68/3.3 x 1023 = 999

At min, output at divider = 3 x 4.7/14.7 = 0.959 volts
At min, adc count = 0.951/3.3 x 1023 = 295

You can use the arduino "map" function to scale the readings:
val1 = map (val1, 295, 990, 0, 100);

As mentioned, it will not be linear. You could, as suggested, use the values with a lookup table to give more accurate results.
 
Last edited:

crutschow

Joined Mar 14, 2008
23,310
As bertus noted, the voltage versus capacity is not linear.
You can use a lookup table (voltage vs capacity at each point) as I suggested, and do linear interpolation between points.
If the points are close enough together (say every 5%) than the linear interpolation between points should be sufficiently accurate for your purposes.
 

Thread Starter

hanmant

Joined Sep 29, 2017
14
Fully charged, your two cell pack will measure 8.4 volts. If you discharge the pack much below 3 volts per cell you will damage the battery. I am assuming you are using the 10 bit counter on an Arduino using the 3.3 volt reference. This will give you a count of 1023 for full scale of 3,3 volts input. So taking 8.4 volts as 100% and 3 volts as 0:

At max, output at divider = 8.4 x 4.7/14.7 = 2.68 volts
At max, adc count = 2.68/3.3 x 1023 = 999

At min, output at divider = 3 x 4.7/14.7 = 0.959 volts
At min, adc count = 0.951/3.3 x 1023 = 295

You can use the arduino "map" function to scale the readings:
val1 = map (val1, 295, 990, 0, 100);

As mentioned, it will not be linear. You could, as suggested, use the values with a lookup table to give more accurate results.
Yes my results are coming nonlinear
 

Thread Starter

hanmant

Joined Sep 29, 2017
14
Fully charged, your two cell pack will measure 8.4 volts. If you discharge the pack much below 3 volts per cell you will damage the battery. I am assuming you are using the 10 bit counter on an Arduino using the 3.3 volt reference. This will give you a count of 1023 for full scale of 3,3 volts input. So taking 8.4 volts as 100% and 3 volts as 0:

At max, output at divider = 8.4 x 4.7/14.7 = 2.68 volts
At max, adc count = 2.68/3.3 x 1023 = 999

At min, output at divider = 3 x 4.7/14.7 = 0.959 volts
At min, adc count = 0.951/3.3 x 1023 = 295

You can use the arduino "map" function to scale the readings:
val1 = map (val1, 295, 990, 0, 100);

As mentioned, it will not be linear. You could, as suggested, use the values with a lookup table to give more accurate results.
Instead of Arduino I'm using lpc2148
 

crutschow

Joined Mar 14, 2008
23,310
Sorry ,I didn't understand how to use look-up table.
Can you please tell me
It's a table of values that you store in non-volatile computer memory (flash or EEPROM) to use in the calculations.
In this case it would be two values for each point.
For example, if you did them at each 10% of capacity used in the battery, you would have (estimated from post #3 @0.2C):

0, 4.15
10, 4.02
20, 3.94
30, 3.87
etc.


You then use the table to generate the % capacity used.
So if you measured a battery voltage of 3.98V you would linearly interpolate between the 10% and the 20% voltage values to drive the value for 3.98V.
 
Top