Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

turning ADC reading into mV

Status
Not open for further replies.

large_ghostman

Well-Known Member
Most Helpful Member
i am using a Pic to read the voltage drop accros a resistor among other things and i want to turn that reading into a voltage is the following correct??
my ADC is 10 bit my ref voltage is say 5v (i will use actual value when i DMM the voltage)
so 5/1024*ADC reading will give me the mV??
i am using c18 so for example if i get a ADC reading of 896 5/1024*896=4.375 but how do i do it in C? or is the floating point value ok?
thank you LG
BTW its for current monitoring on the robot and various voltage readings for displaying on lcd
 
Floating point is fine unless you are doing the calculation at a high frequency.

You could always do 0.00488 * 896 and save your micro a calculation.

Or do 488 * 896 and add the decimal point in yourself when you display the current/voltage.
 
ok great info thank you very much
 
i am using a Pic to read the voltage drop accros a resistor among other things and i want to turn that reading into a voltage is the following correct??
my ADC is 10 bit my ref voltage is say 5v (i will use actual value when i DMM the voltage)
so 5/1024*ADC reading will give me the mV??
i am using c18 so for example if i get a ADC reading of 896 5/1024*896=4.375 but how do i do it in C? or is the floating point value ok?
thank you LG
BTW its for current monitoring on the robot and various voltage readings for displaying on lcd


Hi Logan,
Consider using 4.884V as the maximum input voltage to the ADC, this will give a maximum ADC count of 1000.

As an example use a resistor divider to drop a 5V voltage to be measured to 4.884V input to the PIC's ADC. You will have 1000 counts for a 5V input to your divider.
Multiply the 1000 * 5 to give 5000 for a 5V test voltage and 200*5 =1000 for a 1V test voltage.

OK.?
E.

EDIT:

A 220R and 9K2 divider could be used.
 
Last edited:
I was thinking along the lines of EricGibbs, that you could use a 4.096v precision regulator as the Vref for the PIC ADC (on the Vref pin) that gives each ADC count at exactly 0.4mV which is nicer for display.

And the external Vref regulator means the ADC will be more accurate even if the PIC Vdd 5v varies under load or temperature etc. The regulators are cheap and common enough. :)
 
Last edited:
thank you Mr eric and Mr RB for the ideas i havnt replied till now because i have been thinking about your sugestions if i use a regulator could i use a adjustable normal one?? or is it best to use a fixed one? dad has some precision ones but not sure what voltage they are
 
thats a realy good article but this time i need fairly accurate measurement (more than 1% resistor would give) but most the time the stuff i do with ADC would work great using the dividewrs :D thank you
 
3v0 I just had a read through your article and it looks good apart from you seem to be scaling the PIC ADC at /1023 in all your math when the correct scaling factor for a 10bit ADC is always /1024 as the 10bit ADC has 1024 equally sized units included in a total "scale".

If you imagine a voltage divider with 0v-1024v full scale going in and 0v-100v output to a meter the correct scaling is given as 1024:100 or *100 /1024. Using /1023 gives incorrect scaling and introduces linearity errors in the data.

I was recently involved in a long discussion on another forum re the /1023 vs /1024 debate so rather than type all the proofs again you can see them here;
https://forum.allaboutcircuits.com/showthread.php?t=69189
 
my maths is rubish so i guess i shouldnt get involved but i am now intrigued with this! i had always assumed that for scaleing the number for 10bit was 1023 while LG is totaly convinced its 1024, my reasoning has always been that if you write out a 10 bit number on paper you start from 1 wich would give you 1023 segments.
i have no idea wich is correct especialy after reading the link from RB as both arguments seem to stack up!!! oh well is LG's project so i will chicken out and leave it upto him :D but then again after thinking about it when dealing with ADC your actualy starting from 0 so i dunno :confused::confused:
 
