LiPo charger and monitor in a single IC

edmunds

Senior Member
Dear all,

Have been off picaxe for a while, now back with some new challenges.

I'm looking for better monitoring of the remaining juice in 1s LiPo battery in my model car. I failed somewhat with stabilising calibdac10 readings, got stuck with 2.8V LDO regulator between the monitoring subject and picaxe and before I re-address this, I was wandering if there is a totally different route to go.

As I have my wireless charging components (two coils, two ICs and some caps and stuff) arriving any day now, I'm looking at LiPo chargers. MAX1555 will do for testing, but I was thinking maybe there is an IC that would combine a "fuel gauge" system like this: http://datasheets.maximintegrated.com/en/ds/MAX17043-MAX17044.pdf and a charger. Preferably with I2C interface as I am using it already for other purposes and this would then not take up any more picaxe pins.

I have asked our aunt Google for an hour now and she has not torn up anything. There is a small hope, I'm not using the right keywords and some hope people here can help with that :).

As almost always with me - I love those 1x2mm 8-pin packages. If not, maybe there is a 3x3mm 16-pin QFN or something :).

Best regards,

Edmunds
 

srnet

Senior Member
Dont know about a combined device.

But I cant see how how just measuring the cell voltage can tell you how much 'remaining juice' juice there is.

Is this possible ?
 

eggdweather

Senior Member
Most definitely yes, in the modelling world where LiPo are huge sellers and the usage evidence is huge worldwide, nearly every device be it charger or monitor uses voltage as an indicator to cell capacity. It's not 100% accurate, but nearly every application it is more than adequate. Generally cell voltage relates to capacity according to this:
Resting voltage vs. Capacity

4.20v = 100%
4.03v = 76%
3.86v = 52%
3.83v = 42%
3.79v = 30%
3.70v = 11%
3.6v = 0%

Some chargers monitor mA-Hr return rates, but these are few and far between and the vast majority use overall cell voltage stopping charging and slowing down charge rate as the cell voltages approach 4.2volts.

I am puzzled why the calibdac is not working in this example, because I have successfully used it to monitor the picaxe supply voltage and it returns good accuracy. So a picaxe supplied by a 1S battery should easily be able to monitor its supply/cell voltage and then under programme control provide control or monitoring information. The formulae I used was Vsupply= 1023*60/returned_calibdac_value and for a 5volt supply calibdac returned a value of 12035 yielding 5volts and using the remainder I could add another 0.1volt resolution to the result.

I'm not sure if this device provides monitoring information: http://www.ebay.co.uk/itm/5V-Mini-USB-1A-Lithium-Battery-Charging-Board-Lipo-Charger-Module-for-Arduino-/310877533550?pt=LH_DefaultDomain_3&hash=item4861beb56e

TP4056 is the device, see here: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Prototyping/TP4056.pdf
 

AllyCat

Senior Member
Hi,

I failed somewhat with stabilising calibdac10 readings, got stuck with 2.8V LDO regulator between the monitoring subject
I am puzzled why the calibdac is not working in this example, because I have successfully used it to monitor the picaxe supply voltage and it returns good accuracy. ......The formulae I used was Vsupply= 1023*60/returned_calibdac_value and for a 5volt supply calibdac returned a value of 12035 yielding 5volts and using the remainder I could add another 0.1volt resolution to the result.
Do you (both) really mean CALIBDAC, or CALIBADC ? Also, I can't see how a CAL...10 (10 bit value) can return 12035 , or how/why you used CALIBADC10 with a 2.8v LDO regulator. :confused:

Using CALIBADC can be quite challenging because of PICAXE's limited Integer-Word Division accuracy, which at best is around 0.4%. Perhaps you need to post your exact code and/or your schematic hardware design. I've posted a method for measuring the PICaxe supply rail to 10 mV resolution in the code snippets section. I've also devised a method which can give 1 mV resolution (still with absolutely no external hardware), but not posted it, because it's difficult to explain/justify how it works. ;)

Cheers, Alan.
 

srnet

Senior Member
Well, measuring at 'rest' means your mesuring the voltage at a known current as well.

