Implementing Debounce logic for Push button

Discussion in 'Programmer's Corner' started by RaviKumar.N, Feb 15, 2006.

  1. RaviKumar.N

    Thread Starter New Member

    Nov 24, 2005
    Hi All,

    I am Raviumar.N. I have used push buton in my application.

    The push-button is connected to INT0 of the 8051 microcontroller. The moment push-button is presssed, INT0 will be fired and the corresponding work will be done within the ISR.

    When the Push-button is pressed once, the interrupt has to fire only one time. But, for a single press of the Push-button, the ISR will be executed will be executed 'n' times.

    This 'n' may vary between 20 - 40 times.

    Please provide me the solution for this.

  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    Disable the corresponding interrupt to prevent re-entrant. Enable it back once the button has been released after down for a preset amount of time (button register time).
  3. beenthere

    Retired Moderator

    Apr 20, 2004

    Just to expand a little - always disable all interrupts as soon as one is detected. Handle the interrupt, and then, at the last step, reenable interrupt handling. To save some other possible headaches, you might also locking out the button input until it has been inactive for some tens of milliseconds. A good design in an interface will pass only one interrupt signal per input, whereas your button can stay down for a long time in computer terms.
  4. chesart1

    Senior Member

    Jan 23, 2006

    You could design a one shot circuit that sends a single pulse to the 8051 each time the push button is depressed. Another words, your one shot will react to a rising or falling edge rather than a level.

    One idea would be to design the one shot circuit so that the interrupt occurs when the push button is released. This would solve the problem you described in your message.

    One additional suggestion. If both your main program and your interrupt servicing routines are modifying the same RAM location, you could run into some strange problems.

  5. manish girase

    New Member

    Mar 9, 2006
  6. manish girase

    New Member

    Mar 9, 2006
    Use small RC network along with diode and transitor to int. signal .
  7. windoze killa

    AAC Fanatic!

    Feb 23, 2006
    No it won't. If you have bounce in the push button switch you will see that falling edge many times. All the one shot will do is be a buffer to the switch.