{"id":8261,"date":"2015-07-15T09:15:04","date_gmt":"2015-07-15T16:15:04","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=8261"},"modified":"2021-06-16T16:14:23","modified_gmt":"2021-06-16T23:14:23","slug":"debouncing-circuits","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/debouncing-circuits\/","title":{"rendered":"Debouncing Circuits"},"content":{"rendered":"<p>Welcome back to the Digilent Blog!<\/p>\n<p>Pushbuttons are an inherent source of problems inside of sensitive circuits. Ideally, we like to think that when a button is pressed it is either &#8220;pressed&#8221; or &#8220;not pressed&#8221; without any sort of funny business. Unfortunately, as pushbuttons are a mechanical component, a lack of funny business simply isn&#8217;t going to be the case.<\/p>\n<p>Both mechanical buttons and switches have an inherent problem with bouncing. This phenomenon is exactly what it sounds like: after changing state (going from on to off or vice versa) there is small amount of literal bouncing that the component experiences. While the physical material is vibrating, the voltage level of the output is affected causing the transition edges from on to off to not be as clean as we would like. Various microcontrollers and FPGAs are fast enough to capture some of these fluctuations that occur in the few hundred microseconds when it is switching state.<\/p>\n<figure style=\"width: 480px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/learn.blog.digilentinc.com\/Documents\/chipKIT\/P07\/buttonbounce3.png\" alt=\"\" width=\"480\" height=\"234\" \/><figcaption class=\"wp-caption-text\">System boards will be able to capture some fluctuations before the actual change occurs. The yellow line is the button voltage state, the blue line is the measured digital logic reading. Image from <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/256\" target=\"_blank\" rel=\"noopener\">learn.blog.digilentinc.com<\/a>.<\/figcaption><\/figure>\n<p>If the bouncing has a large enough changes, the system board may interpret them as additional button presses, which is detrimental for some types of programs. Luckily for us, we can mitigate this problem by implementing a method known as debouncing. There are many potential ways to debounce a circuit through both <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/256\" target=\"_blank\" rel=\"noopener\">delaying software<\/a>, <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/257\" target=\"_blank\" rel=\"noopener\">a library<\/a>, or hardware via something like a <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/324\" target=\"_blank\" rel=\"noopener\">555 timer<\/a>, but what I will cover is using an RC circuit.<\/p>\n<p>An RC circuit utilizes a resistor and a capacitor to &#8220;smooth out&#8221; voltage changes. This works by the capacitor storing up energy when the button is pressed and then slowly releasing that energy when the button is released. The resistor is there to limit the amount of current flowing in the circuit, effectively changing what is known as the time constant, tau, \u03c4. Larger values of \u03c4, corresponding to both larger resistors and capacitors (\u03c4 = R * C), indicate that it will take longer for a capacitor to charge or discharge. In a practical sense, the larger values of tau show that any transitions that occur will be smoothed out for a longer period of time.<\/p>\n<figure style=\"width: 480px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/learn.blog.digilentinc.com\/Documents\/chipKIT\/P09\/bsignocap.png\" alt=\"\" width=\"480\" height=\"234\" \/><figcaption class=\"wp-caption-text\">This is what a button press looks like on an oscilloscope, but it&#8217;s not so clean looking if we zoom in&#8230; Image from <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/258\" target=\"_blank\" rel=\"noopener\">learn.blog.digilentinc.com<\/a>.<\/figcaption><\/figure>\n<figure style=\"width: 480px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/learn.blog.digilentinc.com\/Documents\/chipKIT\/P09\/bsignocap100x.png\" alt=\"\" width=\"480\" height=\"234\" \/><figcaption class=\"wp-caption-text\">A zoomed in view of what actually happens when a button is released. Image from <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/258\">learn.blog.digilentinc.com<\/a>.<\/figcaption><\/figure>\n<figure style=\"width: 480px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/learn.blog.digilentinc.com\/Documents\/chipKIT\/P09\/bsigcap.png\" alt=\"\" width=\"480\" height=\"234\" \/><figcaption class=\"wp-caption-text\">After we add an RC filter to our circuit, the button press waveform is a much smoother transition. Image from <a href=\"https:\/\/learn.blog.digilentinc.com\/Documents\/258\" target=\"_blank\" rel=\"noopener\">learn.blog.digilentinc.com<\/a>.<\/figcaption><\/figure>\n<p>While this all looks nice and theoretically helpful, when does debouncing actually come into play in our lives? One example is when you are pressing buttons on a TV remote. Nobody wants to press the mute button only to have the TV mute and then immediately unmute itself due to the button bounce, leading to awkward moments as you fumble with the remote. This is where debouncing comes in to save the day. By adjusting our resistor and capacitor values\u00a0we can ensure that the\u00a0changes will only be mitigated for an appropriate length of time,\u00a0so that buttons can be pressed multiple times in a row without any of the intentional transitions being missed.<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-8261 jlk' data-task='like' data-post_id='8261' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-8261 lc'>0<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-8261 jlk' data-task='unlike' data-post_id='8261' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-8261 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-8261 status align-left'>Be the 1st to vote.<\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Pushbuttons are an inherent source of problems inside of sensitive circuits. Ideally, we like to think that when a button is pressed it is either &#8220;pressed&#8221; or &#8220;not pressed&#8221; without any sort of funny business. Unfortunately, as pushbuttons are a mechanical component, a lack of funny business simply isn&#8217;t going to be the case.<\/p>\n","protected":false},"author":17,"featured_media":8313,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1563],"tags":[],"ppma_author":[4469],"class_list":["post-8261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/07\/buttonbounce3.png","authors":[{"term_id":4469,"user_id":17,"is_guest":0,"slug":"jamescolvin","display_name":"James Colvin","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/509febded809c5de0423909f6ae6587f?s=96&d=mm&r=g","author_category":"","user_url":"","last_name":"Colvin","last_name_2":"","first_name":"James","first_name_2":"","job_title":"Applications Engineer \/ Technical Support Engineer \/ Product Support Engineer \/ Technical Writer \/ the person to bother about T&M and JTAG when the senior design engineer is busy","description":"A local Digilent employee who is sometimes tricked into making other content besides documentation and supporting customers on the Digilent Forum, but then I get to write a little more informally so that's a plus. \r\n\r\nA sassy engineer, lover of puns and dad jokes, father and husband. \r\n\r\nI know both way too much and simultaneously almost nothing about a number of nerdy topics. If you want to hear me rant, ask me what data rate USB C operates at."}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/8261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=8261"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/8261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/8313"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=8261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=8261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=8261"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=8261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}