View Full Version : Solved Looking for an expelation for strange behavior of tact switch.
09-21-2011, 01:06 PM
I don't know where to post this, so I decided to put it in general. Feel free to move!
So I got some tact switches (https://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/pushbutton/List/0/SortField/4/ProductID/203/Default.aspx) and I've set them up in a simple circuit for the Propeller Demo Board. Basically I've got a 10 kΩ resistor going from the VDD to VSS and the switch going from the resistor to a Propeller pin. The Propeller is programmed to turn an LED on when the switch is pressed.
Now comes the strange part: When I touch the metallic body of the switch with my finger, the LED turns on! I'm 100% sure that I'm not actually applying any force at the plastic switch, just touching the body.
Why would that happen?
09-21-2011, 02:07 PM
It sounds to me like your finger is injecting electrical 'noise': could you kindly post the exact code you are using, together with further details of the hardware.
There are easy circuit recipes that will enable you to make the hardware stable, then 'debounce' the switch in software sucessfully. Just give us a few more clues to work on ...
T o n y
09-21-2011, 02:07 PM
Your switch circuit is wrong. What is happening is that, when the switch is open, the Propeller I/O is floating ... not connected to anything. The Propeller I/O is a very high impedance, voltage sensitive circuit and your finger induces a voltage change in the I/O pin, probably from the power line voltages around you, possibly also some static electrical charges on your body. In any event, this causes the Propeller I/O pin to switch on.
The proper input circuit for a switch would have a 10K resistor from Vdd to the Propeller I/O pin and the switch from the Propeller I/O pin to Vss. You can also connect it the opposite way with the 10K resistor from Vss to the Propeller I/O pin and the switch from the Propeller I/O pin to Vdd.
09-21-2011, 02:10 PM
You say you have the resistor between VDD and VSS, really it is supposed to be going from the Prop pin to VSS to hold it to ground, or VDD to hold it up, depending on what you are driving it with. For example, if you have one end of the button connected to VDD the other end should have a 10k resistor to VSS and be connected to the prop pin. This works also in reverse. Without that pulldown, the Propeller pin is very sensitive to current. Since the body is conductive, I believe what is happening is that due to the lack of a proper pull up/pull down resistor the Propeller is detecting the slight current and reacting to it as if it was supplied with a switch. Of course, this is just a theory. I can't tell without pictures.
Anyway, put your resistor in the right spot and it should stop doing this.
09-21-2011, 02:12 PM
Mike must have posted while I was typing. Anyway, he verifies the statement.
09-21-2011, 02:22 PM
For a NO switch:
pull down on the left, pull up version on the right.
R= 10k to 470k, if battery operated curcuit and switch stays closed for longer lenghts use 100-470k.
Think of it as water:
when the switch is open, the line will eventually fill up (pull up version) a larger resistor and it takes longer.
When switch is closed the water in the line connected to the prop empty's out fast,
much faster than the water coming in through the resistor. so now you get your zero state.
09-21-2011, 08:18 PM
Thanks a lot guys, you're great!
I can't believe I made such a beginner's mistake and did not notice it until now.
I fixed the pushbutton circuit and did some debouncing too, so it works fine now.