# Power PIC from battery or AC

#### CVMichael

Joined Aug 3, 2007
419
I am building a small device that I need to power it with NiMH batteries, or an AC. When AC is plugged in, I want to charge the batteries in slow charging mode (i.e. 1/10th the ampHr rating of the cell)

The batteries are 8 in series, 2200mAH each, totaling 9.6 Volts.

I also want to monitor the current flow through the batteries, and voltage of the batteries.

I attached the schematic of what I have so far.

Here is the theory of what I wanted to do there: When powered by battery BT1, the relay REL1 sits on closed position on pin 1, and powers the device.
When I plug the AC in the J1 jack, it powers the device through diode D1, and the code on the microcontroller can choose to charge the battery by turning on the pin 2, RH3. Then the REL1 flips to the other side, and charges the battery BT1.
The current is monitored on R5 (1 ohm), amplified by U5 (AD8041, is the only OP-AMP SMD chip I have available right now) going to the AN0 of PIC, and voltage is monitored by R8 & R9 going to AN1 of PIC.
The R10 & R11 goes to AN2 so that the PIC knows when it's powered by AC or battery.

The PB1 push button is the "ON" button. The idea here is that you push the button, flipping the relay to power the PIC, then the PIC turns on RH6 pin to keep itself powered on after you release the push button.

I have a few questions, if anyone can answer any of them?

1) For charging, I need a current of 220mAH to charge the batteries, what resistor do I have to use for "R7" ?

2) To amplify the signal for the current I used an AD8041 (U5), but I don't know what resistors R14 & R15 to have so that for a current of 1 Amp, the voltage at AN0 will be 5V (or somewhere close to that)?

3) I want to use the same button PB1 to turn OFF the device. I am hoping that it will be a difference in voltage at pin 5 on the relay REL2, between when the PIC turns on the transistor Q2, and when I press the push button. If there is a voltage difference then I can detect it using the AN3 analog input, and the PIC can turn off the RH6, and therefore turning off the device once the push button is depressed.
Do you think it will work like that ?

4) I don't really want to have a relay REL2 to power the device on/off. What other options do I have ? maybe a MOSFET? and how can I use a push button to turn it on and also off?

5) Any other suggestions, or problem you see with the schematic?

#### Attachments

• 71.3 KB Views: 23