Go Down

Topic: feeding a lm317 with another to get constant current voltage? (Read 4360 times) previous topic - next topic


For a simple lithium ion charger could I set one lm317 to output 4.2volts, and have that fed with another lm317 constant current source configuration to allow it to draw say 1/3 amp but max out at the 4.2 volts?


With caveats, yes you could.

Caveat: You'd have to take into account the voltage drop through the 2nd (current limiting) LM317, and this is not an absolute constant.

I think it would be much better, and more fun, to do this with with an LM317 and a simple MCU.


What would be the simplest way to use an arduino to control it? I guess I would need a digitpot then? Or an rc filter from pwm to a transitor?


Most digipots would not have the ability to tolerate the current seen in the voltage divider path.  You could look at generating the reference voltage needed using an external op amp (buffer) fed by a PWM pin through an RC filter.  Something I have been meaning to experiment with but have not tried.

My attempt at using a PWM driven LED coupled to an LDR were less than stellar.


Is there any other way to manipulate the adj pin? Or is the voltage divider the only way?


Yes, actually there is.  Give me a day or two to dig up the schematic, but I did a similar project for SLA batteries which have a very similar charge curve to Li-ion batteries.  You will just have t change the voltage levels.  I used a PICAXE, but you could just as easily use an AVR or Arduino.

Also, I am assuming a single cell, right?  If not, there are other considerations.


Yes, single cell
I hve a few of different sizes so it would be cool to control the voltage and current digitally somehow,
also what's the fastest you would usually charge a cell? I have a rather small cell I tried charging at 2C and nothing bad happened, but I was wondering if there's any drawbacks from charging that fast


May 29, 2012, 12:46 pm Last Edit: May 29, 2012, 12:56 pm by BillO Reason: 1
Have a look at the attached schematic.  This is for lead acid batteries, but could be modified for use with litium-ion or LiFePO4 batteries.

This circuit was used as an example of prototyping using modules.  Basically, in the finished product you can just combine the 3 different schematics.  Here is some other information:

  • The 1.7 ohm resistor sets the charge current.

  • The relay switches between current mode and voltage mode.

  • The pot in the regulator module sets the maximum output voltage

  • The transistor on input A shuts the output off with the base high

  • The transistor on input B, along with the 33K resistor set the float voltage
    when the base is high

  • The pot in the voltage divider sets the voltage seen by the MCU and can probably
    be eliminated for a single cell Lithium situation.  It is there to reduce the voltage to
    something the MCU can deal with.

Here is the code to run it.  Written in PICAXE Basic for a PICAXE 20M2, but could easily be ported to Arduino C
Code: [Select]

;  Smart Battery Charger
;  Free Project Series
;  Aztec MCU Prototyping
;  www.aztecmcu.com
;  For use with the Smart Battery Charger schematic
;  This is the code for a Lead Acid type battery charging protocol
;  This code was written for a PICAXE 20M2
;  C.0 is connected to a RED LED
;  C.1 is connected to a GREEN LED
;  C.2 is connected to a BLUE LED
;  C.7 is connected to the Voltage Divider module to detect the voltage on the charger output
;  B.0 is connected to the Relay Module
;  B.1 is connected to input B of the Regulator Module
;  B.2 is connected to input A of the Regulator Module

Gosub Init ; Go initialize the regulator

    readadc10 C.7, w1
if w1 < 100 then gosub NoBat
if w1 > 99 and w1 < 525 then gosub BadBat
if w1 > 524 and w1 < 630 then gosub Charge
if w1 > 629 then gosub NoCharge
Goto Main

;NoBat - It we read under 2 volts, we are going to
;assume there is no battery attached.  Just blink the
low c.0
low c.1
high c.2
     pause 500       ; wait a bit
     low c.2
     pause 500
;BadBat- This is a 12V battery charger so, If the
;battery is between 2 and 10.5 volts, we assume
;it is bad and cannot be charged.  Flash all the
high c.0
high c.1
high c.2
     pause 200       ; wait a bit
     low c.0
     low c.1
     low c.2
     pause 200

;NoCharge - called when the battery does not
;need to be charged.  Just blink the GREEN LED
low c.0
high c.1
low c.2
pause 500
low c.1
pause 500

;Charge - Main charging routine
high c.0 ;Turn on the RED LED
gosub CCC ;Start the constant current charge
readadc10 c.7, w1
if w1 > 100 then gosub CVC ;If the battery is still connected, start the constant voltage charge
low c.0 ;Turn off the RED LED, we are done charging
readadc10 c.7, w1
if w1 > 100 then gosub Float ;If the battery is still connected, start the float
Gosub Init ;We're all done, reinitialize the system.

;CCC - This is the constant current charge mode.  Stay
;in this mode as long as the battery is attached and
;below 14.4V
high c.2 ;Turn on the BLUE LED
high b.0 ;Set the regulator to current mode
low b.2 ;Turn on the regulator
CCC_ChkV: ;Check the battery voltage
readadc10 c.7, w1
if w1 < 720 then goto CCC_ChkV ;If battery less than 14.4V, keep checking
high b.2 ;Turn off the regulator
low c.2 ;Turn off the BLUE LED
low b.0 ;Set the regulator back to voltage mode

