Pushbuttons + Microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by MikeD_72, Jun 10, 2009.

  1. MikeD_72

    Thread Starter Active Member

    Nov 11, 2008
    46
    0
    Hi all,
    I am designing a fairly simple microcontroller-based system with about 5 momentary pushbuttons triggering interrupts. I haven't ordered my parts yet, so I was wondering: what kind of circuit do I need to debounce the pushbuttons?

    I thought that shunting a capacitor between the button output and ground would do just fine, but what happens when the pushbutton is released? Does that pin stay high, or does the capacitor discharge through the microcontroller pin? I would like the pin to go low as quickly as possible.

    Thanks,
    Mike
     
  2. StayatHomeElectronics

    Well-Known Member

    Sep 25, 2008
    864
    40
    I would place a resistor in series with the push button as well, that will give you a more controlled charge of the capacitor and not such an inrush of current.

    A resistor in parallel with the capacitor can help discharge the capacitor along with the INPUT pin. The values of resistance must be chosen so that the voltage divider created will still register as HIGH when the button is pushed. Adding this resistor will also slow down the registering of HIGH by the micro-controller since the capacitor charge will not happen as quickly. Try without the parallel resistor first to see if the time is acceptable for your application.
     
  3. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    Disable your int for some delay to debounce. Depending on your device, you may have to do a read loop to read the key release.
     
  4. MikeD_72

    Thread Starter Active Member

    Nov 11, 2008
    46
    0
    I can't do a software delay because my application is timing-critical.

    StayatHome, thanks for the suggestion. I may end up doing that if I don't come up with any other solution.


    I also came up with my own idea (see attached schematic). I haven't learned much about transistors, but would this circuit work?
     
  5. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,685
    900
  6. MikeD_72

    Thread Starter Active Member

    Nov 11, 2008
    46
    0
    Thanks S.H.E, I managed to work out some values that made your suggestion work. Circuit attached. The diode is only applicable to the one toggle switch I have in my design. When that capacitor is charged and another pushbutton is pressed, the diode causes the capacitor voltage to drop less during the transient than if it were not there.
     
  7. Steve C

    Active Member

    Nov 29, 2008
    86
    0
    If your micro can handle the software, I suggest software debouncing. Reason being, as a SUPER amateur I demand my circuits have the fewest number of components possible, figuring there are very, very few situations where less isn't more.

    found this resource months ago and found it VERY informative, even for an amateur like myself:

    http://www.ganssle.com/debouncing.pdf

    --------

    Just reread the thread, and I think software is definitely the way to go. Because it's timing critical, I don't think 20% capacitors are gonna give you more stable debounce timing than the software solution. Just because it's hardware doesn't mean there isn't delay!
     
  8. axeman22

    Active Member

    Jun 8, 2009
    53
    0
    I'll weigh in and try my best to give back to the forum which has been helping me so much of late!

    what you're doing is exactly (I think) what I've just done with a PICAXE controller kit. Take a look at this PDF file and see pin 4. When you press the push button the pin is raised to 4.5V but when you let go the pull down resistor brings it basically down to 0V, dead easy.. from a programming perspective you can easily program the PIXCAXE to sense if the pin is logix high or low.

    hoep that helps..
     
  9. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    The fact that you are using an interrupt, will almost surely debounce the switch on it's own. Jumping to the vector, disabling that interrupt, executing your routine, flipping the interrupt level to read a release, then re enabling your interrupt is likely going to happen anyway. Setting this to a lower priority won't affect any timer interrupts.
     
Loading...