ADC Math - reading 30Vdc


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default ADC Math - reading 30Vdc

    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?

    Code:
    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
    Last edited by jmgelba; - 8th April 2011 at 15:11.

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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.
    All progress began with an idea

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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.

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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

  5. #5
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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.

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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.
    Last edited by aratti; - 8th April 2011 at 17:36.
    All progress began with an idea

  7. #7
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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.

  8. #8
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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?

  9. #9
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    Quote Originally Posted by jmgelba View Post
    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?

    Code:
    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)
    Charles Linquist

  10. #10
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    Quote Originally Posted by jmgelba View Post
    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.

  11. #11
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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.
    Charles Linquist

  12. #12
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    Thanks Charles. I have had this set to 50uS right from the start. All my ADC channels are working very well.

  13. #13
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: ADC Math - reading 30Vdc

    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

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts