ADval*/Quanta Question


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default ADval*/Quanta Question

    Hello

    In the formulae ADCIN0,Adval 'read ch0 into Adval
    &Adval=Adval*/Quanta (using 18f4550)
    where Quanta=1251 for 0-5v input
    Adval returns 0-499 ie 4.99

    However for a 10 bit result I require Aval to return 0-1023.
    This appears to be about right when Quanta=2600

    Question: Does anyone know what the correct value of Quanta should be or the formulae to calculate it accurately.

    Thanks
    Tom

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Take VDD divided by the MAX A/D reading, and multiply times 256.

    5 / 1023 * 256 = 1.251

    Scale that up to however many decimal places you want.
    For 3 decimal places, multiply by 1000.

    = 1251

    So your current number is correct for 10-bit A/D with 3 decimals. (0-4999)

    If you only want 2 decimals as indicated in your post, use 125 instead. (0-499)
    Or you can calculate to 3 decimals, then add 5 and divide by 10 and you'll get a rounded number. (0-500)

    4999 + 5 = 5004, /10 = 500
    <br>
    Last edited by Darrel Taylor; - 6th May 2009 at 21:17. Reason: added rounding
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel for your formulae. Substituting 1023 for the 5 I get
    1023/1023*256 *10=2560(Quanta). I was using 2600,now from Pic this gives true 10bit number(1023) at full scale that is sent to pc to be scaled,damped,averaged etc.

    Tom

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    What?

    That's completely self defeating. The A/D converter already put's out 0-1023.

    1023/1023*256 *10=2560
    With the */ operator, all your formula does is multiply it times 2560 and divide by 256, which is the same as just saying ADval * 10.

    So you would actually be sending 10230.
    I don't think that's what you wanted.

    If you want to send 0-1023 to the PC, just send the ADval.
    <br>
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel

    Now I understand, Adval by itself returns 102? and when Adval=Adval*10 it returns 1023 which is what I am using.

    Thanks again.

    Tom

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Don't thank me yet.
    Cuz it looks like there's still some misunderstandings.

    With the Analog to Digital converters, you have two choices (8-bit or 10-bit).
    8-bit returns values from 0-255.
    10-bit values are from 0-1023.

    Those numbers come straight from the converter without any additional math needed.

    Without seeing your code, I can only guess at what's happening.
    My guess is that before sending to the PC, you are breaking the numbers down with the DIG operator.

    DIG starts at 0, with 0 indicating the rightmost digit.
    If ADval was holding the value 1023, (ADval DIG 0) would be 3.
    Code:
    DIG  3210
         1023
    If you're thinking the rightmost digit is 1, and you used DIG 1 thru 4, it would return 0102.
    Multiplying *10 first would make DIG 1 thru 4 return 1023, although the actual value is 10230.

    Are you using DIG?
    <br>
    DT

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Yes you are right Darrel, I am using DIG 1-4 as you thought. I have now simplified program, since adval does = 1023 directly and using DIG 0-3 to send to PC. All 8 temperature readings now work well.

    Thanks again

    Tom

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


    Did you find this post helpful? Yes | No

    Default

    Maybe this isn't the right thread, but when A/Ds are mentioned, everyone thinks in terms of 8 or 10 bit resolution. Some chips (8723 for example) return a 12 bit value. That has screwed me up more than once.
    Charles Linquist

Similar Threads

  1. ADCIN question
    By Greg McFadden in forum General
    Replies: 4
    Last Post: - 16th September 2008, 02:53
  2. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  3. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Timer / CCP Question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2005, 08:22

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