PIC ADC

schmitt trigger

Joined Jul 12, 2010
2,089
If you can increase the supply voltage to 5.12 volts, which is well within a PIC’s operating voltage, then the steps will be exactly 5 mV, and the conversion maths will be simplified.
 

sagor

Joined Mar 10, 2019
1,049
While resolution may be very small (ie: 4.8mV), the accuracy of the A/D process could be off by a few bits. While typical error for this PIC is usually less than one whole bit, it can have up to +/- 2 or 3 bits of error. Check Section 27 of the datasheet, Electrical Characteristics.
You can improve "accuracy" by taking multiple readings and averaging them, but there could still be an offset from real values...
 

Jon Chandler

Joined Jun 12, 2008
1,596
A key point nobody has mentioned – an ADC needs a voltage reference. Typically, Vdd is used, in which case, you assume the reference voltage is 5 volts. So if you measure Vdd with the ADC, it will measure 5 volts no matter what it actually is.

The PIC you're using as several possible references besides Vdd to use, but they are less than 5 volts, so you can't measure 5 volts directly (reference must be greater than the voltage being measured). The less desirable option is to use a voltage divider connected to an ADC input to bring Vdd down to a level that can be measured.

A better method, requiring no external parts, is to set Vdd as the reference and measure what one of the internal references measures. Say the internal reference should measure 2.0 volts, but using Vdd as a reference, it reads 10% high. That means Vdd is 10% lower that the expected 5 volts.
 

joeyd999

Joined Jun 6, 2011
6,281
If you can increase the supply voltage to 5.12 volts, which is well within a PIC’s operating voltage, then the steps will be exactly 5 mV, and the conversion maths will be simplified.
If you consider the A/D conversion result a fraction (as opposed to an integer), then the math is always simple regardless of Vref.
 

Ian0

Joined Aug 7, 2020
13,132
A better method, requiring no external parts, is to set Vdd as the reference and measure what one of the internal references measures. Say the internal reference should measure 2.0 volts, but using Vdd as a reference, it reads 10% high. That means Vdd is 10% lower that the expected 5 volts.
Worth noting that some microprocessor references aren't very good.
Renesas's RA4M1 is 1.44V±5%. That's worse than a 7805 which can manage ±2%.
The LP2951 which I use to supply Vdd to the RA4M1 is ±1%.
 

ericgibbs

Joined Jan 29, 2010
21,442
I want to measure the voltage of a 5V supply with a PIC18F45K22 ADC and a 10K POT,
Hi,
If the TS powers the 10k pot from the same nominal +5v as the PIC and uses the 5v Vdd as the ADC reference voltage, any small change in the 5V supply will not affect the ADC count, as the ADC is ratio-metric.

E
 

Jon Chandler

Joined Jun 12, 2008
1,596
I want to measure the voltage of a 5V supply with a PIC18F45K22 ADC
Worth noting that some microprocessor references aren't very good.
If the TS powers the 10k pot from the same nominal +5v as the PIC....
@MTech1 said he wants to measure the voltage of a 5 volt supply. It very well could be the supply to the PIC.

Maybe the PIC's FVR doesn't have great accuracy. If the TS doesn't understand the point I made, if he measures Vdd referenced to Vdd, he'll be amazed how accurate his supply is.....and that result will be garbage.

If he's measuring the output of a pot or a sensor powered by the same voltage source, yes, the measurement is radiometric – but this is an important concept to understand.

Sorry if my comment to aid in understanding important details has somehow angered y'all. As a troubleshooting engineer, my career has been spent looking past what's being said in order to solve the real problem and to provide understanding. That seems to be the antithesis of the typical answer in this forum. When somebody asks a "kindergarten" question, they get a "doctorate" level reply which does nothing to aid their understanding. Then the arguing of the minutiae starts and the forum is suddenly six pages long after the TS has bailed after the first couple answers.
 

ericgibbs

Joined Jan 29, 2010
21,442
Sorry if my comment to aid in understanding important details has somehow angered y'all.
Hi, Jon.
I hope that I am not included in 'y'all'. ?
I am not angered by your posts.:)

I expect that you already realise that most posted answers are not TS specific, and are read by many other members, so the additional background information posted is often helpful.

Of course, like many other Forum sites, we have our fair share of wiseacres.

E
 
Last edited:

Thread Starter

MTech1

Joined Feb 15, 2023
181
I'm a bit confused about measuring a 12V DC voltage using a potentiometer and displaying it on the screen. To convert the 12V range into the 0-5V range that the ADC can handle, a voltage divider circuit is used. With a 10-bit ADC, 0 represents 0V, 1023 represents 12V, and halfway, 512, represents 6V. The formula to convert ADC values to voltage is:

Voltage = (ADC Value * Maximum Voltage) / Maximum ADC Value

For instance, to find the voltage for an ADC value of 'x':

Voltage = (x * 12V) / 1023

Am I on the right track with this understanding?
 

ericgibbs

Joined Jan 29, 2010
21,442
Hi M,
If I need to measure 12V using a 5V ADC input limit, what divider ratio do I need to use?

And would that ratio apply to all the applied ADC input voltages as set by the 10Kpot wiper?

E
 
Last edited:

Ian0

Joined Aug 7, 2020
13,132
I'm a bit confused about measuring a 12V DC voltage using a potentiometer and displaying it on the screen. To convert the 12V range into the 0-5V range that the ADC can handle, a voltage divider circuit is used. With a 10-bit ADC, 0 represents 0V, 1023 represents 12V, and halfway, 512, represents 6V. The formula to convert ADC values to voltage is:

Voltage = (ADC Value * Maximum Voltage) / Maximum ADC Value

For instance, to find the voltage for an ADC value of 'x':

Voltage = (x * 12V) / 1023

Am I on the right track with this understanding?
It would be advisable to design it so that it can measure voltages more than 12V, say 15V.
Otherwise, if the 12V supply you were measuring was too high, you would never know.
If it reads full scale at 12V, it will also read full scale at 12.5V, 13V, 15V etc.
 

Thread Starter

MTech1

Joined Feb 15, 2023
181
My original question was regarding the formula I provided for measuring a 12-volt DC input. Could you help clarify or confirm if that formula is applicable in that scenario /program?

Anyway, To measure 12V using a 5V ADC input limit, it typically use a voltage divider. The ratio would be determined by the formula:

\[ \text{Divider Ratio} = \frac{\text{R2}}{\text{R1} + \text{R2}} = \frac{\text{Vout}}{\text{Vin}} = \frac{5\text{V}}{12\text{V}} \]

Refrance link https://www.allaboutcircuits.com/tools/voltage-divider-calculator/

4.7 kΩ and 6.8 kΩ12V to 5V
 
Last edited:

Ian0

Joined Aug 7, 2020
13,132
I use this one:
http://sim.okawa-denshi.jp/en/teikokeisan.htm
and it gives 1.3k and 1.8k as the closest.

Then you have to decide whether to use 130Ω/180Ω, 1.3k/1.8k,13k/18k, 130k/180k,all of which will, of course, produce the right answer.

The output impedance of the network is important, being 755Ω for 1.3k/1.8k (the parallel combination of the two resistors).
The A/D will specify a maximum drive impedance, (which is generally about 10k) to achieve maximum speed without influencing adjacent channels. So you could choose 13k/18k if you needed a lower load on the 12V supply, or if you really needed to save power, and were prepared to run the a/d more slowly, you could choose 130k/180k.
 
Top