Shop OBEX P1 Docs P2 Docs Learn Events
Looking for an expelation for strange behavior of tact switch. — Parallax Forums

Looking for an expelation for strange behavior of tact switch.

AndrejaKoAndrejaKo Posts: 24
edited 2011-09-21 13:18 in General Discussion
Hi!

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 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?

Comments

  • TonyWaiteTonyWaite Posts: 219
    edited 2011-09-21 07:07
    Hi Andreja,

    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 ...

    Regards,

    T o n y
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-21 07:07
    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.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2011-09-21 07:10
    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.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2011-09-21 07:12
    Mike must have posted while I was typing. Anyway, he verifies the statement.
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-09-21 07:22
    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.

    PullDownUp2.jpg
    http://vimeo.com/1133329
  • AndrejaKoAndrejaKo Posts: 24
    edited 2011-09-21 13:18
    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.
Sign In or Register to comment.