I do use LiPos in my model planes, and its really quite difficult to measure remaining capacity, since what you really want to know is how much capacity you have left when the motor is running, and that is next to impossible.

However, if resting voltage is OK, then a simple voltage measurement will do.

The device pointed to was quite differernt, designed for Lithium Ion, and it purpose was to characterise the useage of a battery over time, and measure how the voltage fell and come to a conclusion or estimation as to how much was left.

Some chargers monitor mA-Hr return rates, but these are few and far between and the vast majority use overall cell voltage stopping charging and slowing down charge rate as the cell voltages approach 4.2volts.
Plenty of chargers will measure mAHr in, but these are normally standalone bench chargers.

All LiPo chargers should be constant current charging to 4.2V, then constant voltage charging at 4.2V untill the charge current drops to zero.
 
Last edited:

Jeremy Harris

Senior Member
I did a fair bit on this years ago, when I wanted a "fuel gauge" to show remaining capacity in a lithium battery pack.

Measuring voltage alone is completely meaningless. The cell voltage varies with load, with time since the load was removed, with time since the cell came off charge, with temperature, you name it. I used a combination of regularly sampling the voltage and current and subtracting the Ah used against a preset (at charge) Ah capacity. It's worked well for years, and others have built the circuit and found it equally useful. The original version used an 08M2 and had an analogue voltage output using PWM to drive a "fuel gauge" type display (see here: http://www.endless-sphere.com/forums/viewtopic.php?f=2&t=22675&sid=811197e758db6b30c03093423174a83c), the current version uses the spare pins on the AXE 133Y and is written up on this forum, here: http://www.picaxeforum.co.uk/showthread.php?22014-Squeezing-functionality-out-of-an-OLED-display .
 

hippy

Technical Support
Staff member
I am puzzled why the calibdac is not working in this example... The formulae I used was Vsupply= 1023*60/returned_calibdac_value and for a 5volt supply calibdac returned a value of 12035 yielding 5volts and using the remainder I could add another 0.1volt resolution to the result.
It would be worth posting details of your hardware and the full code for determining voltages so others can understand exactly what you are doing and how. That may help determine what may be going wrong.
 

edmunds

Senior Member
It would be worth posting details of your hardware and the full code for determining voltages so others can understand exactly what you are doing and how. That may help determine what may be going wrong.

I have several pieces of code by now, but as described in some earlier post, this did not give a stable reading with entirely adequate decoupling and filtering for all other means. Even when I average the readings out by taking the average of 6 (six exactly for other timing reasons), I still got rubbish every now and then. And yes, I mean calibadc10, not calibdac. The following code snippet is the bit that shows alternating readings of 2.7 or 2.8 volts now after the regulator, but was not happy at all, when it was connected to the battery directly (the line commented out). While most readings were alternating a tenth of a volt, an odd reading would show 3.2, 2.4, 1.9 or some other crazy value. I tested this with 4 different batteries just to make sure and a plethora of capacitor and resistor combinations intended as filters and eventually gave up.

Code:
  LiPoVolts = 0                                                               'Restart before each measurement
  LiPoVoltsAgr = 0                                                          'Restart before each measurement
  
  for Counter = 0 to 5                                                    'Take six measurements of battery voltage
    calibadc10 LiPoVolts                                                  'Read Vs as compared to internal 1.024V reference
    LiPoVoltsAgr = LiPoVoltsAgr + LiPoVolts                     'Agregate for average later
  next Counter
  LiPoVolts = LiPoVoltsAgr / Counter                             'Put the average calibdac10 value into LiPoVolts variable
'  LiPoVolts = 52378 / LiPoVolts * 20                             'Turn the number into milivolts (or something), kind of worked with direct LiPo supply
  LiPoVolts = 10476 / LiPoVolts                                     'Volts times 10 @ 2.8V supply
