5 ms·
Wow. I'm surprised they don't do this on the component level. When I was working in embedded, I considered software debouncing a lazy hack. I'd rather sanitize
by alar44 5y ago
Wow. I'm surprised they don't do this on the component level. When I was working in embedded, I considered software debouncing a lazy hack. I'd rather sanitize the data before it hits software.
- brokenmachine 5y agoThere's nothing wrong with software debouncing. Almost all fancy DIY exotic keyboards use software debouncing effectively. In fact it's more customizable for quicker response than hardware RC debouncing. There is, however, something wrong with shitty debouncing software.
- sannee 5y agoFirstly, hardware debouncing is a bit awkward to implement on a multiplexed matrix, since you need a debouncing circuit for each of your inputs (meaning about a dozen or so of them). More importantly though, software debouncing offers greater flexibility. For keyboards, you usually[1] want to implement an asymmetric "eager" mode, where a key press gets registered immediately and only the key release is debounced. Since software usually does stuff on the key down event, this works to reduce latency. [1] Well, that's what the various enthusiast mechanical keyboard firmwares do, I am not so sure that generic $random_corp keyboards do care...
- deleted 5y ago[deleted]
- halpert 5y agoIt looks like he keyboard state is read by the driver, rather than the keyboard sending the state to the OS. How would you denounce on a hardware level with such a setup?
- gridspy 5y agoOne way is a RC circuit - where the switch (the keyboard button) in series with a resistor then charges a capacitor. You specify the ratio of resistance to capacitance so it takes long enough for the switch to stop bouncing before the capacitor output rises to the sense level of your digital input. But if you want to reduce hardware cost, you can eliminate many capacitors and resistors by doing it in firmware instead.
- halpert 5y agoI’m not too familiar with hardware, but would you be able to differentiate between the unpressed state with such a scheme?
- alar44 5y agoOf course. Hardware debouncing came long before software. It's basic electronics. Many switches have it built in.
- gridspy 5y agoTypically in a 5v system you'd treat capacitor output voltages under 2.3V as pressed and over 2.3V as released. There is a "pullup" resistor and the switch is wired to "pull down" the circuit towards ground, through the mentioned resistor. Most Microcontrollers have the pullup resistor built in. Modern ones even let you turn the pull-up feature on and off per pin with a SFR (a special register /fixed memory address you can write to where you change hardware settings). Often you can also choose between reading a pin or driving it as an output. The most important thing to know about debouncing is that any hardware switch bounces from 50-200 times over a very very short interval when you press it. You can use an oscilloscope to see that. The bouncing is not as bad on release but I imagine it still exists there too. Another fun hardware trick is that when you turn off a magnet (like a relay) you can get a massive over-voltage pulse back (10x typical drive) for a moment. You need to protect yourself from that, for instance with a Schottky diode. Here's a discussion on that fun detail [1]. [1] https://forum.allaboutcircuits.com/threads/reduce-voltage-spike-on-relay-coil.184312/ https://forum.allaboutcircuits.com/threads/reduce-voltage-sp...
- alar44 5y agoYeah, I get where you're coming from, but a few dozen SMD caps and resistors ordered in that kind of bulk probably raises the cost by a penny. Of course you do technically have more points of failure I guess.
- baybal2 5y agoI had clients who were going to bargain for less than a penny