View Single Post
  #4   Spotlight this post!  
Unread 30-01-2013, 12:48
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: LimitSwitch as Command Button

Quote:
Originally Posted by notmattlythgoe View Post
My only worry is getting multiple triggers with one press from noise on the channel. We're trying to implement a frisbee counter that count frisbees coming in and leaving the robot. We tried using the Counter class, but we kept getting random increases in the count from the limit switches. I'm assuming there was noise as the switch was pressed which made it think that there were multiple presses.
The counter class acts as an interrupt and counts every single edge of the switch bounce, which isn't what you want.

The simplest method for dealing with switch bounce is to poll the switch slower then the duration of the switch bounce. This works as long as the process actuating the switch is "slow", which my guess is that a frisbee counter is. For example, if the switch bounces for 10ms, polling it every 20ms will give you at worst one reading during switch bounce. If you happen to sample low during the bounce, you're reading of the switch will be delayed 20ms (the next sample will be high). If you happen to sample high during the switch bounce, you will react immediately (and the next sample will be high). If you extend button to read the switch, it would automatically get called at 20ms.

The following paper has lots of examples of switch bounce, as well as examples of both hardware and software debouncing, if you determine you do need to debounce. http://www.eng.utah.edu/~cs5780/debouncing.pdf

If you extend Button, you could implement your debouncing algorithm in get method.
Reply With Quote