# Designing a Battery Charger With a PIC

I've designed the following circuit for a battery charger. With the PIC just turning the output on and off when it is charged. For the program design what would be better, to have the analogue input constantly checked? Or to have the output on for the charge time then to move to the second?

• Sorry the picture hasn't uploaded. Will do it when I get back.
– Dean
May 3, 2011 at 12:52
• What type of battery is it? May 3, 2011 at 13:29
• NiMH battery. But the question is on how the operation of the PIC should be.
– Dean
May 3, 2011 at 16:56

your schematic contains more then one mistake. Any pin of the µC can only handle 5V. Going above 5V without limiting the input current will damage the µC. IN your circuit, this can happen when the battery fails open circuit or when the battery is removed. You should add a series resistor with the input and a capacitor to ground on the ADC pin. The resistor can be 100K and the capacitor 100nF. You will also need a diode connected between the ADC input pin and the 5V power supply and a 'dummy load' across the 5V supply. This will prevent the µC from powering itself from the battery trough the diode between the ADC input and the supply pin of the µC. 10K will do. (And that's the reason I've chosen the 100K resistor between the battery and the ADC input. The 100nF capacitor will correct the input impedance seen by the input of the ADC. (The ADC uses a sample and hold. Now the sample and hold capacitor can charge itself by stealing some charge from the 100nF capacitor and it also makes the input less sensitive to noise.)

Secondly, the drop-out voltage of the LM317 is to high if you want to charge 4 series connected cell's. The battery voltage will reach 6.2V and an LM317 needs 3V to operate (min. voltage between in and output). And then you also have the 1.25V drop across R1. That's 9V - 4.25V= 4.75V.

Oh, and while I write this it occurs to me that disconnecting the power supply while the battery is still connected will damage the LM317. You will need a diode between the battery and the LM317. That's an other 0.5V if you use a Schottky diode.

You might be better of using a PNP transistor and an op-amp to construct a low drop current source.

And there sure are more elegant ways to disable the current source. Over driving the ADJ pin can save you a power-mosfet. (It takes two small resistors and an NPN transistor with the appropriate biasing resistors.)

Regards

• And I forgot: you will have to divide the battery voltage so it will not overdrive the ADC. Jun 1, 2011 at 0:22
• Possible to add any circuit diagrams of how you mean? If you can add some then you have a great answer and I will change the accepted answer. I don't understand how you recommend to turn off the current source.
– Dean
Jun 1, 2011 at 11:04
• Sure I can post a schematic. I'll send you a revised schematic that will work. Besides, how do you want to terminate the charging cycle? Zero slope detection? Jun 1, 2011 at 22:59
• I was just going to turn the current source off when the voltage reached its maximum.
– Dean
Jun 1, 2011 at 23:10
• this method will not work for NiMh batteries because you can not tell where you are in the charging cycle by measuring battery voltage alone. Do you mind telling us for what purpose you're designing this charger? There might be better solutions (or very difficult solutions if any.) available. However, it all depends on your programming skills. Jun 2, 2011 at 0:02

Depending on the chemistry of the battery you'll want to be very careful about overcharging. Here is a page describing attributes of various batteries: http://www.batteryspace.com/batteryknowledge.aspx

Down near the bottom is the overcharging tolerance information. You have to be very careful with... well, everything except lead-acid batteries. Deciding when to stop charging or how to moderate the charging rate is very important in battery chargers. This page describes designing a PIC-based a NiCd/NiMH charger and discusses the important aspects of the charging method. Quickly though:

• There are a variety of methods to charge: quick, slow, trickle, etc. Different strategies are required for each. Obviously faster charging methods get it charged faster but might cause excess heat, your battery to explode, etc.
• Overheating is bad - you ideally would monitor it if you were attempting to do a very quick charge.
• Overcharging is bad - you have to monitor the NiCd/NiMH voltage and watch for a slight (very slight) drop in voltage that tells you when it's done, or monitor change in temperature over change in voltage and cut off charging when it reaches a specific value.
• Desired charged voltage varies depending on the number of cells in the battery, the chemistry, etc.

There's a lot to keep track of and bad things can happen if you try to charge the battery the wrong way. In general your schematic is good but it's the internals of the PIC that are going to be the important part here. Good luck.

Edit: Followup question: is that really a 5V NiMH battery? If so, that's nominally 1.25V/cell and four cells = 5V. Okay, good deal, but you'll want to charge the cells up to about 1.4-1.6V. With four cells, that turns out to roughly 6V. You can't measure 6V with the A/D of the PIC and it may be dangerous for the PIC to have those voltages on its pins- check the absolute maximum voltage rating of that pin. It's usually VCC + something. In any case, you'll need a voltage divider to read the full range of the battery so you know when it's done charging.

Bottom line: that circuit won't work unless I'm mistaken. And I have been known to be. Anyone confirm?

• Many manufacturers of cheap chargers don't seem to bother with any of this - resulting in the premature death of expensive rechargeable cells. Of course they also make the cells. Pure coincidence I'm sure :o{ May 3, 2011 at 13:31
• Yeah I was unsure about that as well will half the voltage to 3 to make it safe then.
– Dean
May 3, 2011 at 21:33
• NiMH can show multiple /$-dV/dT/$ events before completing a charge. There are other methods for detecting a full charge. I cannot remember what they are anymore though. Jun 1, 2011 at 15:27