Last edited:
my maths is rubish so i guess i shouldnt get involved but i am now intrigued with this! i had always assumed that for scaleing the number for 10bit was 1023 while LG is totaly convinced its 1024, my reasoning has always been that if you write out a 10 bit number on paper you start from 1 wich would give you 1023 segments.
i have no idea wich is correct especialy after reading the link from RB as both arguments seem to stack up!!! oh well is LG's project so i will chicken out and leave it upto him :D but then again after thinking about it when dealing with ADC your actualy starting from 0 so i dunno :confused::confused:

hi J,
Its the possible 'states' of a 10bit value... starting at binary 00 0000 0000, thats the first possible state [ ie; 0Volts] , the last binary state is 11 1111 1111 [1023]

so there are 1024 possible 'states' or equivalent voltages.

Its the old telegraph poles and gaps exam question , you have 1024 poles but only 1023 gaps.:rolleyes:

E.

EDIT:
I use a divide by 1023, after all its the 'changes' in states that matters.

To simplify it, consider a 3bit ADC , with 8 states.
If you had a 8V ADC input and you divided by 8, that would suggest you could display on say an LCD, upto 8Volts.

States:
000...0V
001...1V
010...2V
011...3V
100...4V
101...5V
110...6V
111...7V [ 8 is not possible]

If you divided by 7, that would give 8 states, with an interval of ~1.42V, so 111 would represent 8V
 
Last edited:
Nigel did it easier to learn in his Analog Board tutorials for both understanding and calculation, by using 10.23V ref:
 
Fixed it and if you could give it a quick check I would be grateful.

Yeah it looks pretty good apart from a minor nitpick, you said;
"Lets start by assuming our micro controller has a 10 bit ADC , Analog to Digital Converter. Each conversion will result in a number between 0 and 1023. 0 volts maps to 0 and 5V to 1023."

Actually 5v "maps" to 1024, but since there is no ADC unit above 1023 all values above 4.99999v will also default to 1023. I don't think you need to change anything in the text it's just a technicality.

EricGibbs said:
...
EDIT:
I use a divide by 1023, after all its the 'changes' in states that matters.

To simplify it, consider a 3bit ADC , with 8 states.
If you had a 8V ADC input and you divided by 8, that would suggest you could display on say an LCD, upto 8Volts.

States:
000...0V
001...1V
010...2V
011...3V
100...4V
101...5V
110...6V
111...7V [ 8 is not possible]

If you divided by 7, that would give 8 states, with an interval of ~1.42V, so 111 would represent 8V
...

Using /1023 is a convenience that means the top ADC value will represent 100%, but it does corrupt the data and makes it non-linear. The effect is that the bottom ADC values have a bias that rounds them low and the top ADC values have a bias that rounds them high. So in terms of the "changes" in state it's actually bad as you get displacement of any data set at either end of the range and stretch in the data set if it is large and reaches both ends of the range.

In the last couple of years I've done a lot of programming of windows CAD software and embedded CNC control software, where it always needs to convert from inches to mm and from them to stepper motor steps. It's important to use the correct ratio in translating data from linear scale A to B, which is A:B (or *B /A). If you use *B /(A-1) it gives a linearity error where the left coords on the machine cut too far left and the right coords cut too far right, and the part comes out too big. Or in a ADC with a linear temperature sensor like LM335 the low values will read low and high values read high and total temperature deviation etc is stretched.

So in a nutshell data from linear scale A should be converted to linear scale B using *B /A and this scales all the data correctly during translation, but introduces a rounding down effect where data is rounded down - to the integer unit. If you need to round data +/- to the nearest integer unit you add half a unit before rounding down, so the math is (*B + (A/2)) /A whcih now gives the benefit of correctly scaled data AND will round data up or down as needed to the closest integer unit.
 
Hi guys,

The enhanced mid-range devices include an FVR (fixed voltage reference) module that can be used for the ADC positive voltage reference (you don't have to tie up a pin for an external +vref). Couldn't you use a 25:1 resistor divider along with a 4.096 volt reference from the FVR to get an ADC value = V * 10 (1/10th volt resolution)? For example, 15.3 volts would generate an ADC value of 153? Could this work?

Regards, Mike
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top