element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Bouncing and debouncing
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jlangbridge
  • Date Created: 3 Jan 2017 4:01 PM Date Created
  • Views 4478 views
  • Likes 9 likes
  • Comments 16 comments
  • bounce
  • mcu
Related
Recommended

Bouncing and debouncing

jlangbridge
jlangbridge
3 Jan 2017

I’ve been teaching students of all ages, from 8 years old to adults, and one of the most common things I’ve heard is about bouncing. Sooner or later, we are faced with this rather simple problem, so what causes it, and what can we do?

image

 

Let’s start off with a simple schematic. Press the button, and VOUT goes to VCC. Release it, and it goes back down to GND, through the pull-down resistor.

Counting sheep

 

In theory, nothing could be simpler than a switch. Make an electronic connection, press the button, and here we go. The microcontroller will notice an “edge” (the change of voltage to/from VCC and GND), and act accordingly. The problem is, it is never that simple. I asked some students to wire up a simple switch, and to count the number of presses. Initially, they looked at me as if I had underrated their capabilities, but it was a trick question, and it didn’t take long before they had questions. Hey, but I only pressed once, how come the microcontroller said I pressed two, three times? (and in one case, up to seven times). They then went through the code, looking for problems. The problem wasn’t the code, it was mechanical.

I did the same thing at home, only this time I connected an oscilloscope. This is what I got when I pressed the button:

image

 

You can see where I pressed the button, the voltage jumps from 0V to 2V. However, it looks like I pressed it twice; 40µs later, it goes back to zero, and after 50µs, it goes back to 2V. My microcontroller is fast enough to notice, and so it counts two presses. This isn’t the worst I’ve seen; some of the cheaper push buttons can bounce 6 or 7 times.

Bounce, a definition

To understand how this is possible, you need to imagine what a switch actually is. It is mechanical, and so it has all the advantages, and disadvantages associated with that. Imagine two metal connectors, and a metal plate on top. When the button is pressed, the plate comes down, and makes an electrical contact. Just like when you drop a metal ruler on the floor, the plate will “bounce” slightly, so as the plate hits the contacts, it might bounce slightly, before settling down.

So, what can you do about it? Thankfully, there are several solutions.

RC

Electronically, you can add a resistor-capacitor to slowly charge and discharge. This will add a small delay to your circuit, the time it takes for the capacitor to charge up.

image

 

The 74xx14 Schmitt inverter will detect a voltage above a certain level as a logical one, and invert it to zero. Likewise, a voltage below a certain level will be detected as a logical zero, and inverted to one. By adjusting the resistor and capacitor values, the capacitor charge time can be changed, filtering out unwanted bounces. Likewise, when the switch is released, the voltage is discharged through a resistor, removing bounces.

Dedicated electronics

There are devices that are dedicated to debouncing switches and pushbuttons.

image

 

In this example, an MC14490 is used. It has internal pull-up resistors, so no external components are required. The capacitor C2 is used for the internal oscillator, and apart from that component, no other components are required. The only down side to this situation is the price of the component itself; around 5€ per component, but each one can debounce 6 switches.

Programming

If the microcontroller is fast enough to actually see multiple bounces, then it is also fast enough to be able to debounce them. There are two philosophies; act immediately, or act when sure.

If the exact timing is critical (as in less than a millisecond), then the program must register the first edge, and then ignore subsequent edges for a small amount of time. This is also the technique to use if your application is using interrupts. For an Arduino, you can register the time of the first edge using the millis() function, and then compare subsequent edges to that value.

If polling, there are two options. One is to register the first change of state, and to ignore subsequent states, the second is to validate a state change after a certain time. This has the advantage of filtering very brief pulses. Again, both can be done using the millis() function.

The wrong way

A third technique I’ve seen, and not the recommended way, is to simply poll less often. Imagine a push button on a breadboard. If you press the button for a second, and poll ten times a second, there is a very good chance you will never see any rebounds. Now, try to push that button as many times as you can in a second. How many times? 5? 10? Let’s say 10, even if I can’t do that personally. So, the output will be on for around 500ms, and off for 500ms. Ten pushes, so on for 50ms, off for 50ms, etc. If you poll every 10ms, the statistically, you should be fine. The down side is that this technique adds a high level of latency, and does not guarantee that you won’t be victim of very bad bouncing.

  • Sign in to reply

Top Comments

  • dougw
    dougw over 8 years ago +3
    Good topic, my first system failure was due to switch bounce. I wish someone had explained it to me earlier. I prefer to use a double throw switch whenever possible because it can be debounced quickly…
  • jc2048
    jc2048 over 8 years ago in reply to dougw +3
    Here it is from the "RCA COS/MOS Integrated Circuits" databook from 1975. This is from one of the application notes at the back. Theirs is the other way up with a pair of NOR gates, the switch goes up…
  • D_Hersey
    D_Hersey over 8 years ago +3
    This is the mercury delay-line memory from the Univac 1
  • D_Hersey
    D_Hersey over 8 years ago

    image

    This is the mercury delay-line memory from the Univac 1

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jc2048
    jc2048 over 8 years ago in reply to jc2048

    Found an example of the NAND version used with TTL.

     

    image

     

    This is from the Intel Memory Design Handbook, again from 1975 (must have been a vintage year for databooks).

     

    Here's what a state-of-the-art 1 Mbyte memory looked like in the early '70s. It used 1k bit DRAMs, which is why there are so many circuit boards - must have cost a small fortune. The organisation was 128K x 72.

     

    image

     

    And here's a photomicrograph of a chip. This is a 1kbit DRAM (designed in 1972 according to the copyright on the die). You can sit and count the DRAM cells (32 columns and 32 rows) - it would take forever if you tried to do that with a DRAM now.

     

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 8 years ago in reply to D_Hersey

    counting to a threshold you will both debounce and runt-reject

    Done a version of that as well.

     

    It suits some applications, but if you're introducing a newbie ( I’ve been teaching students of all ages, from 8 years old to adults ), then it can be a little hard to grasp.

     

    Like most things in software there are multiple ways to do something and not all of them are right or wrong.

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 8 years ago in reply to jc2048

    I might have to dig out some of mine ...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • D_Hersey
    D_Hersey over 8 years ago

    Well, I think using a DPST and a F/F for debouncing is timeless.  We should scan these old databooks and put them in an archive, IMHO

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube