Visual LEDs for LiPO battery

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
yellowfish
Posts: 7
Joined: Thu Mar 22, 2012 9:53 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Visual LEDs for LiPO battery

Post by yellowfish »

HI Clever people

I am trying to build a Lipo battery visual Status(watch Dog) with PIC
I am a beginner and only started the hobby after 15 years again when I discovered flowcode.

Attach my file.
Need to attach a unit to a RC helicopter and have a visual(LED) display on the status of the LiPo battey.
This for a Lipo from 3 Cell(12.6V) to 6 Cell(25.2) fully charged @ 4.2 Volt per cell. Table below showing the voltage per cell relates to the left over capacity.
Idea to use potential divider(need help on this also) , this is linear and assuming the pack is fully charge
Need to use % calculations so that I can add any lipo, from 3 cell to 6 cell. ADC takes initial value and compares with current value.(Total voltage) I have tried everything just not working, think I lack the maths skill .

H Understanding this will be a great breakthrough understanding ADC.

Attached my file, this not right as I have tried multiple options on getting this to work

4.20v = 100% Flash Green LED
4.03v = 76% Flash greeg LED
3.86v = 52% Flash GreennLED
3.83v = 42% Alternate red and green led from 50% to 30%
3.79v = 30% Flash only red LED when reaching 30%
3.70v = 11%
3.6?v = 0%
Attachments
Test Lipo Original.fcf
(17.36 KiB) Downloaded 271 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Visual LEDs for LiPO battery

Post by medelec35 »

Hi yellowfish,

Would you like to try this flowchart and let me know it is ok for you or not please.

One thing to consider:
You could some some battery power by powering LED's via PWM at say 1KHz.
All you would to is for flashing is alternately change duty between 0% and 90% for example every 500ms

Martin
Attachments
Test Lipo Modified1.fcf
(16.36 KiB) Downloaded 283 times
Martin

yellowfish
Posts: 7
Joined: Thu Mar 22, 2012 9:53 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Visual LEDs for LiPO battery

Post by yellowfish »

Hi Martin

This works just fine, much appreciated. Have so much to learn and great you sharing.

Will implement your suggestion on PWM for flashing led’s. The RC heli's draw up to 50 A while flying. On a 6 cell LiPo(25.2V) flight time is 7 min's and the saving with PWM, I think, will not do much in this application. Will benefit other applications where LiPo is used and bat life important.

Can you recommend a input circuit, voltage divider for connecting the LiPo battery to the pic. I suppose this will need to be linear and have to consider the input impedance for the A/D port on chip.

Will a resistor divider suffice for this application ?

Thanks for your help.


Regards

Martinus

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Visual LEDs for LiPO battery

Post by medelec35 »

Hi Martinus,
Your welcome, glad I could help.
yellowfish wrote: Will a resistor divider suffice for this application ?
Yes I would probably use a potential divider.
Something like this:
Suggested Voltage divider.png
(4.41 KiB) Downloaded 4522 times
Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: Visual LEDs for LiPO battery

Post by Steve001 »

hi,

you could also use op amps configured as a "instrument ampifier " if you wish to isolate you battery from your pic.
I used this in one of my projects to messure battery volts (which was 110 Vdc)

can post the circuit over the weekend if you wish let me know,

steve
Success always occurs in private and failure in full view.

yellowfish
Posts: 7
Joined: Thu Mar 22, 2012 9:53 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Visual LEDs for LiPO battery

Post by yellowfish »

Hi Steve, will appreciate your circuit, if you can over the weekend. Played around with this and could not make it work. Very rusted

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Visual LEDs for LiPO battery

Post by medelec35 »

yellowfish wrote: Played around with this and could not make it work. Very rusted
Assuming 25V supply (so link is not in place & 3k9 is not in the equation)..
Using ratio of 1/(4.7+1)
=0.175
if x by 25V
= 0.175 x 25 = 4.4V (2dp)
If 50% of 25V = 12.5V

Then using ratio of 0.175:
0.175 x 12.5 = 2.19V (2dp)

This represents a 50% drop ( from 4.4 to 2.18) so in theory should work.
The i/p resistance to ADC pin is very high so should not affect the voltage across divider.
Have you confirmed the voltage is as expected across 1K0 Resistor?

Martin

Edit: I will try it myself today just to see if theory is correct.
Will post findings.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Visual LEDs for LiPO battery

Post by medelec35 »

