PIC18f2423 two 12bit adc input problems


Closed Thread
Results 1 to 7 of 7
  1. #1
    Brandon's Avatar
    Brandon Guest

    Default PIC18f2423 two 12bit adc input problems

    Hi all,

    I got some pic18F2423 chips so I could monitor two pots on two pins at 12bit.
    Everything ALMOST works. I can't seem to get the second adc (porta.1) to work.
    It is not the pots, if i siwtch them porta.1 stays dead, or i should say, outputs whatever is on porta.0.

    Any help would be great, i am sure it is a newbie queston


    'pic18f2423 with 12bit adc

    define OSC 20
    DEFINE ADC_BITS 12 'SETS NUMBER OF BITS IN RESULTS 8,10,12
    DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
    DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS
    ADCON2.7 = 1 'right justify port a
    W0 Var WORD
    W1 Var WORD
    b0 Var w0.Byte0 'high byte of word w0
    b1 Var w0.Byte1 'low byte of word w0
    b2 Var w1.Byte0 'high byte of word w1
    b3 Var w1.Byte1 'low byte of word w1
    include "modedefs.bas"

    loop:
    ADCIN PORTA.0,W0
    pauseus 100
    ADCIN PORTA.1,W1
    pauseus 100
    LOW 0 'turn off led for testing
    SEROUT PORTB.3, T9600, ["T"] 'TILT
    SEROUT PORTB.3, T9600, [#w0,10]
    HIGH 0'turn on led for testing
    SEROUT PORTB.3, T9600, ["P"] 'PAN
    SEROUT PORTB.3, T9600, [#w1,10]

    goto loop

    end
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello, you need to configure the ADCON1 register, refer to datasheet page 228.

  3. #3
    Brandon's Avatar
    Brandon Guest


    Did you find this post helpful? Yes | No

    Default still having problems reading anything other then AN0

    I've read the datasheet over and over, and I think I have all the ADCONs set to read analog from AN0 and AN1 but I can only get AN0 to work, AN1 just reads whatever is coming in AN0. Any help would be great


    'pic18f2423 with 12bit adc

    define OSC 20
    DEFINE ADC_BITS 12 'SETS NUMBER OF BITS IN RESULTS 8,10,12
    DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
    DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS
    ADCON1 = %00001101 'SET ANALOG PINS AN0 AND AN1
    ADCON2.7 = 1 'right justify port A
    W0 Var WORD
    W1 Var WORD
    'b0 Var w0.Byte0 'high byte of word w0
    'b1 Var w0.Byte1 'low byte of word w0
    'b2 Var w1.Byte0 'high byte of word w1
    'b3 Var w1.Byte1 'low byte of word w1
    include "modedefs.bas"

    loop:
    ADCIN PORTA.0,W0
    pauseus 100
    ADCIN PORTA.1,W1
    pauseus 100
    LOW 0 'turn off led for testing
    SEROUT PORTB.3, T9600, ["T"] 'TILT
    SEROUT PORTB.3, T9600, [#w0,10]
    HIGH 0'turn on led for testing
    SEROUT PORTB.3, T9600, ["P"] 'PAN
    SEROUT PORTB.3, T9600, [#w1,10]

    goto loop

    end

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


    Did you find this post helpful? Yes | No

    Default

    Use the AN? number, not the PORT pin.

    ADCIN 0,W0
    ADCIN 1,W1

    With the original statements ...

    ADCIN PORTA.1,W1

    It reads PORTA.1 as a DIGITAL bit value. And since the pin is in analog mode, it always reads 0.

    It then uses that number for the AN? channel. So ADCIN always reads Channel AN0.
    <br>
    DT

  5. #5
    Brandon's Avatar
    Brandon Guest


    Did you find this post helpful? Yes | No

    Red face Thanks!

    That was the problem, thanks a lot! boy do I feel dumb.

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


    Did you find this post helpful? Yes | No

    Thumbs up

    The longer you hang around here.

    The less you'll have that feeling.
    <br>
    DT

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Are you really sure of it
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. ADC input using a current transformer?
    By jessey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th May 2009, 22:13
  2. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  3. Problems with ADC
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th January 2009, 17:34
  4. PIC18F2423 ADC Need Help
    By Lockerbee1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd July 2007, 22:00
  5. Replies: 2
    Last Post: - 17th February 2006, 09:52

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