PG1

Best Way to Use Asynchronous KBI ISR to debounce

Discussion created by PG1 on Nov 3, 2011
Latest reply on Nov 4, 2011 by bigmac

I need to detect key presses from tactile switches which are likely to bounce for milliseconds. I only need to detect presses (not releases) and do not have to measure how long the key is down.

 

I am looking for the easiest way to implement debouncing.

 

Here is what I came up with

 

1. Initially all 4 switch inputs to the KBI module can trigger an interrupt using edge detection only.  When one or more switches is pressed, the ISR is called.

 

2. The state of all 4 switch inputs are read, and global flags (contained in one byte) are updated to indicat which key(s)  is (are) pressed. This occurs in the ISR. Higher level routines can use this flag and reset it.

 

3. Any key that is pressed will be masked off so it can cause another interrupt. A software timer associated with that key is started. This occurs within the ISR. In this case there will be four software timers

 

4. The KBI is ack'ed and the ISR returns.

 

5. If a software timer associated with a certain key times out, that key input is un-masked  so that it can cause another KBI Int to occur.

 

 

Is there a simpler or better way?

 

Thanks.

Outcomes