Subject:
|
software debouncing (was Re: touch sensors aren't just switches (was Re: ideas for a RIS 2.0
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Wed, 25 Aug 1999 22:00:36 GMT
|
Viewed:
|
587 times
|
| |
| |
> > One VERY easy method is to take successive samples at an interval
> > greater than the switch bounce (from the spec sheet for the switch)
> > and just make sure you have two identical readings before processing
> > it as a state change...
In lugnet.robotics, lego-robotics@crynwr.com (Jim Thomas) writes:
> [...] Debouncing multiplexed switches in software is more
> difficult than you proposed unless you make some limiting assumptions.
The way I debounce is by using a simulated RC network ("RC" stands for
resistor-capacitor). RC networks exhibit a "decaying exponential" response to
an input waveform. Here is an example of how to simulate an RC network:
averagereading = 0;
while (true) {
Sleep(1); /* take readings every 1/100 second */
rawreading = SensorInput();
/* The "+ 2" is for rounding */
/* Change "4" and "5" to "10" and "11" to make it respond more slowly */
averagereading = ((4 * averagereading) + rawreading + 2) / 5;
if (averagereading > THRESHOLD1) {
/* beep */
} else if (averagereading < THRESHOLD2) {
/* burp */
}
}
|
|
Message is in Reply To:
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|