10bit A/d input


Closed Thread
Results 1 to 9 of 9

Thread: 10bit A/d input

  1. #1
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    24

    Default 10bit A/d input

    I'm trying re-learn what I thought I understood 3 yrs ago.
    I have a 16F877A with the A/D set-up for 10 Bits. Outputing the found value to an lcd.
    For my 0-5v input, I have to do FoundValue=DEC adval0/64 in order for the 0-5vdc to equate to FoundValue of 0-1023 on the lcd.
    Otherwise the DEC value goes up in increments of 64 to thirty some thousand.
    I assume I have to use this FoundValue/64 in my calculations.
    Thanks
    JRudd

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Hi,

    Probably you just forgot the conversion result has to be RIGHT justified ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Thanks but it was right justified. I've added the code below. Sorry, I've forgotten how to use a code window and can't find the thread instructions.

    '* This sample program is supplied courtesy of microEngineering Labs Inc *
    '************************************************* ****************************

    ' PicBasic Pro program to display result of
    ' 10-bit A/D conversion on LCD
    ' Connect analog input to channel-0 (RA0)

    ' Define LCD registers and bits
    @ DEVICE HS_OSC

    DEFINE OSC 20
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTD
    Define LCD_RSBIT 2
    Define LCD_EREG PORTE
    Define LCD_EBIT 1
    define LCD_RWREG PORTD
    define LCD_RWBIT 3

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    adval var word ' Create adval to store result
    duty var word
    '************************************************* ***************
    'Set up (2) Channel Analog input
    TRISD=0
    TRISE=0
    TRISA = %00000001 ' Set PORTA.0 to input,ALL THE REST OUTPUTS
    ADCON1 =%00101110 'Set PORTA analog and right justify result
    PORTE.2=0 ' Turn off leds so you can use the lcd display
    PORTD.3=0 ' LCD R/W line low (W)
    Pause 500 ' Wait .5 second
    LCDOUT 254,1
    PAUSE 500
    '************************************************* *****************
    'Set up PWM
    PR2=9
    TRISC.2=0 'Set CCP1 to Output
    CCP1CON=%00001100 'SET CCP1 TO PWM
    T2CON=%00000100 'SET TIMER2 TO "ON";PRESCALE=1

    duty=5


    loop:
    ADCIN 0, adval ' Read channel 0 to adval
    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value: ", DEC adval/64 ' Display the decimal value

    Pause 100 ' Wait .1 second

    Goto loop ' Do it forever
    End
    JRudd

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    you really sure ???

    ADCON1 =%00101110 'Set PORTA analog and right justify result
    I' not ....

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Post editor somewhat " Rock and Roll " ... Heeeeellllp, Lester


    REGISTER 11-2: ADCON1 REGISTER (ADDRESS 9Fh)
    bit 7
    ADFM: A/D Result Format Select bit
    1 = Right justified. Six (6) Most Significant bits of ADRESH are read as ‘0’.
    0 = Left justified. Six (6) Least Significant bits of ADRESL are read as
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Ace, thanks, I've been using a Microchip A/D addendum manual I downloaded years ago and I guess it sort of worked because I never noticed severe problems. (http://ww1.microchip.com/downloads/e...Doc/31023a.pdf)
    I'm going to play with the ADCON1 settings shown in the proper data sheet for the 16F877 this evening.
    JRudd

  7. #7
    Join Date
    Jul 2009
    Location
    Worcester South Africa
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Hi,
    Ace can you please explain right and left justified to me in plain English, what is the difference? What do I get back from a ADCIN PORTA.0, VAR, what is in
    that VAR now, if you have a 10K pot with 5V on, into PORTA.0 ??

    Thanks
    Willie

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


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Hi,
    If your reference voltage is 5V and you're feeding in 5V on the analog input the ADC will return the value 1023. Since a 10 bit value need two bytes (ADRESH and ADRESL) to "fit" you can choose if the result should be left or right justified within those two bytes containing the result.
    Code:
    ADRESH   ADRESL
     00000011   11111111   <-This is right justified, result is "pushed toward the right" within the two bytes
     11111111   11000000   <-This is left justified, result is "pushed towards the left" within the two bytes
    
    The red digits represnts the most significant bit in the result
    If you read the result by combining the high and low byte into a word when the result is left justified you'll get 65572 instead 1023.

    /Henrik.

  9. #9
    Join Date
    Jul 2009
    Location
    Worcester South Africa
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 10bit A/d input

    Thanks a lot Henrik, I think I understand it a bit better now.

    Willie

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