;CVC - This is the constant voltage topping charge mode.
;Stay in this mode for a fixed time.  In this case about
;3 hours
high c.1 ;Turn on the GREEN LED
b0=180 ;Set the number of minutes
b1=60 ;Set the number of seconds
b0=b0-1 ;Decrement the minute counter
b1=b1-1 ;Decrement the seconds counter
low b.2 ;Turn on the regulator
pause 1000 ;Wait a second
high b.2 ;Turn off the regulator
readadc10 c.7, w1 ;Test the battery voltage
if w1 > 99 and b1 > 0 then goto LSec ;Go another second if it is still connected
if w1> 99 and b0 > 0 then goto Lmin ; Go another minute if it is still connected
low c.1 ;Turn off the GREEN LED

;Float - This is the float charge mode.  The voltage is reduced
;to the float level (13.4V).  Stay in this mode as long as the
;battery is connected.
high c.1 ;Turn on the GREEN LED
high b.1 ;Set the regulator to float voltage
low b.2 ;Turn on the regulator
pause 1000 ;wait a second
high b.2 ;Turn off the regulator
readadc10 c.7, w1 ;Check the battery voltage
if w1 > 99 then goto Flt_ChkV ;Keep on Float if the battery is still connected


;Init - Initialize the regulator
low C.0 ;RED LED off
low C.1 ;GREEN LED off
low C.2 ;BLUE LED off
low B.0 ;Set the Regulator to Voltage Mode
low B.1 ;Set the Regulator to Charge Voltage
high B.2 ;Set the Regulator to off

Be sure top read this Wikipedia article on Lithium chemistry batteries too: http://en.wikipedia.org/wiki/Lithium-ion_battery

Have fun!


Awesome, thanks
I think ill try this out and see what happens


Li batteries generally require more sophisticated charging regimens than lead-acid
batteries. You might do some background research on charging Li batteries before


I looked it up a bit, and basically you just charge it constant current at 1C until it reaches ~4v then it tapers down a bit to top it off till 4.2v


Li batteries generally require more sophisticated charging regimens than lead-acid
batteries. You might do some background research on charging Li batteries before

Not true for single cells.  They actually have a simpler curve than do lead acid batteries.  They are just not as tolerant to abuse.  Most cheaper lead acid battery chargers actually significantly reduce the life of the batteries we given them to care for.  However, because they will take considerable abuse, it goes unnoticed.  If they are properly treated, lead acid batteries can last 10-15 years, or more.  Lithium cells reward even a little abuse by overheating and bursting, or even causing fire.

The difficulty with Lithium based batteries are at least two fold.  First,  you need to keep strict watch on the minimum and maximum voltages you allow the cell to hold.  Most high power cells these days actually have built in limiter circuits that will cut of the cell if it pushed beyond these limits.  Be careful that you keep within these limits as sometimes the reset process is difficult.  This is more of a problem if a multi-cell pack as the voltages of each cell need to be monitored separately during charge and discharge.  This brings us the the second difficulty.  The internal resistance of Lithium cells can vary considerably, even in the same batch.  So much so that, in order to avoid breaching the voltage limits, you must monitor each cell independently and cut off charge or discharge of the entire pack once an single cell reaches a limiting voltage.

The 2nd difficulty can be mitigated by doing 3 things.  1 - Artificially increasing the internal resistance of the cells by a fixed amount so that the relative differences between cells are minimized.  2 - carefully selecting amongst those cells for near identical characteristics, and 3 - imposing tighter charge-discharge voltage limits.  So, given a cell that has a Vmax of 4.2V and a Vmin of 2.8V, run it in-pack between 3V and 4V such that for a 4 cell pack, cut off discharge at 12V and charge at 16V.  However, because of the increased internal resistance of the cells, this bag of tricks only works in low demand situations, like phones and other small devices.  Even then it's not a 100% satisfactory solution and battery life is much reduced from the ideal.

@ winner10920,

Unless you absolutely need to charge these batteries quickly, I'd recommend 1/4C or less.  Charging or discharging at C or above can cause heating issues which will change Vmax and Vmin and make them difficult to monitor correctly.

As an example, for a 4700mah cell with a Vmax of 4.2V, charge it in constant current mode at 1A until V=4, then switch to constant voltage mode at 4.2V for about an hour or 2 at the most then end the charge.  This method is for when you need to use the cell right away.

If you wish to be able to leave the battery in the charger and keep it at a reasonable state of  charge fore go the constant voltage cycle.  Just charge at 1/4C until V=4 then cut off.  Continue to monitor the cell voltage and when it drops to 3.4 or so, re-charge it back up to 4 again.  For a charger like this, I would add a push-button to signal to the MCU when you want it to fully top up the battery and enter a CC - CV cycle that brings it to the full 4.2V.

One more hint.  For long term storage lithium cells like to be at their 'nominal' voltage.  For most cells this is somewhere around 3.6V.  You could program in a 3rd cycle for pre-storage that begins with a CC cycle to 3.6 volts, then a CV cycle at 3.8V for a couple of hours.  Check voltage in storage occasionally and it they drop below 3.4 or so, give them another pre-storage charge cycle.


That limiting circuit is pretty cool
On that small battery I was talking about I assumed it was dead with like .09 volts, I tried charging it and now its fine, I realized afterward that must have been the limiting ciruit cutting it off,
Another question, is it safe to allow the batttery with such circuit to drain it until it cuts out regularly?  Or should I still have my own disconnecting means when its too low


Try to disconnect it before it gets too low.  Lithiums like to be kept charged.

Go Up