Reading a 9V battery on a PIC is nothing new. The most simple and straightforward way is with a voltage divider. I'd like to keep the divider resistances cranked up into the hundreds of kohms so I'm not killing my battery unnecessarily, however I looked at the datasheet for the PIC18F4550 and the max "recommended" analog input impedance is 2.5kohms. This means I can stick 2 5Ks for my divider, but 900uA is a lot to waste on just checking the battery. What can I do to my design (passively) to minimize battery drain? I've considered active solutions such as a software controlled pfet or a buffer, but board space and budget are a bit of a luxury, so I'll only do it if I have to. I'm also wondering if I'm I being concerned over nothing.

  • \$\begingroup\$ I just find this post during my google search. Just for saying that you have answered my question and given me a lot of help !!! My atempt to read ADC with my PIC18 was blocked because the value read by the MCU allways varie... I put the RC suggested by Alex and all the probleme go out !! Thanks a lot ! PS: Excuse me for my english, I am french. \$\endgroup\$ – Florian Feb 26 '14 at 12:35

The reason the ADC needs a low source impedance is because it has a switched capacitor input. Basically, whenever the ADC 'samples' the voltage on the pin, a small capacitor is connected, charged up, and then disconnected. If the impedance is too large, charging the capacitor up will draw enough current to create a voltage drop large enough to affect the reading.

If you need to read a high speed signal, the best option is to add an amplifier of some sort to provide a low source impedance to the ADC. However, if you are looking at a relatively slow signal there are a couple of other options.

One solution to this is to increase the sample time - the length of time the capacitor is connected to the pin. The chip usually has a limit on how long this time can be, though.

Alternatively, you can add a decent sized capacitor in parallel with the ADC input pin. This will decrease the amount of droop that occurs when the ADC sampling capacitor charges up as most of its charge will be drawn from the capacitor instead of through the resistor.

  • 3
    \$\begingroup\$ Capacitor is the way to go. ADC specifies a source impedance not resistance. Convert its sampling time to a frequency, and use a cap with impedance much lower at that frequency. \$\endgroup\$ – Brian Drummond Dec 6 '13 at 9:48

There are about 4 ways of connecting a voltage divider to an A/D and dealing with max input impedance requirement.

  1. Use small enough resistor. This is what the O.P. is already doing.
  2. Put an OpAmp buffer between the divider and A/D input. OpAmp should have high input impedance and low output impedance. [As already mentioned by Alex.]
  3. Use a larger resistor and add a capacitor from the analog input to ground. [As already mentioned by Alex.] The capacitor should be mush larger than the one in sample and hold. You will be inadvertently making an RC filter, but this still works if the signal is slow. A combination of 10kΩ and 0.1μF worked well for me.
  4. [last but not least] Switch off the voltage divider with a MOSFET switch, and use relatively small resistors. This was you can eliminate the leakage pretty much completely when you are not measuring. This is a common technique for battery measurement.

Replace R1 and R2 with the values you need. The schematic was originally posted in this thread.

  • \$\begingroup\$ Why not just connect the voltage divider to a pin on the PIC? Drive the pin low to sample, set High-Z to disconnect. \$\endgroup\$ – Bitrex Dec 6 '13 at 5:14
  • 2
    \$\begingroup\$ @Bitrex Suppose, you make a low-side switch out of a digital output pin like you're describing. +9V is applied to the top of the voltage divider. When the low-side switch pin is driven low, everything is fine. When you set it to high-Z, +9V will appear on the A/D pin and on the switch pin too. PIC pins are not rated for +9V. \$\endgroup\$ – Nick Alexeev Dec 6 '13 at 5:58
  • \$\begingroup\$ Oops, for some reason I missed the "9V" requirement! \$\endgroup\$ – Bitrex Dec 6 '13 at 6:45
  • \$\begingroup\$ An idea that could work with the above scheme that saves a MOSFET is driving the PNP in the above image directly from the same pin the resistor divider is connected to; drive to 0 to measure, and to Vss to shut off. With appropriate selection of pullup/pulldown resistors for the pfet, this will work so long as the 9 volt battery voltage doesn't drop low enough to forward bias the fet's body diode. \$\endgroup\$ – Bitrex Dec 6 '13 at 6:55

Bitrex's idea would work if the PIC digital pin was configured as "open drain" then clamped to 2.7V with a zener to protect it from the 9V.

To turn it "ON" and "OFF" initialize the pin by writing a logic low to it (and leave it there) then turn the pin "ON" and "OFF" by writing to the TRIS latch which will cause the pin to be either a logic low or high z respectively.

The pin will switch from 0 to 2.7V which should be enough to drive a low gate threshold MOSFET.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.