I have a circuit which has a 3.7V LiPo Battery with its positive terminal tied to a power switch which is connected to the sparkfun 5V boost converter (http://www.sparkfun.com/products/10255) and the negative terminal tied to ground of the system. On the the positive terminal of the battery, it is also directly connected to an analog pin of the atmega328 microcontroller (running off the 5V from the regulator) to measure battery voltage. My issue is even with the power switch off, I'm getting 3.2V on the 5V rail of the system. I believe the issue is related to having the battery tied directly to the analog pin, but don't really understand why or how to fix the issue. Unfortunately I'm under NDA for this school project so I can't post a schematic. Any assistance would be appreciated.
There are protection diodes from each I/O pin to the +5V rail intended to divert ESD transients. Your battery is forward-biasing this diode to about 0.5V and actually supplying current to the +5V rail so you are seeing 3.2V. Generally not good for the diode. I'd suggest adding a 1k series resistor to limit how much current could ever go through this diode. You could even go to 10k but then your measurements will start to become less and less accurate (though it may not matter if you just want an estimate of battery voltage).
-- The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected
You better add up serial resistor as suggested above, and also connect this resistor after the switch - to prevent you battery from over-discharging.
So just to make sure I understand correctly. I should put at least a 1K resistor between the I/O pin used to read the battery voltage and the battery to prevent the protection diode from getting forward-biased when the system is off. I just want to make sure because its a custom PCB and I'm going to have to cut the trace to add the resistor.
As another solution, could I just reroute the analog I/O trace to the opposite side of the power switch so that it only gets the battery voltage when the system it turned on?
Yes, do both, and make it perhaps more, 4k7 or 10k. Analog inputs are happy with upto 10k impedance signal (get less accurate as you rise to higher impedances)
You have already possibly damaged the protection diode or nearby stuff on the chip, so don't be surprised if its misbehaving, but you might be lucky.
General rule is never apply low impedance signal to the inputs of a powered-down chip - you can put the chip into latch-up as well which means when the power is applied it overheats and doesn't work till all power is removed. Series resistors on logic inputs will marginally slow down the rise/fall times but will protect the chip from damage and latch-up.
I agree, do both as using just a resistor still allows the li-po cell to discharge (even at low current) the cell below the value where permanent damage can result to the cell. Over discharging and charging are the two easiest ways to destroy a Li-po battery cell.
Thanks for the replies. I'll do both for sure. At least the Li-Po cell I'm using has a protection PCB to prevent it from over discharging, and hopefully I didn't damage the microcontroller with this design flaw...