Voltage inputs to PIC when PIC is unpowered - Page 1
Forum section: electronics / projects

author: carveone
author_rank: Contributor
timestamp: March 08, 2015, 05:19:28 pm
content: I'm sorry about this - I'm sure this question has been done to death. Just with a slight twist on the power supplies!I'm using a battery charger chip (MCP73831) to charge a 3.7V Li-Ion battery in circuit with a PIC micro. It's a low power circuit. I want the PIC to detect when the +5V is plugged in. The "obvious" way is to take the 5V via a resistor to a PIC input (er, not MCLR...) and let the input protection diodes clamp.There's two issues there - first if the battery has dropped below its UVLO level, the PIC may be unpowered. The obvious way above tries to power the PIC via the protection diodes which doesn't seem like a good idea. The other issue is that, resistor depending, the 5V may try to "top up" the battery with a small current. If you used 10k there would be (5 - 4.2) / 10 = 0.08mA flowing into the Vbat line. I'm not sure if that's a problem really...This is my quick solution (attached).I don't believe there's an issue if Vbat is zero here. That would not be the case if Q1 was an NPN transisor as the B-C junction would conduct just as well as the B-E junction does! There's no way I can see that +5V can get to Vbat. Does this sound reasonable?Thanks, Conor.

author: AndyC_772
author_rank: Super Contributor
timestamp: March 08, 2015, 07:17:28 pm
content: Power the PIC with a pair of OR-ing diodes, one from +5V and the other from the battery, so it's always powered if either rail is present.Then, use the PIC's ADC to measure its built-in voltage reference, using the power supply as the positive reference for the ADC.Once you know what the (known) voltage reference measures, you can calculate what the upper reference, and therefore the PIC's supply voltage, must be.If it measures more than, say, 4.5V, then the 5V supply must be present.

author: richard.cs
author_rank: Super Contributor
timestamp: March 08, 2015, 08:03:31 pm
content: Your circuit will work but I don't really think it's necessary. Check the PIC datasheet for the input impedance and make the series resistor big enough not to care about the leakage current. I would think you can go to at least 100k and the battery won't care about 8uA.

author: carveone
author_rank: Contributor
timestamp: March 09, 2015, 01:16:45 pm
content: Quote from: richard.cs on March 08, 2015, 08:03:31 pmThe typical input leakage current for the PIC16F1829 is 5nA! Pretty close to 0 really. That's the thing - it's hard for me to know how much current is required to get the PIC to (try to) start up.I absolutely get your point though - one resistor is a much simpler solution. However, if you didn't know the input voltage - say it could be up to +12V or is supplied by an end user - then perhaps more care would be prudent. I had one case where a cheap optoisolator was the most prudent as the input had the possibility of being exposed to, well, anything! Static for example

author: MrAl
author_rank: Super Contributor
timestamp: March 10, 2015, 02:03:07 am
content: Hi,If i understand your problem correctly then it looks like you are worried about powering say a single pin of the PIC chip when there is no power to the PIC power supply pin, yet there is still a ground connection to the PIC ground pin.Your idea of 10k in series with the pin isnt bad, but you might throw off the 1/2 bit precision of the ADC. In order to meet the 1/2 bit precision over the full temperature range (assuming you really need that) you have to use a resistor value that does not drop more than 1/2 bit at the maximum DC leakage current for that pin. For some chips the max DC leakage is 1ua, and with a 5v ADC reference this would mean the max series resistance (total) would be 2441 ohms. So 10k would mean about 4 times that, or a 2 count possible inaccuracy. This is over the full temperature range which you may not need anyway though.There are a couple other catches here too though. One is that if using the internal clamp diodes, you have to make sure that the pin being used actually has a clamp diode. Some do not have them, although i think it is rare. The other is that the chip and circuit must draw enough current to stop the chip from starting up with too low of an operating voltage due to the diode clamp current. This simply means if you use 2.4k instead of 10k then the chip and circuit always have to look like say a 240 ohm resistance (that would mean about 1/10th of the voltage appears at the Vcc pin). A solution would be to use a 240 ohm resistor across the Vcc to ground pins of the PIC chip, if you need that. If you go with the 10k, then 1k would be fine, unless the chip and circuit draws enough current even when the Vcc voltage is low like 1v (not at the full 5v which it probably always does).Another small catch is the max current of the diodes, which is higher than you'll probably encounter.

author: PeterFW
author_rank: Frequent Contributor
timestamp: March 10, 2015, 02:47:59 am
content: Quote from: AndyC_772 on March 08, 2015, 07:17:28 pmYes and noYes to the method of measuring, no to the diodes. Well... one of the diodes.If you measure as Andy said you do not need anny additional circuit.The supplyvoltage of the PIC should never be above 4.3 Volts, with the supply connected you have above 4.3V.But i suggest this circuit, the FET instead of the Diode will have much lower voltage drop. Running the battery through a diode wastes a lot of powerAnd you should read this App Note from Microchip, you should disconnect the battery from the load when charging. The above circuit will do that and enable you do sense a charger connection.http://ww1.microchip.com/downloads/en/AppNotes/01149c.pdf

author: AndyC_772
author_rank: Super Contributor
timestamp: March 10, 2015, 07:53:59 am
content: Last time I used this technique, I used a pair of Schottky diodes to minimise the voltage drop, and a PIC12F device.'F' parts contain a voltage regulator and are perfectly happy with 5V supplies. It's only the 'LF' parts which are low voltage.The PIC itself draws so little power that the forward voltage drop across the diodes is very small. It's specified down to 2.3V, so add the diode drop and you have, say, 2.7V at worst. That's still well above the minimum voltage across a 3.7V lithium battery.