;  bintoascii LiPoVolts,Hundreds,Tenths,Units             'Decode volts into displayable values
The reason I mention the 2.8V regulator, is because I need to re-do the hardware anyway now to measure anything else than 2.8V - I need to connect picaxe adc pin directly to the battery with a voltage divider (as the picaxe is now running @ 2.8V and direct battery voltage would be significantly above rail) and maybe some capacitors again. This sounds like extra components and I don't like that, so I'm looking if there is a more advanced, integrated way to achieve the same - like a solution integrated in a charger ic. This would still be extra components, but most or even all would be components I need to have anyway.

As explained above by other people, it seems to be somewhat trickier business than it sounds. For starters, you do need stable accuracy at 100th of a volt to actually determine the remaining capacity of a cell. This sort of stability of an analog reading is a bit difficult to imagine if you are running anything more than a few LEDs and, say, a temperature sensor. I have a DC motor, I2C distance sensor, IR receivers, serially controlled sound module and 20+ LEDs, albeit the low current type (~2mA each). Then, even if you figure out the voltage, what do you do with it? I assume it will drop quite a lot faster and lower when the model car is climbing a grade at full torque than if it is just sitting and waiting for the next IR command at a parking lot. A false-negative reading will cause a lot of problems as once a car gets set for a "battery low vehicle", it won't go out of that state unless it arrives at a charging station and successfully completes a re-charging cycle. So while I need to preserve my batteries and thus charge them often a little rather than deplete and charge a lot, I also need cars on the roads, not in the charging stations. There should be no errors unless the battery is really bad or something.

Probably all are challenges possible to tackle, but solutions "already built for this" would take me forward quite a bit faster. Maybe :).

Edmunds
 

hippy

Technical Support
Staff member
LiPoVolts = 52378 / LiPoVolts * 20

There does not seem to be anything wrong with that maths so seems there is some other issue involved. I would guess the readings are not consistent causing the average to vary more than one would like than in display of the value elsewhere. Why they would be inconsistent with a LiPo rather than any other supply I do not know.
 

AllyCat

Senior Member
Hi edmunds,

Personally, I can't see why you would use CALIBADC if you "know" that the PICaxe supply rail is 2.8 volts (since the regulator voltage is probably more accurate than the PICaxe's FVR). Of course you can use READADC, but as you surmise the input pin voltage cannot exceed the Reference Voltage, and/or the Vdd, so you would need an external (Potential) Divider resistor chain to monitor a higher battery voltage. This can be done with higher accuracy than CALIBADC, because only multiplication (and not the less accurate division) is required.

If you're getting inconsistent ADC measuremenets, that suggests either the "measured" value or the "Reference" voltage is changing (e.g. due to inadequate low-pass filtering of either signal). Are you by any chance using PWM drive, in particular for Low Frequency motor drive? With PWM drive, quite high pulses of current can flow, thus causing large (or apparent) transient voltage drops during the "on" time. Many novices are unable to identify where these currents might flow, or what might be their effect.

Also, it's often overlooked that PWM (for motors, or any inductive load such as a Power Supply) is an "Energy Recovery" system, which can cause the "Load" to feed power back into the "Supply" rail. Generally a semiconductor Regulator can only "switch off" (if their output voltage gets too high), so if the load attempts to push current into the supply rail then the Vdd may rise. Thus it's sometimes necessay to use much larger-valued decoupling (or filtering) capacitors than might be expected.

Therefore, it can be important to document the exact and complete hardware and software topology to diagnose problems.

Cheers, Alan.
 

hippy

Technical Support
Staff member
Personally, I can't see why you would use CALIBADC if you "know" that the PICaxe supply rail is 2.8 volts
That confused me at first. If I have figured it out correctly; this is simply the set-up edmunds has which got things working, powering the PICAXE through the LDO because powering the PICAXE directly from the LiPo wasn't behaving as expected.
 

edmunds

Senior Member
Hi edmunds,

Personally, I can't see why you would use CALIBADC if you "know" that the PICaxe supply rail is 2.8 volts (since the regulator voltage is probably more accurate than the PICaxe's FVR). Of course you can use READADC, but as you surmise the input pin voltage cannot exceed the Reference Voltage, and/or the Vdd, so you would need an external (Potential) Divider resistor chain to monitor a higher battery voltage. This can be done with higher accuracy than CALIBADC, because only multiplication (and not the less accurate division) is required.

