Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/08/09 09:45
Read: times


 
#163230 - Debounce and interrupts
Responding to: ???'s previous message
Switches and interrupts are rarely a good idea - firstly because of switch bounce and secondly by using extra interrupts.

The safer method is setup a timer tick to interrupt, say, every 10mS. In the timer tick interrupt you can sample the switch inputs. I usually shift the switch status into a variable and test for a number of consecutive '1's or '0's depening on the active state of the switch. If you get a number of active status in a row, then you can be pretty sure the switch is not bouncing. You can then also use the timer tick for other purposes in your program. Use an external interrupt if you need to wake the cpu from a sleep, but then disable that interrupt and start the timer tick.

Just a couple of 'rules':
1. minimise the number of interrupt sources. Less to go wrong.
2. keep your ISRs lean and mean - do only the bare minimum in them. No extended delays etc.

Be aware of atomic access of shared variables - interrupts can happen at any time, be sure you protect access to shared variables so that you stop or avoid interrupts happening whilst you're changing the variable.

List of 5 messages in thread
TopicAuthorDate
Interrupts not working            01/01/70 00:00      
   EA ?            01/01/70 00:00      
      YEah, i also activated ea.            01/01/70 00:00      
         do not retype ...            01/01/70 00:00      
            Debounce and interrupts            01/01/70 00:00      

Back to Subject List