PIC ADC

ericgibbs

Joined Jan 29, 2010
21,442
hi M,
Your original question was.
I want to measure the voltage of a 5V supply with a PIC18F45K22 ADC and a 10K POT
Which is not the same as your last post.

4.7 kΩ and 6.8 kΩ12V to 5V

E
EG57_ 1301.png
 

Thread Starter

MTech1

Joined Feb 15, 2023
181
hi M,
Your original question was.
I want to measure the voltage of a 5V supply with a PIC18F45K22 ADC and a 10K PO
Now I am more interested regarding the formulas used for measuring voltage across different ranges using an ADC in a program. I am not more focused on hardware. I am being confused by reference voltage and maximum voltage

For a voltage range of 0 to 5 volts, the formula used in the program is:
\[ \text{Voltage} = \frac{\text{ADC Value} \times \text{Maximum Voltage}}{\text{Maximum ADC Value}} \]
For instance, to calculate the voltage for an ADC value 'x':
\[ \text{Voltage} = \frac{x \times 5V}{1023} \]

On the other hand, when measuring a voltage range of 0 to 12 volts, the formula remains consistent:
\[ \text{Voltage} = \frac{\text{ADC Value} \times \text{Maximum Voltage}}{\text{Maximum ADC Value}} \]
For a given ADC value 'x':
\[ \text{Voltage} = \frac{x \times 12V}{1023} \]

Can you confirm the last formula that I am using to measure between range 0 to 12 v is correct?
 

tumbleweed

Joined Jun 27, 2023
19
In the above, replace "Maximum Voltage" with "ADC Reference Voltage".
No matter what, that's the max voltage that the ADC can measure, and it results in an ADC Value of full-scale.

If the ADC Reference Voltage is set to the chips VDD, then that's the max.
If you want to measure more than that, compute your voltage dividers to give you an absolute max output < the ADC Reference Voltage.

If you put more than the ADC reference voltage into the ADC input it won't damage anything, but it'll top out at Vref.
Never put more than VDD into any of the pins (unless specifically told it's ok to do that).
 
Top