Key state machine

All electrical contacts exhibit some degree of bounce, which is a brief intermittent contact at the make/break point. Reed switches often close in under a millisecond, but others can take 10 msec or more to stop bouncing. And it’s conceivable that the wiping action of the silver wire contacts could generate bounce as a key is being pressed or released. As I intend to poll the manual keys & pedals every millisecond, it’s important to detect and handle bounce, lest it lead to excess MIDI traffic and unnecessary taxation of the Hauptwerk machine. Below is the debounce state machine I’m using in the polling software. The gist is that a single key transition won’t lead to a MIDI note on/off message; rather, two consecutive polls must agree before the transition is complete. This scheme adds an acceptable 1 msec of latency. Bouncing is still possible with such a simple state machine, but MIDI-OX has detected virtually no bounce in my early tests, and I’m unwilling to add additional latency.


This entry was posted in Uncategorized. Bookmark the permalink.