Incorrect adc channel bits generated


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    40

    Angry Incorrect adc channel bits generated

    I have been trying to get the following code to work using a pic18F24j11.
    The code is compiled with PICbasicpro 2.50. I have stepped this code using mplab simulator and as one can see the incorrect analog channels are being generated. Is this a problem with the compiler?

    ' PICBASIC PRO program to READ 4 ANALOG VALUES
    ' 10-bit A/D conversion
    ' PIC=18F24J11
    '
    ' Connect analog input to channel-0 (AN0) RA0
    ' Connect analog input to channel-1 (AN1) RA1
    ' Connect analog input to channel-2 (AN2) RA2
    ' Connect analog input to channel-3 (AN3) RA3
    ' Connect analog input to channel-4 (AN4) RA5
    '
    ' 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

    adval0 var word ' Create adval to store result
    adval1 var word
    adval2 var word
    adval3 var word
    adval4 var word


    START:
    ANCON0=%11100000 'analog 0 to 4
    ANCON1=%11111111 'DIGITAL
    ADCON0=%00000001
    ADCON1=%10000010 ' Set right justify result
    TRISA=%00011111

    'adcon0 CHS VALUES
    mainloop: ADCIN 0, adval0 ' OXC1 = 0000 CHAN0
    ADCIN 1, adval1 ' 0XC9 = 0010 CHAN2
    ADCIN 2, adval2 ' 0XD1 = 0100 CHAN4
    ADCIN 3, adval3 ' 0XD9 = 0110 CHAN6
    ADCIN 4, adval4 ' 0XE1 = 1000 CHAN8
    GOTO MAINLOOP

    Graham

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    See the first issue on this page.

    http://melabs.com/support/pbpissues.htm
    <br>
    DT

  3. #3
    Join Date
    May 2009
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Incorrect adc channel bits generated

    Thanks for the quick reply Darrel. Will use workaround.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. parsing adc word into bits
    By GREYBIRDMAN in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th April 2007, 21:08
  4. 18F1320 ADC multiple channel select
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2005, 21:40
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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