View Full Version : ADC Math - reading 30Vdc
jmgelba
- 8th April 2011, 14:58
I have a little project where I need to read 0 - 30Vdc. I've used a 100K /10K divider to give a max of 3V into the ADC pin.
My Vref is 5.000V and I'm using a 10bit ADC.
5/1024 = 0.0048V per count
3V = 625
625x48 = 30000
How do I get a count of 625 to display as 30.00V?
ADCIN 1, LEDCOUNT
LEDVOLT = LEDCOUNT * 48
LEDV0 = LEDVOLT/10
LEDV1 = LEDVOLT//10
PAUSE 200
LCDOUT $FE,1, "LED VOLTS ", DEC2 LEDV0, ".", DEC1 LEDV1, "V"
This gives me a display of xx.xV not xx.xxV
aratti
- 8th April 2011, 15:39
5/1023 = 0.004887586 (it is 1024 including the zero)
Times 10000 = 48.8 let use 49
613 x 49 = 30076
30076 / 10000 = 3.0076
Cheers
Al.
jmgelba
- 8th April 2011, 15:49
Ahh yeah. Forgot about the 1023 vs 1024 count.
Ok, so now how do I get the second decimal place shown? I need to display, say, 29.99V or 12.84V etc etc.
Jerson
- 8th April 2011, 15:57
A different look at the problem
5V at adc gives 1024 counts
3V at adc gives ??? counts
Counts for 3V = (1024 * 3)/5
Now, we want to find the voltage instead of counts of adc, so using the equality of ratios,
5V/3V = 1024/???
can also be stated as
5V/??V = 1024/Adc counts
V = (Counts for 5V / 1024)*Adc Counts
since you want V not as 0-3V but as 0-30.00 volts, we will multiply the result by 1000 and artificially put the decimal point in the result
V = (Counts for 5V/1024)*Adc Counts * 1000
This will yield a reading of 0000 to 3000 for an adc reading going from 0-614
You have to display the result by artificially putting the decimal point into the printed result.
Cheers
jmgelba
- 8th April 2011, 17:22
I've got an adc reading giving me a value of 20.4 deg C. How can I get 20.4x?
Ive tried //100 but that just gives me 20.44 where the numbers after the decimal are always the same, ie 20.11 or 20.55 etc etc.
aratti
- 8th April 2011, 17:34
Sorry I missread your post, thinking you needed to read 3 volts.
You will use the same as in your post#1
Count x 49 / 1000 (since you want to read 0 - 30 volts) for the integer.
Count x 49 // 1000 for the decimal part.
Cheers
Al.
Jerson
- 8th April 2011, 17:34
There are a couple of ways. One is to use the DIG command to extract the numbers. Another way would be to use the /(divide) and //(modulus) functions.
So, you print (number /100)
print decimal point
print (number // 100)
I do not have a handy example to show you.
jmgelba
- 8th April 2011, 20:55
I tried the DIG command earlier and I got an odd character.
Interestingly, with a 8.0V source, I'm getting a reading of 15.4V. I'll have to do some further testing.
Meanwhile, any good Math for a thermistor?
Charles Linquis
- 9th April 2011, 02:42
I have a little project where I need to read 0 - 30Vdc. I've used a 100K /10K divider to give a max of 3V into the ADC pin.
My Vref is 5.000V and I'm using a 10bit ADC.
5/1024 = 0.0048V per count
3V = 625
625x48 = 30000
How do I get a count of 625 to display as 30.00V?
ADCIN 1, LEDCOUNT
LEDVOLT = LEDCOUNT * 48
LEDV0 = LEDVOLT/10
LEDV1 = LEDVOLT//10
PAUSE 200
LCDOUT $FE,1, "LED VOLTS ", DEC2 LEDV0, ".", DEC1 LEDV1, "V"
This gives me a display of xx.xV not xx.xxV
If you want two decimal places (xx.xxV):
Number_you_want_to_display = (LEDCNT * 48)/10
"LED VOLTS",DEC2 (Number_you_want_to_display/100),".",DEC2 (Number_you_want_to_display //100)
;-----------------------------------------------------------------------------
If you want 3 decimal places: (xx.xxxV):
Number_you_want_to_display = LEDCNT*48
"LED VOLTS",DEC2 (Number_you_want_to_display/1000),".",DEC3 (Number_you_want_to_display //1000)
jmgelba
- 11th April 2011, 19:32
I tried the DIG command earlier and I got an odd character.
Interestingly, with a 8.0V source, I'm getting a reading of 15.4V. I'll have to do some further testing.
Meanwhile, any good Math for a thermistor?
Fixed both of these issues. Thanks for the help everyone.
On to the next part of the project: controlling a digital pot.
Charles Linquis
- 12th April 2011, 02:23
Also make certain that you have an adequate acquisition time. The ADC is most accurate when the source impedance is < 2K ohms. With a 10 K source, you will need an acquisition time of 11uSec or greater.
jmgelba
- 12th April 2011, 04:23
Thanks Charles. I have had this set to 50uS right from the start. All my ADC channels are working very well.
aajgss
- 16th April 2011, 04:54
How accurate do you need you 3V? A 100K and 10 K don't make a 10:1 ratio.
Ohms Law RTotal/ Rx (in this case 10K)
110K / 10K is a ratio of 11:1
So dropping 30V across 110K will give 27.27V across the 100K and 2.73V across the 10K
aajgss
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.