De-bounce a contact
I'm using a Propeller pin to monitor a signal that goes from +5V to ground at a frequency of about 5 Hz to a maximum of 23 Hz, square wave. I'm using a Negedge counter to count the number of times per second this is occuring, but I'm having some trouble. I get the correct answer and then suddenly I get nonsense - sometimes a really high count or sometimes a very low count. I'm thinking it has something to do with the way the signal is being generated. I know when I try grounding the pin by hand, I will get wild fluctuations in the reading of the Negedge counter; one time it will be 3 and the next second it will be 12645 or some other wildly fluctuating value. I think I'm experiencing some kind of bounce on contact closure. What can I do to filter this out given the 5 to 23 Hz signal that I'm trying to pick up?
Comments
Daniel
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Here is a picture of my current setup. The stamp pin is suppose to float to 3.3 V (sorry I had previously written 5V) and the diode is suppose to protect it from the evils of the outside world. The black box is grounding the line at a frequency of 5 to 24 Hz.
Can someone help me modify this circuit to be well-behaved?
Formally, you should characterize your switch mechanism's bounce (you can have contact open bounce as well as closure bounce), but it would seem that a debounce filter on the order of 5-10 ms might be a good starting point.
You will also need to take into account your mechanism's pulse width--you do not want your filter to take too long to react so as to miss the pulses.
You should also consider using a software filter, so you can take advantage of recognizing the first edge of the bounce--the Ganssle article covers the software principles involved. They are adaptable (with sufficient effort) to any processor.
Daniel
It is nice to do the debounce in hardware, so you can continue use the NEGEDGE mode of the counter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for the suggestion. It worked well.