If you're getting inconsistent ADC measuremenets, that suggests either the "measured" value or the "Reference" voltage is changing (e.g. due to inadequate low-pass filtering of either signal). Are you by any chance using PWM drive, in particular for Low Frequency motor drive? With PWM drive, quite high pulses of current can flow, thus causing large (or apparent) transient voltage drops during the "on" time. Many novices are unable to identify where these currents might flow, or what might be their effect.

Also, it's often overlooked that PWM (for motors, or any inductive load such as a Power Supply) is an "Energy Recovery" system, which can cause the "Load" to feed power back into the "Supply" rail. Generally a semiconductor Regulator can only "switch off" (if their output voltage gets too high), so if the load attempts to push current into the supply rail then the Vdd may rise. Thus it's sometimes necessay to use much larger-valued decoupling (or filtering) capacitors than might be expected.

Therefore, it can be important to document the exact and complete hardware and software topology to diagnose problems.

Cheers, Alan.
Alan,

Thank you for your insightful reply. I should try to reference to the "known" 2.8V one day. PWM is in use and likely it is in the low frequency range you are talking about. I'm not doubting this can cause problems, although I have tried various ways of eliminating them, but without much success. You will find the schematics, the board layout and the software attached below, but I do not expect you or anybody else on the forum to go through all of that and solve my problems for me. I'm posting it just because there seems to be a strong opinion I should :).

ICD_v_3.0_sch.pngICD_v_3.0_brd.png

The code makes the post 39000 characters long with only 10000 allowed. Don't know how to post that.

Thank you for your time,

Edmunds
 

edmunds

Senior Member
That confused me at first. If I have figured it out correctly; this is simply the set-up edmunds has which got things working, powering the PICAXE through the LDO because powering the PICAXE directly from the LiPo wasn't behaving as expected.
Dear hippy,

The last part is not correct. I had to use 2.8V regulator because of VL6180x sensor. Really beautiful device! After you get it working :).

The fact I installed the regulator on my test car, kind of deferred the LiPo monitoring problem, because without re-wiring it, which I did not have time for immediately, the only thing I could monitor was the regulator operation. The problem is not gone and the regulator is not a solution.


Edmunds
 

AllyCat

Senior Member
Hi edmunds,

I do not expect you or anybody else on the forum to go through all of that and solve my problems for me. I'm posting it just because there seems to be a strong opinion I should :)....

The code makes the post 39000 characters long with only 10000 allowed. Don't know how to post that.
I believe that you can "attach" the whole .BAS file rather than pasting within
Code:
 tags.  But I do agree that we're unlikely to want to work through all that code.   ;)  

