10bit A/d input


Closed Thread
Results 1 to 9 of 9

Thread: 10bit A/d input

Hybrid View

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

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


    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 " !!!
    *****************************************

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


    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 " !!!
    *****************************************

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

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