Debouncing switches

I made a little exercise out of compacting the example “switch debounce” code that the PIC tutorial examples uses. My next exercise will be to improve the debouncing in the “reverse variable speed LED rotation by pressing switch” by interleaving the debouncing check into the delay loop. As it stands, when the rotation is slow, the example can miss brief switch pushes.

My glorious savings of three instructions is documented on a separate page.

One nifty trick I found through Google that might be very helpful if I have to debounce 88 keys on a Symbolics keyboard (naturally, the same number as on a piano) is called “vertical counters.” This consists basically of replacing counter increments with boolean operations, which can be easily performed in parallel, if the corresponding bits for multiple counters are grouped in register-sized words.

This page shows how to use a four-count two-bit vertical counting scheme to debounce eight switches in parallel.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: