16F684 ADC problem


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2005
    Posts
    53

    Angry 16F684 ADC problem

    I am having a problem reading the RA4 (AN3) pin 3 on a 16F684.
    I have several boards that perform the same.
    I can read RA0 (AN0) OK. Am I missing a setting?

    TRISA = %11011111 ' Config I/O s
    CMCON0 = 7 '%00000111 ' Comparators OFF
    CCP1CON = %00000000
    ANSEL = %00001001

    Loop
    ADCIN 3,AD4 'read channel 4...AN3
    AD4 = AD4 >> 6
    SerOut PORTA.5, n2400,[I,192,#AD4," "]
    goto loop

  2. #2
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default cannot read RA4 pin3 ADC configuration?

    I can read AN0, AN1, AN2 but not AN3, AN4 data appears to change with AN2.

    AM I missing a configuration setting?

    INCLUDE "modedefs.bas"
    DEFINE CHAR_PACING 500 '
    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
    WPUA=%00000000
    OSCCON = $60 ' WDT_OFF,
    @ DEVICE PIC16F684, INTRC_OSC_NOCLKOUT, PWRT_Off, MCLR_OFF, BOD_OFF,PROTECT_OFF
    AD0 VAR WORD ' AD0 word (10 bits)
    AD1 VAR WORD ' AD1 word (10 bits)
    AD2 VAR WORD ' AD2 word (10 bits)
    AD3 VAR WORD ' AD3 word (10 bits)
    AD4 VAR WORD ' AD4 word (10 bits)
    TRISA = %11011111
    TRISC = %11000000
    CMCON0 = 7 '%00000111 ' Comparators OFF
    CCP1CON = %00000000
    adcon0=%00000001
    ANSEL = %00000001
    LOW PORTC.1

    loop:

    ADCIN 0,AD0 'read channel 0...AN0
    AD0 = AD0 >> 6
    ADCIN 2,AD2 'read channel 2...AN2
    AD2 = AD2 >> 6
    ADCIN 3,AD3 'read channel 3...AN3
    AD3 = AD3 >> 6
    ADCIN 4,AD4 'read channel 4...AN4
    AD4 = AD4 >> 6
    SerOut PORTA.5, n2400,[I,192,#AD0," ",#ad2," ",#AD4," "]
    SerOut PORTA.5, n2400,[I,128,#AD3," "]

    goto loop

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    http://ww1.microchip.com/downloads/e...f684%20data%22

    the link above will get you the data sheet, the code below is copied from the data sheet page 33 I believe it is what you need, I would add that input pin appears to require a pullup resistor too.
    ASM
    BCF STATUS,RP0 ; BANK 0
    CLRF PORTA ;Init PORTA
    MOVLW 07H ; Set RA >2:0> to
    MOVWF CMCON0 ;Digital I/O
    BSF STATUS, RP0 ;Bank 1
    CLRF ANSEL ;Digital I/O
    MOVLW 0Ch ;Set RA<3:2> as inputs
    MOVWF TRISA ; and set RA<5:4,1:0>

    BCF STATUS,RP0 ;Bank 0
    ENDASM

    if this turns out to be wrong, keep this in mind,
    I did all the typing for you

    JS
    More lost than many . . too dumb to know it, too darn old to care.

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


    Did you find this post helpful? Yes | No

    Default

    @MarkEdwards
    Your ANSEL setting is wrong. Try
    ANSEL %00011111
    Steve

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

  5. #5
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Question ANSEL %00011111 didn't work

    Thanks MR E for the reply!

    pin 3 RA4, AN3 seems like it is an output because it is low impeadance.
    I am trying to measure 0 - 4 vdc and have a 10k series
    resistor and a .1uf capacitor. The voltage is loaded down
    on some boards, a few boards pin 3 seems to work.
    I figure I am missing some configuration setting or don't understand
    something. 3 other adc inputs work as expected.

    Mark

Similar Threads

  1. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  2. 16F684 AtoD problem
    By hell_pk in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 20th February 2009, 06:59
  3. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  4. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22
  5. ADC problem
    By NacNud in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th December 2004, 02:27

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