PIC18F2423 ADC Need Help


Closed Thread
Results 1 to 2 of 2
  1. #1
    Lockerbee1's Avatar
    Lockerbee1 Guest

    Default PIC18F2423 ADC Need Help

    All,

    Good evening. I am using the PIC18F2423 and am trying to use the ADC with PICBasic Pro. To test it's functionality, I am using a modified version of Project 5 from Chuck Hellebuyck's Programming PIC uCs with PicBasic. Depending in the AD reading, the uC should lights up LEDs attached to PortC (with current-limiting resistors).

    Unfortunately, I can only get one LED to briefly flash on, then off.

    Note I am using a 4MHz crystal for the uCs clock, and am trying to use the uCs RC oscillator for the A/D conversion. I'm pretty sure my problem is something with the settings in the ADC control register. My program is as follows:

    'Define ADCIN Parameters

    Define ACD_CLOCK 3

    Define ADC_SAMPLEUS 16

    'Configure Microcontroller I/O Ports

    TrisA = %11111111
    TrisB = %00000000
    TrisC = %00000000

    'Define Constants and Variables

    VOLT var word

    Init:
    PortB = %11111111
    PortC = %00000000


    ADCON1 = %00001100
    ADCON2 = %10000111 'A/D Conversion clock select

    LOOP:
    ADCON0 = %00000001
    ADCIN 0, VOLT
    PAUSEUS 14

    LEDtst1:

    if VOLT > 400 then tst2
    PortC = %00000001
    GOTO cont

    tst2:

    if VOLT > 1200 then tst3
    PortC = %00000011
    GOTO cont

    tst3:

    if VOLT > 2000 then tst4
    PortC = %00000111
    GOTO cont

    tst4:

    if VOLT > 2800 then tst5
    PortC = %00001111
    GOTO cont

    tst5:


    PortC = %00011111

    cont:

    Pause 100
    GOTO LOOP

    END

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


    Did you find this post helpful? Yes | No

    Default

    I keep referring people here
    http://www.rentron.com/PICX2.htm
    Shows how to have the ADC parts in nice neat subroutines.

    It is for a different chip but it is very clear and with the data sheet for the chip you are using in front of you, should be good to go.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  4. PIC18f2423 two 12bit adc input problems
    By Brandon in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th December 2007, 09:47
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

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