PDA

View Full Version : Can you use the same pin as input/output and control led load?



FromTheCockpit
- 13th August 2013, 23:42
I want to confirm if one pin can be an input and later when needed can be made an output and high/low as needed?

It's just that when an input, it will have 2.5 volt on it through a voltage divider and then I want to inject 5V into the middle point of the voltage divider by making pin an output and toggling it high.

I am concerned if the pin can be made an output from an input and pushed high, while it already has 2.5v on it continually.

Normnet
- 14th August 2013, 01:51
You can safely toggle a pin high with the output wired to ground or toggle a pin low with the output wired to high as long as their is a 1K resistor (and probably smaller) between the PIC and the wired to high/low.


Norm

LinkMTech
- 14th August 2013, 01:54
Sure. As long as your voltage divider impedance is not too low and if my math isn't too far off...

Suppose the voltage divider is two 2K Ohms in series for the 2.5V, then the PIC's (approx.) internal 200 Ohm series resistance sourcing 5V will get you a little over 4.5V at the output.

But if it's two 200 Ohms in series then the output would only be about 3.3V.

FromTheCockpit
- 14th August 2013, 09:13
I think it is better to upload what is in my mind.

LinkMTech
- 14th August 2013, 16:37
To answer your question and your concern,
Yes, you can monitor that circuit then switch to an output without over driving it.

comwarrior
- 15th August 2013, 00:51
I believe most pic16's and PIC18's have a 20mA source or sink limit so a resistor on the pin would not be required.
So FromTheCockpit's diagram above will work, though you will not get 5V to feed the LED so you'll need to trim the LED's resistor if you want a brighter LED.

Also on that note... an LED consumes more than 20mA (~33mA at desired voltage i believe) so... you may not need a resistor on the LED. Instead, if you up the voltage divider resistance values ~ 2K each the LED would not come on but you would still have your /2 voltage divider.

Charlie
- 15th August 2013, 09:28
What are you trying to accomplish with this circuit?
Is the objective to have the LED on dimly and be able to confirm it has not failed, then be able to have the PIC turn it on brightly or off completely?
Is the PIC also powered by 5V?
If so, R3 does not serve any purpose...