adcin trouble


Closed Thread
Results 1 to 3 of 3

Thread: adcin trouble

  1. #1
    Join Date
    Mar 2010
    Location
    Austin, TX
    Posts
    68

    Default adcin trouble

    I am experimenting with a servo tester to gain some experience with pic programming. Especially reading a pot, and a switch to control the servo output. The pic is a 16f683 and I can get it working and I can read the switch, but I have so far failed to get anything but 0 from the pot.

    The pot input is pin 6, AN1 and I have verified that it varies the voltage from 0 to +5.

    Here is the relavent portion of code:
    --------------------------------------------------------------------------
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC SAMPLES 50

    TRISIO = %11111110 ' set porta.0 output and all other to inputs
    ANSEL = %00000010 ' porta.1 to analog, others to digital
    ADCON0 = %10001001 ' analog input on porta.1, Right justify result
    CMCON0 = %00000111 ' Turn of the comparators
    PORTA = %00000000 ' set porta to all 0's

    pulse_width var word

    adcin porta.1, pulse_width
    --------------------------------------------------------------------------
    Any help would be appreciated.
    Thanks,

    Mike

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


    Did you find this post helpful? Yes | No

    Default

    I will assume you mean 12F683 ?

    There is not a PORTA.
    Code:
    TRISIO = %11111110 ' set GPIO.0 output and all other to inputs
    ANSEL = %00000010 ' porta.1 to analog, others to digital
    ADCON0 = %00000100 ' analog input on GPIO.1, Left justify result for 8 bit
    CMCON0 = %00000111 ' Turn of the comparators
    GPIO = %00000000 ' set porta to all 0's
    
    adcin 1, pulse_width
    Give it a try.. No guarantees...
    Last edited by mackrackit; - 29th March 2010 at 22:35.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2010
    Location
    Austin, TX
    Posts
    68


    Did you find this post helpful? Yes | No

    Default

    Thanks MACKRACKIT.

    You were right on both counts.

    Next is timer control and then interrupts.

    Thanks for the help.

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