Info on using a voltage divider to measure higher voltage on a PIC18F

Thread Starter

Subterranean

Joined Jul 27, 2010
13
Hi,
I'm planning to use a PIC18F4553 for a project of mine that will need to measure a voltage that could go up to 22V. I understand how to use a couple of resistors to set up a voltage divider to bring 0-22V down to 0-5V using the correct ratios of resistors, but I have a few questions:

What sort of values for resistors should I use? I would like the pic to draw as little current as possible from the voltage it is measuring, but be able to detect changes in voltage reasonably accurately and quickly. Should I be looking to use resistors in the range of 100Rs, 1Ks, 10Ks etc?

Is there any other kit I should include in this part of the circuit such as diodes or capacitors?

And finally, am I ok to use the same 5V supply (from a linear voltage regulator) to power the PIC and as reference voltage, or should I use a seperate 5V regulator as reference? How much more accurate would it be?

Thanks for any help, I'm quite new to MC's so I apologise if any of the questions are a bit stupid.
 

t_n_k

Joined Mar 6, 2009
5,455
Page 24 of the data sheet suggests that the maximum source resistance at the A-D input should not exceed 2.5kΩ. So the equivalent parallel resistance (R1||R2) of the proposed divider network should not be greater than 2.5kΩ.
 
However, if you follow that advice, then you will be losing a lot of power, around 200 mW continuous.

There are two tricks that I use for this application.

One is to have the voltage divider switch on when you want to read the voltage. You should have the analog input pin of the microcontroller disconnect from the voltage to test, and you can disconnect the low side of the voltage divider. You need to switch both so that you don't have severe overvoltage into the uC pin input. Alternatively, you could switch the divider by the high side. This will probably still involve two transistors, probably a P-channel on the high side to switch the voltage, and an N-channel on the low side to drive the gate for the P-channel (and use a pull-up resistor on the P-channel gate).

In that case, you simply turn on the voltage divider using another uC output pin, then read your voltage, then turn off the voltage divider. In that case you can make the divider the simple 2.5K Ohm impedance.

The second trick is to use a much higher impedance voltage divider, up in the MegaOhms range, like 2 or 5 MegaOhms. But then, also include a capacitor, such as 1 uF or so, from the test point to ground. This will "buffer" the input impedance into the microcontroller ADC.

The ADC takes a "gulp" of current when it samples. This is the actual thing that requires the lower impedance on the input. If you buffer the input with a capacitor, then it will accumulate charge in the off times, and only when the ADC samples it, then it take about 30 pF of input charge and it should be pretty good in the results. Note that most digital multimeters will not show the correct voltage because they will be drawing current from the test point for much longer than a single 30 pF gulp. So trust your uC output in this case.

You can experiment with both and see which works best for you.
 

Markd77

Joined Sep 7, 2009
2,806
If you want to use higher values to reduce loading on the test circuit you can use resistors totalling 100K or more and an op amp buffer. The op amp would have to be "rail to rail" if running from the same regulator as the PIC or be capable of inputs and outputs going to ground if you use a higher supply for it (unless you have a negative supply handy).

<ed>Just saw the capacitor idea, sounds good. Might have to try that one.</ed>
 

Vaughanabe13

Joined May 4, 2009
102
Yes you can use a 5V power supply, as long as it is regulated and pretty constant. Keep in mind that the PIC's ADC module is only as accurate as its reference voltages (VDD and VSS) so make sure that 5V is regulated and you should be fine.
 
Top