Electronic – PIC voltage measurement


I am running a battery powered device, and would like my microcontroller (PIC) to report on the supply voltage.

This is so I can determine how many batteries is used in the supply, and also the state of charge of the battery pack.

Supply voltage ranges from 4xD (either 1.2V nominal NiMH or 1.5V Alkalines making about 6V) to 12xAA (1.2V NiMH for 14.4V or 1.5V Alkaline for 18V).

My PIC is running off a regulated 5V supply.

I plan to use one of the ADC ports to measure the voltage, and therefore believe I should map the 18V f.s.d. to the range 0-5V, so roughly I'd need to divide the input voltage by 3.

I've heard of using a resistor voltage divider, but know that it can be wasteful in terms of energy consumed.

Wondering if there is a better way to achieve this voltage division without too much energy loss/wastage?


Best Answer

you want a voltage divider. if you care about power dissipation, there are a couple of things you can do:

  • use a fairly high impedance voltage divider, with a capacitor on the output terminal, and buffer it with a low-power op-amp. Make sure you use an RC filter between op-amp and ADC, values of this RC filter are typically around 50-200 ohms, 1000pf. This serves to keep voltage stable when the ADC is switching between channels and charge is transferred between the ADC's internal capacitor and the outside pin. An op-amp alone cannot do this. If you don't buffer the high-impedance voltage divider, you will get errors due to ADC leakage current and charge transfer.

  • switch the voltage divider, e.g. connect/disconnect it to the supply voltage, so you can do this only occasionally when you want. A PFET would work, just be careful with how you drive it.