TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to Debounce a Contact (2014)

150 pointsby user_78324 months ago

19 comments

nickcw4 months ago
&gt; But some environments are notoriously noisy. Many years ago I put a system using several Z80s and a PDP-11 in a steel mill. A motor the size of a house drawing thousands of amps drove the production line. It reversed direction every few seconds. The noise generated by that changeover coupled everywhere, and destroyed everything electronic unless carefully protected. We optocoupled all cabling simply to keep the smoke inside the ICs, where it belongs. All digital inputs still looked like hash and needed an astonishing amount of debounce and signal conditioning.<p>:-)<p>I had a similar experience with a elevator motor and a terminal. The electronics worked absolutely fine, but when someone operated the elevator it occasionally produced phantom keypresses on the capacitive keypad.<p>This was perhaps understandable, but what really confused the users was that these phantom keypresses sometimes pressed the not fitted debug buttons (which weren&#x27;t on the production keypad) which stuck the device into debug mode!<p>We learnt not to include the debug code in the production firmware and beefed up the transient suppression hardware and the debouncing firmware to fix.
评论 #42635284 未加载
评论 #42638658 未加载
bambax4 months ago
&gt; <i>Years ago a pal and I installed a system for the Secret Service that had thousands of very expensive switches on panels in a control room. We battled with a unique set of bounce challenges because the uniformed officers were too lazy to stand up and press a button. They tossed rulers at the panels from across the room. Different impacts created quite an array of bouncing.</i><p>It&#x27;s impossible to guess how users will use a system until they can be observed in the wild.
评论 #42634242 未加载
khafra4 months ago
&gt; One vendor told me reliability simply isn&#x27;t important as users will subconsciously hit the button again and again till the channel changes.<p>Orthogonally to the point of this excellent article, I found it striking how this was probably true, once--and then TVs got smart enough that it took seconds to change channels, instead of milliseconds. And then it was no longer possible for input failures to be corrected subconsciously.
评论 #42637364 未加载
评论 #42635177 未加载
评论 #42638142 未加载
评论 #42632685 未加载
评论 #42633645 未加载
geerlingguy4 months ago
This is one of the best treatises on debounce, I&#x27;ve read it a number of times and probably will again.<p>One of the best things I&#x27;ve done to help with really bad debounce is spend time testing a number of buttons to find the designs that have, at the hardware&#x2F;contact level, much less bounce. Some buttons wind up with tens of ms of bounce, and it&#x27;s hard to correct for it and meet expectations all in software.
评论 #42636284 未加载
评论 #42633583 未加载
the__alchemist4 months ago
I&#x27;ve been using the perhaps-too-simple:<p><pre><code> - Button triggers interrupt - Interrupt starts a timer - Next time interrupt fires, take no action if the timer is running. (Or use a state variable of some sort) </code></pre> Of note, this won&#x27;t work well if the bounce interval is close to the expected actuation speed, or if the timeout interval isn&#x27;t near this region.
评论 #42635897 未加载
评论 #42637536 未加载
theamk4 months ago
Analysis is nice, although the graph style is very much 2005. The conclusion is that as long as you don&#x27;t get a crappy switch, 10mS debounce interval should be sufficient.<p>I would not pay much attention to the rest of the text.<p>The hardware debouncer advice is pretty stale - most of the modern small MCUs have no problem with intermediate levels, nor with high frequency glitches. Schmidt triggers are pretty common, so feel free to ignore the advice and connect cap to MCU input directly. Or skip the cap, and do everything in firmware, MCU will be fine, even with interrupts.<p>(Also, I don&#x27;t get why the text makes firmware debouncer sound hard? There are some very simple and reliable examples, include the last one in the text which only takes a few lines of code.)
评论 #42632128 未加载
ghusbands4 months ago
This is an interesting take on debouncing, but I found the choice of TV remotes as an example a bit confusing. From my understanding, the issues with remote controls aren’t typically caused by bouncing in the mechanical sense but rather by the design of the IR communication. Most remotes transmit commands multiple times per second (e.g., 9–30 times) intentionally, and the receiver handles these signals based on timing choices.<p>If there are problems like double channel jumps or missed commands, it’s more about how the receiver interprets the repeated signals rather than a classic switch debounce issue. There’s definitely a similarity in handling timing and filtering inputs, but it seems like the core issue with remotes is different, as they must already handle repeated commands by design.
评论 #42635143 未加载
dekhn4 months ago
I&#x27;ve been given a lot of suggestions for debouncing switches over the years. I&#x27;m just doing hobby stuff, either I have an endstop switch for some CNC axis, or more recently, some simple press buttons to drive a decade counter or whatever. My goal for one project was just to have a bit counter that I could step up, down, reset, or set to an initial value, with no ICs (and no software debounce).<p>I got lots of different suggestions, none of which worked, until I found one that did: 1) switch is pulled high or low as needed 2) switch has capacitor to ground 3) switch signal goes through a schmitt trigger<p>I designed this into its own PCB which I had manufactured and soldered the SMD and through-hole and ICs to that, and treat it as its own standalone signal source. Once I did that, literally every obscure problem I was having disappeared and the downstream counter worked perfectly.<p>When you look at the various waveforms (I added a bunch of test points to the PCB to make this easy) the results of my PCB produces perfect square waves. I found it interesting how many suggested hardware solutions I had to try (simple RC filter did not work) and how many &quot;experts&quot; I had to ignore before I found a simple solution.
kevin_thibedeau4 months ago
My test whenever I get handed someone else&#x27;s code with a debounce routine is to hammer the buttons with rapid presses, gradually slowing down. That shows if the filter is too aggressive and misses legitimate presses. I also see strange behavior when they&#x27;re implemented wrong like extra presses that didn&#x27;t happen or getting stuck thinking the button is still held when it isn&#x27;t.
评论 #42631691 未加载
user_78324 months ago
I saw this site in one of the comments on <a href="https:&#x2F;&#x2F;hackaday.com&#x2F;2025&#x2F;01&#x2F;04&#x2F;button-debouncing-with-smart-interrupts&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hackaday.com&#x2F;2025&#x2F;01&#x2F;04&#x2F;button-debouncing-with-smart...</a>
cushychicken4 months ago
Be sure to read Jack’s mega treatise on low power hardware&#x2F;software design if you haven’t yet.<p><a href="https:&#x2F;&#x2F;www.ganssle.com&#x2F;reports&#x2F;ultra-low-power-design.html" rel="nofollow">https:&#x2F;&#x2F;www.ganssle.com&#x2F;reports&#x2F;ultra-low-power-design.html</a><p>One of the best practical EE essays I’ve ever read, and a masterwork on designing battery powered devices.
Certified4 months ago
I&#x27;m a big fan of debouncing in hardware with the MAX3218 chip. It will debounce by waiting 40ms for the signal to &quot;settle&quot; before passing it on. This saves your microprocessor interrupts for other things. It also will work with 12 or 24 volt inputs and happily output 3.3 or 5v logic to the microprocessor. It is pricey though at $6-10 each.
评论 #42636629 未加载
评论 #42635377 未加载
评论 #42636390 未加载
评论 #42637165 未加载
matheusmoreira4 months ago
Wish I had known about this article last year when developers added debouncing to the Sensor Watch project. I had to learn a lot of this from scratch in order to review and merge in their changes.<p>I&#x27;m still running their code right now on my watch. It uses timers to allow the switch to settle before triggering input events. Dramatically improved its usability. Latency noticeably increased but without it interfaces which required holding down buttons simply didn&#x27;t work reliably.
评论 #42633339 未加载
slippy4 months ago
I read through a whole page, wondering when we are getting to legal stuff, before I went back and re-read the title. &quot;Contact&quot; not &quot;Contract&quot;....
roland354 months ago
I&#x27;ve actually never really had much issue with switch bounces - I think many modern microcontrollers have built in gpio circuits which seems to help with this.
persnickety4 months ago
What&#x27;s with the advice about interrupts and undebounced signals?<p>What does it mean that a flip-flop gets confused? What kind of undesired operation could that cause?<p>Because, quite honestly, if connecting directly means occasional transient failures, then having less hardware is a tempting tradeoff on small PCBs.
seoulbigchris4 months ago
I&#x27;ve used that article several times in the past. I&#x27;ll also note that many years ago, on projects which were not cost sensitive, we would often use the MC14490 IC for hardware debouncing (mentioned in part 2 of this article).
neuroelectron4 months ago
I just bought a horrible Lenovo keyboard with terrible debouncing. For some reason, it seems to only affect the vowels... is this sabotage?
评论 #42633048 未加载
denimnerd424 months ago
the evoluent vertical mouse I use has a notorious short lifespan because the switches aren&#x27;t debounced or aren&#x27;t debounced for a long enough period after only a year or two of wear. i demonstrated on an arduino that additional debouncing logic could fix the issue transparently to the user but never went further than that.