Help with multiple ADC inputs


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Help with multiple ADC inputs

    I'm having some issues turning on more than a single ADC input, Ive been using the code below.
    Code:
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    RES1 Var Word ' A/D converter result
    RES2 Var Word ' A/D converter result
    RES3 Var Word ' A/D converter result
    AGAIN:
    ADCIN 0, Res1 ' Read Channel 0 data
    ADCIN 1, Res2 ' Read Channel 1 data
    ADCIN 2, Res3 ' Read Channel 2 data
    res1 = res1 /256
    res2 = res2 /256
    res3 = res3 /256
    'Display all 3 ADC results on LCD
    Pause 100
    goto again
    end
    Now I know im missing some ansel, adcon or something to enable the extra inputs, right now the extra inputs are eratic/off, they dont take readings right.
    as long as i stay with ADCIN 0 thers no problem, but I need to take readings on more pins. and am confused on these extra settings, any ideas would be great. also i havent learned to do the fuse settins for freq, brounout, mclre ect, so if possible leave that stuff out of code for right now.

    BTW using a 18F4550
    Last edited by wdmagic; - 28th December 2012 at 05:51.

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


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple ADC inputs

    Try adding

    ADCON2.7 = 1
    ADCON1 = %00001100
    TRISA = %00000111
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple ADC inputs

    after adding that none of the adc works. let me post the actual code im using not the base code, i will include the code you posted

    Code:
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    ADCON2.7 = 1
    ADCON1 = %00001100
    TRISA = %00000111 
    TRISD = %00000000 ' PORTD is output
     
    LCDOUT $FE, 1 ' Clear LCD
    PAUSE 500 ' Wait 0.5sec for LCD to initialize
    SETT Var Word ' A/D converter result in 10bit
    READT var word
    AGAIN:
    ADCIN 0, READT ' Read Channel 0 data
    ADCIN 1, SETT ' Read Channel 0 data
    ReadT = ReadT / 13 'this may change depending on thermostat
    SETT = SETT / 1024 'Output = 0 - 63
    readT = (((readT / 10) * 9) / 5) + 33 'Convert ANA0 to Farent.
    setT = sett + 40 ' Temp Range will be 40 - 103
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "Set Temp = ", DEC setT , $DF , "F     "
    LCDOUT $FE, $C0
    LCDOUT "Temp = ", DEC READT , $DF , "F     "
    pause 100
    GOTO AGAIN ' Repeat

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


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple ADC inputs

    Not sure what is going on with your setup, I do not see the problem.
    I dug out a board with an 18F2550 and ran the below code to make sure it works. I only have the ADC on channels 1 and 2 as I have a LED soldered on channel 2. Other than that it should all be the same.

    Code:
    '<FL_PIC18F2550>'
        '<FL_PBPL>'
        DEFINE OSC 48
        #CONFIG
         __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
         __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
         __CONFIG   _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
         __CONFIG   _CONFIG2L, _PWRT_ON_2L & _VREGEN_ON_2L
         __CONFIG   _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
         __CONFIG   _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
        #ENDCONFIG
        CNT VAR BYTE
        ADCON2.7 = 1
        ADCON1 = %00001101
        TRISA = %00000011
        DEFINE ADC_BITS 10   
        DEFINE ADC_SAMPLEUS 50
        ADC_0   VAR WORD
        ADC_1   VAR WORD
        
        START:
        CNT = CNT + 1
        Serout2 PORTC.6, 16572, ["TEST ",DEC3 CNT, $d, $a]
        Serout2 PORTC.6, 16572, ["ADC_0 ",DEC4 ADC_0, $d, $a]
        Serout2 PORTC.6, 16572, ["ADC_1 ",DEC4 ADC_1, $d, $a]
        TOGGLE PORTA.2
        PAUSE 1000
        GOSUB GET_ADC
        GOTO START
        
        GET_ADC:
        ADCIN 0, ADC_0
        ADCIN 1, ADC_1
        RETURN
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple ADC inputs

    I got it to work by leaving off the adcon.7 code, heres what I am using for 2 ADC, it works great, if I change the adcon.7 it wont even compile

    Code:
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    
    ADCON1 = %10000000
    TRISA = %00000011 'PORTA 0&1 is input
     
    SETT Var Word ' A/D converter result in 10bit
    READT var word ' A/D converter result in 10bit
    
    AGAIN:
    ADCIN 0, READT ' Read Channel 0 data
    ADCIN 1, SETT ' Read Channel 1 data

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


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple ADC inputs

    ADCON.7 will not compile because it is a wrong command. You need to use ADCON2.7=1
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple ADC inputs

    sorry I mistyped, I did use adcon2.7, ill try to produce the exact error again and post it.

Similar Threads

  1. Multiple analog inputs ?
    By rngd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th February 2008, 15:13
  2. Can't get RA0 to read inputs?!?
    By kevj in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th December 2007, 20:46
  3. dip switchs & inputs
    By grounded in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th September 2006, 13:37
  4. Many Analog Inputs
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 10th July 2006, 08:15
  5. multiple serial inputs
    By Richardco in forum mel PIC BASIC
    Replies: 2
    Last Post: - 25th November 2005, 21:26

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