Multiple 10bit adc on pic 16f887?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Posts
    3

    Default Multiple 10bit adc on pic 16f887?

    Hello. This is my first question in this forum.
    I have read it for some time. Thanks.

    I need help with a code example for reading AN0,AN1,AN3 with 10bit result.
    I have found som examples but they dont work.

    My display show 1=0 2=0 3=random values. can some one tell me what i do wrong.
    The hardware is ok. i use PBP247.


    ' Compiler : PICBASIC PRO Compiler 2.47
    ' Assembler : PM or MPASM
    ' Target PIC : 40-pin 16F887
    ' Oscillator : 4MHz external crystal
    ' Description : PICBASIC PRO program to display result of
    ' 10-bit A/D conversion on LCD
    ' Connect analog inputs to channels 0, 1, 3 (RA0, 1, 3)
    ' Define LCD registers and bits
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1
    ' Define ADCIN parameters ********************************
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    'Define ADC_CLOCK 3 ' This define is inoperative on 16F88x
    ADCON0 = %11000000 ' Set ADC_CLOCK to RC (DEFINE ACD_CLOCK inoperative on the 16F88x)
    ADCON1 = %00000000 ' Left-Justify result in ADRESH:ADRESL registers
    ANSEL = %00001011 ' Set AN0, AN1, AN3 to analog, others digital
    ANSELH = %00000000 ' Set AN8 and higher channels to digital operation
    '************************************************* *********
    adval1 Var word ' Create adval1 to store result
    adval2 Var word ' Create adval2 to store result
    adval3 Var word ' Create adval3 to store result
    TRISA = %11111111 ' Set PORTA to all input
    Pause 500 ' Wait .5 second
    mainloop:
    Lcdout $fe, 1 ' Clear the LCD
    Adcin 0, adval1 ' Read the first ADC channel
    Lcdout "0=", #adval1 ' Send it to the LCD
    pause 10
    Adcin 1, adval2 ' Read the second ADC channel
    Lcdout " 1=", #adval2 ' Send it to the LCD
    pause 10
    Adcin 3, adval3 ' Read the third ADC channel
    Lcdout " 3=", #adval3 ' Send it to the LCD
    Pause 200 ' Delay for time to read the display
    high portd.1 'led detect program run
    pause 200
    low portd.1
    Goto mainloop ' Do it forever
    End

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


    Did you find this post helpful? Yes | No

    Default Re: Multiple 10bit adc on pic 16f887?

    Try reading one channel first, then go for all three when that is working.
    You have a couple mistakes in your code so look at this
    http://melabs.com/samples/PBP-mixed/adcin10.htm
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Multiple 10bit adc on pic 16f887?

    With 10bit ADC you should right justify the result ADCON1=%10000000
    Shawn

  4. #4
    Join Date
    Feb 2012
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Multiple 10bit adc on pic 16f887?

    Thanks. i am going to try this out.

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


    Did you find this post helpful? Yes | No

    Default Re: Multiple 10bit adc on pic 16f887?

    My data sheet for the 16f877 shows the ADCON1 register to be set up as follows:
    Bit 7,6 Unimplemented, set as 0
    Bit 5 "1"= Right Justified, "0"=Left Justified
    Bit 4 Unimplemented set as 0
    Bits 3,2,1,0 Choose these to select the channels you wish to be analog or digital.

    So, for 10bit and AN0=analog and all others digital, and "Right Justify" result, I would use ADCON1%00101110

    Is this not correct
    JRudd

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


    Did you find this post helpful? Yes | No

    Default Re: Multiple 10bit adc on pic 16f887?

    This is strange. I've been using a MicroChip 10bit a/d manual (http://ww1.microchip.com/downloads/e...Doc/31023a.pdf) which shows a different set-up for ADCON1 than the A/D section of the Datasheet for the 16F877. What am I missing here?
    Thanks,
    John
    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