PORTA.4 as analog input


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Location
    Selangor, Malaysia
    Posts
    31

    Default PORTA.4 as analog input

    Hi all,
    I'm having problem to use the porta.4 as the analog input for PIC16F88... When i connect the signal line (0.1v to 0.9v) to porta.4, the signal voltage will become 0v. I have tried to put a 10M series resistor to porta.4 and connect another 10M resistor to the ground. Anyone have the idea?

    I also tried to connect the signal line to other AN, for example AN2. Now the voltage on the signal will be .2 lesser than the original voltage. I really don't have any idea on this. Please help!!

    Thanks!

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Without knowing more, all I can tell you is that 10M is far too high a resistance for the input of a PIC to measure. If you want any kind of accuracy, you should keep the input impedance to below 4K or so. Use two 5K resistors
    in series between Vcc and GND and connect the junction to the A/D input, then read the A/D and see what you get.
    Charles Linquist

  3. #3
    Join Date
    Jul 2005
    Location
    Selangor, Malaysia
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    Without knowing more, all I can tell you is that 10M is far too high a resistance for the input of a PIC to measure. If you want any kind of accuracy, you should keep the input impedance to below 4K or so. Use two 5K resistors
    in series between Vcc and GND and connect the junction to the A/D input, then read the A/D and see what you get.
    Thanks for your reply... I just try for 2.2k resistor but also give me the same result. The Signal voltage to measure also drop to 0v...

    From the internet surfing...... the PortA.4 is open collector.... maybe this is the reason.....? Or do i need to put a pull up resistor or something like that?

    Thanks!

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Have you properly configured the pin for INPUT (eg set the TRIS for that pin)?

    Have you DISABLED the COMPARATORS that use that pin?

    Have you ENABLED that pin for ANALOG input?

    What EXACTLY makes you think that RA4 is Open Collector? Some dubious second-hand information that you got off the internet? Just because RA4 is Open Collector on one PIC, doesn't mean it is on another... so find out if that statement is true or not.

    And if it was Open Collector, what has that got to do with using the pin for INPUT?

    There is ONLY ONE definitive source of reliable information for any PIC chip. That is the manufacturers DATASHEET downloadable from Microchips website. Go do it.

  5. #5
    Join Date
    Jul 2005
    Location
    Selangor, Malaysia
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply.

    Below are my declaration

    OSCCON = %01101110 ' 4 MHz, primary clock, internal RC

    PIR1 = %00000000 ' clear all flags particularly A/D IF bit 6
    SSPCON = %00000000
    SSPBUF = %00000000
    TXSTA = %00000000
    RCSTA = %00000000
    OPTION_REG = %00000000 'weak pullups enable

    'pin IO 76543210
    TrisB = %10000100
    TrisA = %01010101

    cmcon =7 'disable the comparator register


    ADCON1 = %10000000 ' right justified, AD Clock divided by 2,Vdd = Vref+, Vss = Vref-
    ANSEL=%1010100'only the RA4/AN4, RA2/AN2, RB7/AN6 as analog input
    CCP1CON = %00001100


    The adc are working on RA2 and RB7, but not on RA4.

    Please help.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    OK...

    Your settings look good, the ones that you have shown us... but here are some comments...

    If you have problems, follow the instructions in the Datasheet.

    They tell you that ANSEL should be set before ADCON1.

    Also, if you are setting an entire Register using the Binary notation %, and the Register is eight bits wide, then you really should be setting all eight bits... ANSEL=%01010100 and not just seven bits.

    You've not shown us your setting of ADCON0.

    Have you also checked that your RA4/AN4 pin is not shorted out against any other pin or part of your circuit? Measure the Resistance between that pin and 0v, then unplug the PIC and measure it again on the socket. This way you will determine whether the excessive loading is internal to the PIC (indicating a possible setting error or other problem with the PIC), of if it is external on your PCB or breadboard layout.

    Finally, beware of settings like...

    OPTION_REG = %00000000 'weak pullups enable

    That does a lot MORE than just set weak pull-up's.

    OPTION_REG.7=0 ' Set weak Pull-up's ONLY (leave the other settings alone!)

    Take a look at the OPTION REG in the Datasheet to see what I mean.

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. Analog input on 18f252
    By kiteman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th January 2009, 08:34
  3. Analog Input on PIC16F88
    By penelopepug in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2008, 22:49
  4. 16f88 - pin RA4 as analog input
    By savnik in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 15th December 2006, 13:55
  5. Analog pins for digital input
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2005, 00:32

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