Analog pins for digital input


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Analog pins for digital input

    I know that if a pin is configured for analog, I can't use it as a digital output, but if a pin is configured as an analog input, can I still read the pin as a digital input?

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


    Did you find this post helpful? Yes | No

    Default

    Not normally if you've configured it as Analogue Input. If you need to use it as digital, you must recondfigure as such... there's no problem doing this mid-program flow.

    For a concise answer, most PIC pins have a simplified block diagram of it's configuration in the Datasheet. If it looks like the pin is simultaneously connected to both analog and digital circuitry regardless, then there's no harm doing an experiment to see if it works in Digital whilst configured for Analogue.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi,

    As long as you only need to read digital "input", you can leave the pin configured as analog.

    I believe TTL logic high (when using a 5 volt supply) is 2V.
    So, just read your analog input and if the voltage is higher than 2V, set a logic flag high. If it's less than 2V, set the flag low.

    That being said, you could just reconfigure the pin as Melanie suggested.
    However, it sounds like you want to leave it configured as analog for some reason.

    I'd be curious to see if you could simply read the pin's input value (not the ADC value) when it's configured as analog. It would be interesting if it registered as a 1 when the voltage was greater than 2V. You should try it.

    Cheers!
    Last edited by picnaut; - 8th September 2005 at 15:55.
    ---> picnaut

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


    Did you find this post helpful? Yes | No

    Default

    i never tested the above suggestion but it can work. But for safety sake i will turn them to digital.

    Another solution...use ADCIN to read the pin.
    [html]
    If result<XYZ => pin is LOW
    if result>ABC => pin is HIGH.
    [/html]
    That will allow to determine your own HIGH/LOW threshold.

    Just an idea.
    Last edited by mister_e; - 8th September 2005 at 15:59.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    I realize that I could just do a conversion to determine the pin's state, but I need to sit in a loop and look for a really short toggle.

    The reason I have to configure it as analog is that the signal is connected to AN1, and I need to configure AN2 & AN3 as analog. The circuit is already built and I can't change the wiring.

    I think the best solution is to do what Melanie suggested and configure the port as digital, read the pin, convert to analog, read channels 2&3, and switch back to digital.

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. How can i control pic input pins order?
    By tanero in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th August 2005, 12:46

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