Hi Martinus,
I have tried with 4k7 and 1k0 resistors and all is working this end.
I thought it would be better to use preferred resistors and adjust flowchart if more precision is required. If no adjustments are made to flowchart, then LED changes from flashing green to both flashing when i/p falls to 12.39V = Value of 49
Both LED’s are flashing when i/p falls to 7.45V = Value of 29
If this is not suitable and you still wish to use this method, then if you post what LEDs you want at what i/p voltage (e.g just Red flashing at 10V etc) then I can adjust Flowchart to suit.

Don't forget that 50% of 5V = 2.5V = 2.5V difference.
But 50% of 25V is 12.5V = 12.5V difference.

That's why it may be better to state Battery i/p voltage rather than MCU voltage.

Martin
Martin

yellowfish
Posts: 7
Joined: Thu Mar 22, 2012 9:53 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Visual LEDs for LiPO battery

Post by yellowfish »

Hi Martin, great apologies :!: . My comment " Played around with this and could not make it work' was not referring to your potential divider circuit. Meant I was trying the op-amp route replying to Steve, and that not working. Your circuit so far perfect. Tried on bread board and all fine so far. Changed target chip to 12F675 now since I do not have real estate on the pcb I want to use.

I just love this forum with chaps happy to jump in and help.

Cheers

Martinus

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Visual LEDs for LiPO battery

Post by medelec35 »

yellowfish wrote:Hi Martin, great apologies :!: . My comment " Played around with this and could not make it work' was not referring to your potential divider circuit. Meant I was trying the op-amp route replying to Steve, and that not working.
Ah, I'm sorry too for jumping to wrong conclusion.

Martin
Martin

yellowfish
Posts: 7
Joined: Thu Mar 22, 2012 9:53 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Visual LEDs for LiPO battery

Post by yellowfish »

Hi Martin
Just to make sure. The V for one cell when fully charged is 4.2V. @ 3 volt per cell(18 volt total for 6 cell) the cell gets damaged and can explode. In a 6 cell LiPo pack(series connected) the total v will be 25.2 fully charged. The minimum recommended voltage that each cell should be drained to is 3.8V. In the 6 cell pack this gives 22.8 volt (30% red led flashing only). That gives us a 2.4 volt drop to work with, 10% of total pack voltage. When pack voltage drops 1.2 volt that should theoretically be 50% capacity left. When pack voltage drops 2.4 volt we are on 30% capacity. on 18 v possible fireworks :lol:

Will the potential divider give this? How will this change the calc in flowcode?

Does this make sense?

Martinus

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Visual LEDs for LiPO battery

Post by medelec35 »

Yes it does make sense.

There are two ways I could think of.
1) is use aswitch DPDT switch on your circuit. So one side of sw connects the two resistors in parallel, while the other side of sw is used to let microcontroller know that the lower voltage power pack is used.
That way the flowchart can be reconfigured to not compare Voltage when power 1st connected, but can continuously monitor the power pack voltage.
My logic for this is two fold. A) What if you want to turn helicopter off, then back on before the battery pack is discharged. The 1st sample voltage could then be lower than it should be. B) if sample is taken before motor is running at full speed then there is a much heaver intimal demand on the battery, which could mean the sample taken is lower than normal, therefore batteries could be allowed to discharge too much before RED LED flashes.
A round this is place a few seconds delay (to allow motor to run at full speed) unless the motor only runs when activated by remote, then would not be an issue.

2) If there was not Potential divider then since fully charged battery is 25.2V and discharged battery is 22.8, then Flashing red needs to be set at 100 - ((25.2 - 22.8 )/25.2 * 100) = 91% (rounding up 90.48)
Not the 30%
Think I have got the maths correct?

Using the ratio of potential divider:
If Batt = 25.2V then i/p to ADC is 1/5.7*25.2 = 4.42V
If Batt = 22.8V then i/p to ADC is 1/5.7*22.8 = 4.0V
A difference of 420mV
But the percentage would work out the same at 90.5

Since there will be rounding errors (pic maths with integers)
It will be best to use ICD or send data to LCD or RS232 so that Value variable displayed for the whole range of 25.5V down to 22.8.

If this method don't work as well as expected then best to consider option 1 but you could ReadAsInt or ReadAsVoltage instead.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: Visual LEDs for LiPO battery

Post by Steve001 »

looks like martin sorted you out and your on your on your way.

i don't want to confuse you . if you still want the circuit let me know

steve
Success always occurs in private and failure in full view.

Post Reply