Can an led be controlled by analog pin?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84

    Default Can an led be controlled by analog pin?

    Is it possible to control an led (+5V output) using a pin that is set to analog? The ADCON1 options don't allow me the desired A/D pin combination's I require.

    I am using a 16F716 & 16C711.

    Thanks
    James

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by droptail View Post
    Is it possible to control an led (+5V output) using a pin that is set to analog? The ADCON1 options don't allow me the desired A/D pin combination's I require.

    I am using a 16F716 & 16C711.

    Thanks
    No, but you can switch the pins between analog and digital pin modes 'ON THE FLY'... You might end up with a pulsing LED, but it'll still work.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Is it possible to control an led (+5V output) using a pin that is set to analog?
    Yes, it's possible. But the technique required depends on how you are using the other Pins on PORTA.

    Pins in analog mode can be put into output mode, and they will work just fine as long as no other Pins on that port are used for Digital input.

    If another pin is using Digital OUTPUT, then a holding register can be used to eliminate the Read part of Read-Modify-Write.

    If RA4 is an input to T0CKI, then that isn't considered a Digital input as far as R-M-W goes.

    And yes, you can re-configure the analog ports "on-the fly", but that won't take care of the R-M-W problem if any of the pins are Digital INPUT.

    What are the other pins on PORTA used for, and what is your current ADCON1 setting?
    <br>
    DT

  4. #4
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Yes, it's possible. But the technique required depends on how you are using the other Pins on PORTA.

    Pins in analog mode can be put into output mode, and they will work just fine as long as no other Pins on that port are used for Digital input.

    If another pin is using Digital OUTPUT, then a holding register can be used to eliminate the Read part of Read-Modify-Write.

    If RA4 is an input to T0CKI, then that isn't considered a Digital input as far as R-M-W goes.

    And yes, you can re-configure the analog ports "on-the fly", but that won't take care of the R-M-W problem if any of the pins are Digital INPUT.

    What are the other pins on PORTA used for, and what is your current ADCON1 setting?
    <br>
    I had thought about continually flipping the ADCON1 register, but wasn't sure about the effect on everything, my continuous ADC, flickering led, etc.

    No other pins on that Port are used as digital input. All PORTA pins are analog, (2) are used as ADC input. (RA4 is an input to T0CKI)
    ADCON1 =0

    Thanks for the input.
    James

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Ok, so there are 4 analog pins, they are all in analog mode.

    You are using 2 of them for analog input and want to use 1 for digital output.
    That leaves 1 analog pin unaccounted for.

    Is that one an OUTPUT too?
    It makes a big difference.

    If not, and it's just not being used, then you can use HIGH and LOW like normal on the pin with the LED.

    If that other pin is also an output, you'll need to use a variable as a Latch (holding reg) to fix the R-M-W issue.
    <br>
    DT

  6. #6
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Ok, so there are 4 analog pins, they are all in analog mode.

    You are using 2 of them for analog input and want to use 1 for digital output.
    That leaves 1 analog pin unaccounted for.

    Is that one an OUTPUT too?
    It makes a big difference.

    If not, and it's just not being used, then you can use HIGH and LOW like normal on the pin with the LED.

    If that other pin is also an output, you'll need to use a variable as a Latch (holding reg) to fix the R-M-W issue.
    <br>
    Yes, TRISA =011X
    A.0 is only used for an LCD output for testing, and is normally necessary. I can live without it.

    Thanks
    James
    James

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Thumbs up

    Yes, TRISA =011X
    Ah Ha! Makes perfect sense now.

    You're "good to go".

    Cheers,
    DT

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  3. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

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