Shop OBEX P1 Docs P2 Docs Learn Events
Button Debouncing Help/Clarification on Analog switch — Parallax Forums

Button Debouncing Help/Clarification on Analog switch

ShawnKimbleShawnKimble Posts: 4
edited 2012-03-01 18:53 in BASIC Stamp
I have a retro analog switch that I'm using as a button. I'm currently getting what appears to be a lot of noise, resulting in false positives, but I'm not really experianced enough to confirm that it's the problem.

I have two questions:

Can someone more clearly explain the Delay/Rate variables of the Button function? As I understand it Delay/rate gives you three options:
  • 0 = no delay, rate variable ignored
  • 1 to 254 * rate = ms delay
  • 255 = 255 ms with no rate multiplyer
Can anyone clarify where/why you would use logic state 1 vs logic state 0 wiring configuration on a button? I'm currently using state 1 in my setup on two buttons, one normally open and one normally closed.

While breadboarding I was able to get the circuit to work perfectly, but due to poor documentation and moving to circuiting, something has changed and I'm having trouble debugging what is going on.

Thanks!

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-03-01 08:21
    Shawn, welcome to the forum.

    I have a tutorial on the inner workings of the button command here: http://www.emesystems.com/BS2fsm.htm#BUTTON

    The command has both "downstate" and "targetstate" binary parameters, and those interact. That makes it hard to answer your question, "where/why you would use logic state 1 vs logic state 0 wiring configuration on a button?". You have to ask which is the pin state, 0 or 1 that corresponds to the pin being held down, and then you have to ask whether you want the target action to occur when you first press the button or when you release it.

    There are other possibly better ways to debounce a button, or two or more buttons.
  • ercoerco Posts: 20,256
    edited 2012-03-01 09:34
    Button or switch? Button implies that you want auto-repeat and all that.

    Debouncing a simple on/off switch is easier, you can add a small cap or modify your software to check its state multiple times.
  • ShawnKimbleShawnKimble Posts: 4
    edited 2012-03-01 10:13
    It is a momentary button. An old rotary pulse terminal to be more accurate.
  • ShawnKimbleShawnKimble Posts: 4
    edited 2012-03-01 13:32
    @ Tracy - Awesome write up. I will digest and report back. Thanks!
  • ShawnKimbleShawnKimble Posts: 4
    edited 2012-03-01 18:53
    @Tracy, using BUTTON set to 255,0 works for what I'm doing. The logic was 25% of my problem, the other 75% was my poor documentation on how the button worked, so I methodically sketched out the schematic of the rotary dial and now am using the proper pins with the proper logic. Thank you again for the write up, it does a great job clarifying what is going on with BUTTON.
Sign In or Register to comment.