Hi all
Does anyone know how to read a switch connected to a port pin on 18f4550 (active high).
eg: switch is connected between port pin and +5v
without using an external pull-down resistor
Hi all
Does anyone know how to read a switch connected to a port pin on 18f4550 (active high).
eg: switch is connected between port pin and +5v
without using an external pull-down resistor
Reading the datasheet & understanding it are two different things.
Not recommended. A pin will 'float'... sometimes it might acquire a charge from internal capacitances and over a period of time you will read a High when earlier it was a Low.
Use internal Pull-Up's where available and pull down with a switch externally for minimum component count. Try not to wire +5v to things like Switches and Sensors... especially if that same +5v supplies your PIC or other Logic... all you're doing is asking for noise to be induced into your Power Supply circuits which could then cause you grief elsewhere.
Hi Melanie
Thanks for your reply, could you please elaborate on a couple of things ?, I'm not sure what you mean about pulling down externaly with a switch ?,
What im trying to do is have a switch with just 2 wires connected that can work active high or active low. (without resistors)
This project is a kind-of one chip does everything scenario, and so I cant use resistors, will it damage my pic if i put +5 to a pin ?.
Thanks
Reading the datasheet & understanding it are two different things.
Somehow I get the feeling you could do with some basics...
DIGITAL only has two states, On or Off, High or Low, 1 or 0. That's why we call it Binary.
A PIC pin when used for DIGITAL can only have two states... High (or 1) or Low (0). 1 or Zero that's all you got. There's no 'in-between', no half-way or part way. Your choice is 1 or Zero. That's it - no other choices. This is also why everybody does DIGITAL and very few people do ANALOG. Because with DIGITAL life is easy. You learn 1 and you learn Zero and that's it - you're a computer expert because there's nothing else to learn.
This means one of two things...
Scenario A. You preset the PIC's pin with a HIGH (ie set it to a Logic 1) and you do this by pulling it UP to +5v via a Resistor (say 10K for arguments sake). This pin is normally now sitting at +5v (Logic 1 or High). You connect a pushbutton or switch between the PIC's pin and Ground (0v). When you push the button, you short that pin down to 0v, forcing it LOW. You need a Resistor, because otherwise you'll be shorting the +5v Power Supply out! Lots of PICs have pull-up Resistors inside them on many of their pins which can be switched-in to do the job and save you from providing one externally. So here, with the switch being OPEN-circuit, the PIC sees a HIGH (Logic 1) on it's pin, and when you press the Button the PIC sees a LOW (0) on it's pin.
Scenario B. You preset the PIC's pin with a LOW (ie set it to a Logic 0) and you do this by pulling it DOWN to 0v via a Resistor (say 10K for arguments sake). This pin is normally now sitting at 0v (Logic 0 or Low). You connect a pushbutton or switch between the PIC's pin and Supply (+5v). When you push the button, you connect that pin up to +5v, forcing it HIGH. You need a Resistor, because otherwise you'll be shorting the +5v Power Supply out! PICs don't carry internal pull-down Resistors inside, so you need to provide one externally. So here, with the switch being OPEN-circuit, the PIC sees a LOW (Logic 0) on it's pin, and when you press the Button the PIC sees a HIGH (1) on it's pin.
You CANNOT leave a PIC pin 'floating' unconnected. This is because the pin can acquire a charge (or discharge) and set the pin HIGH or LOW or even flicker between the two - which is kinda defeating what you want the pin to do if you can't even predict what state it is going to be in at any point in time. You pull it LOW with a switch and it might stay there when the switch is released, then some time later it might float High. You pull it High with a switch, then it might stay there forever after you release the switch - again not what you want it to do.
And in answer to your question - No, you won't damage a PIC's pin (when it's set for INPUT - TRISx=1) by connecting it directly to +5v or to 0v.
Hi Melanie
Its not realy the basics i'm after, Im looking for what seems to be an advanced answer.
I am simply asking if it is possible to get an active high input on a pin ? using any method whatsoever without the need for an external pull-down resistor?.
If the answer is no then thats fine, but all I seem to be getting is ambiguous replies or lectures that dont answer my question.
I had one person that told me to look at the 18f4550 datasheet (which I already had done), he didnt even look himself before making a reply :-(.
I've thought of a simple workaround to the problem myself (although not ideal), have a changeover switch that has the common as the pic pin and the changeover contacts as 0v and +v.
I dunno Melanie I love pic's etc and just do it for fun, but It feels a bit like a bit of a club on this website, and asking for help on hear is hard work, I feel like a noob again. :-(
Reading the datasheet & understanding it are two different things.
But then that is THREE wires and you specified two a couple of posts ago. But yes, that'll work providing your switch is the break-before-make type otherwise you'll be shorting out your +5v line.I've thought of a simple workaround to the problem myself (although not ideal), have a changeover switch that has the common as the pic pin and the changeover contacts as 0v and +v.
Without external components, your simple answer is NO.I am simply asking if it is possible to get an active high input on a pin ? using any method whatsoever without the need for an external pull-down resistor?.
Thanks Melanie
Like I said the change over switch idea is not ideal, but I cant think of anything else just off hand.
If there is no way to do it by programing the pic then that only leave's phisical methods, hmm, gonna have to give this project some more thought before deciding if it is viable.
Thanks very much for taking the time to reply :-).
Reading the datasheet & understanding it are two different things.
Bookmarks