ADC lcd display help


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    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 !

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    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.

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    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.

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