Since I am now the father of 4 lovely robots (MARKIII) , that each take 4 AA batteries. I got tired of changing batteries. I wanted a way to charge the batteries without having to take them out of the robot. So I built a custom charger with a spare PIC18F2320.
Here is the most important piece of the design:
In this circuit, I have a PNP acting as an ideal current source. As long as the PNP s active the base current will determine the collector current regardless of the voltage at the collector. Of course the voltage at the collector needs to stay at least below 6V – 0.7V for the PNP to remain active.
The neat thing about this circuit is that you could supply any voltage to the emitter (same one that goes to the PIC) and you could charge any battery.
The idea is to use a GPIO to toggle the base current ON and OFF thus turning on and off charging. When no battery is present R4-collector will be at max voltage due to the GPIO being pulled high. As soon as the ADC voltage drops, you know that a battery was inserted and you can lower the GPIO to begin charging.
While charging you monitor delta V with the ADC and turn off charging at the appropriate moment. R3 will bias the LED current when charging, and let you know that you are charging. R2 is used to control the amount of base current and thus regulating the fixed collector current that is supplied to the battery.
Here is a picture of them nursing:
Here is a link to the code .