I’m using a momentary push-button type switch hooked up to INT0 pin of an ATMEGA168. I want this switch to put the AVR into sleep mode and wake it up. This would be much easier using a latching type, however my application calls for a momentary switch for this task. The pins are held high until pulled low when the switch shorts.
The problem here is that I can’t use the normal “polling” methods since I might miss some buttons being pushed.
I thought about disabling the interrupt when it is fired, do whatever it supposed to do and start a hardware timer (CTC or overflow) that will call an interrupt that will enable the interrupt after 250ms or something like that. This way the main code can continue to run and the counter won’t be executed while in the ISR.
The problem is that even when I disable the interrupt, a single request will be put in the stack by the AVR (please correct me if this is more than one call, since this is the entire idea behind my code) when the interrupt will be enabled again, the interrupt will fire because 100% the switch will bounce at least once. So to solve this I can define a char variable that will act like a boolean variable. When the AVR starts up, this variable will be: enable=1. When the interrupt will fire it will check if enable=1, if so it will run the interrupt and will change enable=0. After the interrupt will be enabled again, after the counter counted to 250ms, it will fire 1 more time but enable=0 so it won’t do anything other than setting enable=1 so the next time the interrupt will fire it will run the required code.
Any thoughts on this, suggestions?