ADC lcd display help


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108

    Question ADC lcd display help

    Hello all,

    I am finally able to re-visit an old project of mine and am in need of a bit of assistance.
    I've got a 16F886 up and going with one exception... the ADC.
    I've got a DC source I'm monitoring with 10 bit res. on AN0.
    The details:
    DC can swing from 0-350 vdc.
    This runs through a 70:1 scaler and is clamped to 5.1 vdc.
    So at 350 vdc, max scaled voltage will be 5 vdc. (350/70)
    ...
    This is where I get way confused
    Can one of you fine folks explain how to determine the ADC "count" based on my 0-350 vdc?
    and
    How to convert the ADC counts back to the 0-350 vdc in order to display it on an lcd?
    ...
    Thank you all,
    Chris

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


    Did you find this post helpful? Yes | No

    Default

    10 bit A/D count = 1023 when Vin = Vref
    12 bit A/D count = 4096 when Vin = Vref
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Correction:

    12 bit A/D count = 4095 when Vin = Vref
    Charles Linquist

  4. #4
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks Charles,

    I think I grasp that concept.
    350/1024 = .3418 ... so for every .3418 volt change at the 350 side of things, there is a "count" change.
    Therefore, if we start with, say:
    165 vdc
    ...through the voltage scaler to the ADC in:
    165/70 = 2.3571 vdc
    VRef(5.1)/1024 = .004883
    2.3571/.004883 = 482.7115 <<<<<<<<<<<<<<<<<<< The ADC "count" would be 482?
    (ADC count * 4883 * Scaler ratio) / 10000
    (482*4883*70) / 10000 = 16475.242<<<<<<<<<<<<<<<<< 16475 is the "high voltage"?
    ...for the lcd:
    LCDOut 16475/100,".",16475//100," VDC"
    "164.75" <<<<<<<<<<<<<<<<<<<<<<<<< Where did I go wrong in not getting "165"?

    I am probably confusing myself more than I'm helping.
    Would love a quick tutorial from one of you knowledgeable folks.

    Thanks again,
    Chris

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    At the risk of confusing you more...
    http://www.picbasic.co.uk/forum/cont...Sensor-Scaling
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks Mack,

    Funny you point out that thread... That's the one I've been racking my brain over.
    I'll take another look though.

    Chris

  7. #7
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Hey Mack,

    Quick question. When we're talking about the ADC count based on the sampled voltage,
    what happens to the count when it's fractional?
    IE:
    count = 557.26 ... does this become 557 or 558?
    count = 952.76 ... does this become 952 or 953?

    I guess I'm just wondering what the "rounding" routine is, if any?

    Thanks again,
    Chris

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks for the heads up Mack,

    I guess I was a bit confused by this in your ADC scaling tutorial:
    Code:
    Convert this to an 10 bit PIC® resolution.
    
    10 bits ADC = 0 to 1023, 1024 steps.
    At 5.0 volts one volt of input will will read 205. (204.6 actually)
    Why would that read 205, instead of 204?
    Thanks Mack, for helping a newbie trying to understand.

    Chris

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevlar129bp View Post
    Why would that read 205, instead of 204?
    Thanks for catching that and I apologize for the confusion.

    I changed the article to

    10 bits ADC = 0 to 1023, 1024 steps.
    At 5.0 volts one volt of input will will read 204. (204.8 actually)
    But we will use 205 for accuracy.
    204 * 5 = 1020
    205 * 5 = 1025
    Hope that clears things up a bit..
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Hey Mack,

    I sketched this code in notepad after reading some other posts...
    Does it look like I'm on the right track?
    Code:
    ADVal VAR WORD
    Quanta CON 489	'VREF/1024 = 5/1024 = .00488 = 489
    VoltageDivider CON 70
    ADCVolts VAR BYTE
    LCDVolts VAR WORD
    
    ADCIN 0,ADVal
    	ADCVolts=(ADVal/1000)*Quanta
    	LCDVolts=ADCVolts*VoltageDivider
    		LCDout $fe, 1
    		LCDout $fe, 2,   "CURRENT READINGS ARE"
    		Lcdout $fe, $C0, "A/D VDC = ",DEC1 ADCVolts/100,".",DEC2 ADCVolts//100
    		Lcdout $fe, $94, "--------------------"
    		Lcdout $fe, $D4, "ACTUAL VDC = ",DEC3 LCDVolts/100,".",DEC2 LCDVolts//100
    Thanks again for your assistance,
    Chris

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Really close!!
    But I think I would try it like this.

    Code:
    ADVal VAR WORD
    Quanta CON 342     ' 350 / 1023 * 1000
    LCDVolts VAR WORD
    Z   VAR WORD     'DUMMY VAR
    Z1  VAR WORD     'DUMMY VAR
    
    ADCIN 0,ADVal
    	Z = ADVal * 342
            Z1 = DIV32 1000
    	LCDVolts = Z1
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Need help ...with this math. Please !
    I use voltage divider ; R1=1000 ohms; R2= 50 to 3500 ohms.
    I read the voltage :
    Code:
    ADCON0 = %10000001 
    		Pauseus 50			' Wait for channel to setup
    	    ADCON0.1 = 1			' Start conversion
    		While ADCON0.1=1:Wend		' Wait for conversion
    		advalue.HighByte=ADRESH		' Read variable from ADC and save
    		advalue.LowByte=ADRESL
    I try to calculate the resistor(s) R2, assuming that I do not know values.
    Formula is (?) :
    R2= 1000 * advalue/(1024-advalue)
    I wrote this code :
    Code:
    dummy =1000 * advalue 
    resistor = div32 10
    resistor = (resistor / (1024-advalue)) * 100
    I want to display on Nokia 3310 :
    Code:
    '~~~~~~~~~~~~~~~~~ setting cursor for display the advalue
                    LcdReg  =  %10000000 + 5       ' cursor  X
                    call    PrintCtrlLcd
                    LcdReg  =  %01000011            ' cursor  Y
                    call    PrintCtrlLcd
    '~~~~~~~~~~~~~~~~~ now display results 
       
                   Char = (advalue dig 3)           
                   call    PrintChar
                    
                   Char = (advalue dig 2)                      
                   call    PrintChar                
    
                   Char = (advalue dig 1)           
                   call    PrintChar
                   
                   Char = (advalue dig 0)           
                   call    PrintChar
    .............
                    Char = resistor dig 4          
                    call    PrintChar
                    Char = resistor dig 3          
                    call    PrintChar
                    Char = resistor dig 2         
                    call    PrintChar
                    Char = resistor dig 1         
                    call    PrintChar
    But I can not to display the last digit (from right) of values of resistors ...I have "50" instead "54" ; "140" instead "147" ; "1030" instead "1036" ...

    Please, point me to the right direction ! Thanks in advance !

  14. #14
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Hi,
    The result from the ADC ranges from 0 to 1023, not 1024. Try using 1023 in the formula and see if that makes it better.

    With that said the whole thing is a bit convoluted....Why do you multiply by 1000 only to divide the result by 10 directly after?

    What's the voltage at the top of the resistor divider and what's VRef?
    If both are 5V then the highest voltage on the ADC input would be 5/(1000+3500)*3500=3.888V giving an ADC reading of 3.888/(5/1024)=796.
    If you multiply 796 by 100 (multiply by 1000, divide by 10) the result will still overflow a WORD.

    /Henrik.

  15. #15
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Thanks !
    I tried with 1023, but no modification. I need to have the result of resistor(s) into a word variable like this "3499", so I can displaying on my N3310 display.

  16. #16
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Hi,
    I'll try again.... If R1 is 1k and R2 is 3.5k and the voltage at the top of the divider as well as VRef is 5V then you'll get an ideal ADC reading of 796, which will be your highest reading. So far so good.

    Now, doing the dummy=1000*advalue isn't a problem, the problem comes when you do Resistor = div32 10 becasue the result of that calculation WILL overflow the WORD sized variable resistor (79600) so the concept is flawed.

    Apart from that you don't have enough resolution to "get to" the last digit. Your resistive range is 3450 ohms, the voltage at the ADC input will range from 0.238V to 3.889V giving you ADC readings ranging from 48 to 796.
    So all you have is 796-48=748 "steps" for your total range of 3450 ohms, a resolution of roughly 3450/748 = 4 ohm which is why you get 1036 instead of 1030 and 54 instead of 50.

    You can use oversampling to increase the resolution of the measurement.

    /Henrik.

  17. #17
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Now I understand ! Thank You so much !!!

  18. #18
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Here is an OLD example from our not to be forgotten friend Daryl.
    Attached Files Attached Files
    Dave Purola,
    N8NTA
    EN82fn

  19. #19
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: ADC lcd display help

    Thanks ! Verry good example ...
    I miss him too ...

Members who have read this thread : 1

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