However, a short list of well-commented SYMBOL statements might be informative (for example documenting all the currents, voltages and switching frequencies that are present on all I/O pins.  Also an "overview" diagram, showing how the main PCB, the Motor(s) and the battery, etc. all connect together might be helpful.


Looking at your circuit diagram, two potential major issues appear to be that the Motor Bridge IC and the PICaxe are connected to the [U]same[/U] supply rail (VDD_28).  Also the supply decoupling capacitors seem [U]much[/U] too small.  IMHO the Motor Bridge Supply rail should be connected via a wire [B]directly[/B] to the +battery terminal, with a [B]separate[/B] wire from the Regulator input (Vdd) directly to the +battery terminal.  Then [U]each[/U] rail should be decoupled by a value at least [U]10 times[/U] and maybe 100 times larger than the value (2.2uF) which you appear to be using.

The philosophy behind this recommendation is of separating "clean" and "dirty" supply rails, somtimes identified as "analogue" and "digital" rails.  The motor bridge rail is likely to be (very) "dirty" with pulses of 100s of mA (thus perhaps 100s of mV ripple), whilst the PICaxe Vdd needs to be kept "clean", particularly if it's being used as a voltage reference, or for any other analogue function.  Using separate wires right back to the battery not only reduces any common impedances, but their inductance and resistance can form a low-pass filter with the supply decoupling capacitors (typically 100 nF ceramic or "foil" + 100 uF Electrolytic in parallel are a good starting point).  Sometimes it's also benefiicial to identify separate clean (analogue) and dirty (digital/power) [U]Earth[/U] rails, using either a "Star point" (perhaps the -battery terminal) or a "Ground Plane" PCB layer.   

Cheers,  Alan.
 

eggdweather

Senior Member
I don't know what motor size or ESC your using, but I would assume LiPo voltage is a constant (which it is to all-intents-and-purposes) and use one of these: http://www.ebay.co.uk/itm/High-Quality-1Pc-30A-Range-ACS712-Current-Sensor-Chips-Module-for-Arduino-/131386066854?pt=LH_DefaultDomain_3&hash=item1e973847a6
to monitor mA-Hr consumed which gives you a good indication of remaining battery charge. The units (there are many types on the market) give a voltage proportional to current flow, so monitor with a PICAXE ADC command and add some time and you have mA-Hr.
 

edmunds

Senior Member
Hi edmunds,

I believe that you can "attach" the whole .BAS file rather than pasting within
Code:
 tags.  But I do agree that we're unlikely to want to work through all that code.   ;)  

Tried that, it does not seem to work. At least not on my Mac OS X 10.10.3 machine and Safari.

[/QUOTE]

[QUOTE="AllyCat, post: 284557"]Hi edmunds,

Looking at your circuit diagram, two potential major issues appear to be that the Motor Bridge IC and the PICaxe are connected to the same supply rail (VDD_28).

[/QUOTE]

[B]This is excellent advice and thank you so much.[/B] I have heard the terms and probably have read about this somewhere as well, but without practical application and necessity at the time ... you know how this happens :). Now, I will look into this when I'm done with my current "urgent" project to see if this helps and if it will, will look into re-designing the pcb. The reason why I opted not to include a ground plane was there was so little of it anyway. Now when I think about it, I could have carefully gone through my DRC settings in eagle and adjusted them in the same way I adjusted them to allow me to work with 0.15mm traces and distances between adjacent traces. Probably, this would result in a meaningful ground plane.

Upgrading the capacitors seem to be a potential problem. Decoupling is actually 0.1uF in the original circuit. The 2.8V LDO regulator requires 2.2uF on input and output. Maybe this becomes the new decoupling, but I'm not sure. There is also a 0.1uF capacitor at motor terminals, which I forgot to mention and it is not included in the schematics. The PCB I attached has not yet been produced - at the moment the regulator part is "hanging in wires". 10 or 100 times 2.2uF is not available in the dimensions anywhere close what I can afford. 0603 format is max I have used so far, but I can probably push it to 0805. Anything above that is an elephant and needs to be moved outside this PCB, which I would like to avoid for the "final" version. So some thinking to do.

Thank you for your time,

Edmunds
 

edmunds

Senior Member
I don't know what motor size or ESC your using, but I would assume LiPo voltage is a constant (which it is to all-intents-and-purposes) and use one of these: http://www.ebay.co.uk/itm/High-Quality-1Pc-30A-Range-ACS712-Current-Sensor-Chips-Module-for-Arduino-/131386066854?pt=LH_DefaultDomain_3&hash=item1e973847a6
to monitor mA-Hr consumed which gives you a good indication of remaining battery charge. The units (there are many types on the market) give a voltage proportional to current flow, so monitor with a PICAXE ADC command and add some time and you have mA-Hr.
Thank you for the link! This is an elephant in the sense of the project discussed here, probably twice the size of my whole PCB, but might come very handy in the MINNIE MAMBO scratch built foamy I'm finishing the build of. It already got picaxed, btw, since my daughter wanted take-off and landing lights added (two super-bright red LEDs). So adding something like this and making the landing lights flash differently when the battery is running out would be a fun project.


Thank you for your input,

Edmunds
 

premelec

Senior Member
@Edmunds - note that the ACS712 units are also available in other current ranges down to 5 amps...
 

edmunds

Senior Member
@Edmunds - note that the ACS712 units are also available in other current ranges down to 5 amps...
Yes, I'm not interested in the "module" as such, but this gave me a direction for an IC to look for. Has happened quite a lot actually with those eBay thingies :).

Edmunds
 
Top