This page apparently describes a LM317-based charger with auto-shutoff, though it has a few more parts than a resistor.
At the most crude, you can use an LM317 and resistor to form a regulated current source, which is how NiMH/NiCd's should be charged. See "Precision Current Limiter" (p. 19) on the LM317 datasheet. The regulator functions as a current source by attempting to supply as much current as possible to have Vout - Vadj
be 1.25 V.
Note that there is nothing inherent in the LM317 to shut off a charge, so if the batteries are fast-charged (~C/2 or higher), they will fail if you do not terminate the charge at the appropriate time. With a trickle-charge (C/20), you "can" leave them alone with no ill-effect.
So in your specific case, the 2-part charger would be a LM317 and a resistor to charge the pack at C/20.
- Charge rate:
1000 mA·h @ C/20 => 50 mA
- Resistor value:
1.25 V / 50 mA = 25 Ω
You need to provide a voltage to Vin
at least 2.0 V (dropout voltage) + 1.25 V (reference voltage) = 3.25 V greater than the maximum charging voltage. The resistor would be connected between Vout
and Adj
, and your load is connected to Adj
(not Vout)
For a prototype, with careful use, this would still have problems. The LM317 does not tolerate reverse voltages, but you can protect it by putting a diode across it, allowing any reverse current to flow through the diode to the other side (just the capacitor in this case).
In no case should the external power and the USB be connected at the same time.
The USB port should be capable of supplying 500mA at 5V without a problem, so it would appear to meet your needs.
In a production circuit, if you can handle a little droop on USB voltage, use a diode from the USB connection to the circuit's 5V rail. If the USB is connected and no external adaptor is connected, then the USB will supply up to 5V (after the diode's voltage drop). If the external adaptor is connected and not USB, then the external adaptor will supply all the required current at 5V. If both are connected, the external adaptor will be at 5V, while the USB will be lower, thus the diode will protect the computer from possible issues, and the USB won't supply any current.
It's not the best design, but it's quick, simple, cheap, and will save others from damaging their USB ports. There are many ways to handle this problem more elegantly, many using mosfets to switch the best available power into the circuit. But for a simple prototype, this isn't a bad start.
Best Answer
Be careful charging lithium batteries. There are lots of safety issues. You need a way to control the current, terminate charge, and monitor battery temperature to do it properly. If you don't do these things properly there's a real risk of fire or even explosion. Yes, most lithium batteries can charge with a voltage of 4V, but without carefully following the charging recommendations in the battery datasheet you run the risk of getting in trouble. So to answer your question, no, you should not use your LM317 circuit to charge your lithium batteries.