| ??? 08/09/03 02:05 Read: times |
#52326 - RE: software debouncing (alternative) Responding to: ???'s previous message |
Working with rapidly pressed microswitches, I've also developed this alternative - it uses a combination of the interrupt and timer, though... This example, btw, is using the falling edge of the pin for int0, and is designed for a 1ms timer.
(section of interrupt code - all in pseudocode) 1 - do whatever actions you need for each buttom press 2 - disable int0 (or whatever interrupt this is) 3 - 'mov' the number '5' (decimal) into IntDisCount 4 - reti (section of timer) 1 - if button is low, move '5' into IntDisCount 2 - if button is high, dec IntDisCount (DJNZ) 3 - Set the DJNZ to jump to 5 4 - re-enable Int0 5 - reti This way keeps the interrupt disabled until the button "stabilizes" in the open state for 5 milliseconds. You can increase it if necessary, but the microswitches I used worked great at 5 :) This has major advantages in my application - The code is not "tied up" with the debounce routine - you can continue to monitor other operational functions while still debouncing :) . It eats nearly no cpu time, and requres very little in the way of code space. Also, it's very 'fast' - if the switch stabilizes, you could potentially be ready for another push 5 milliseconds after the button's release :) |
| Topic | Author | Date |
| software debouncing | 01/01/70 00:00 | |
| RE: software debouncing | 01/01/70 00:00 | |
| RE: software debouncing | 01/01/70 00:00 | |
| RE: software debouncing | 01/01/70 00:00 | |
| RE: software debouncing | 01/01/70 00:00 | |
| RE: software debouncing | 01/01/70 00:00 | |
| RE: software debouncing | 01/01/70 00:00 | |
RE: software debouncing (alternative) | 01/01/70 00:00 |



