5 ms·
The big question is whether there are spurious transitions from noise or EMI. Generally, the pull-up or pull-down is strong enough so that, except while switchi
by dtgriscom 1y ago
The big question is whether there are spurious transitions from noise or EMI. Generally, the pull-up or pull-down is strong enough so that, except while switching, the raw signal will stay reliably high or reliably low. If this is true, then you can act as soon as you see the first change in the raw signal. Then you have a time constant before you will consider a change in the opposite direction to be valid. That way, no matter how quickly the user taps a button, you will a) act as soon as possible, and b) not miss a tap.
- progbits 1y agoThis is mechanical bouncing.
- lambdaone 1y agoReal environments have both mechanical bouncing and unavoidable EMI spikes, even when you have done your best to eliminate EMI; particularly when you're dealing with switches, which are typically on the end of long wires which are effectively antennae. Source: actual experience with crappy real-world systems.
- lambdaone 1y agoA side-note: I have a friend who is an electronics genius who managed to construct a production system that combined a multi-kilowatt electric arc lamp and a CCD array. Microvolts of CCD signal at megahertz of bandwidth mixed with hundreds of watts of RFI all in the same chassis. Oh, and of course lots of low-jitter digital timing and sequencing electronics and wideband ADCs. It all worked perfectly. He used every trick in the book, and some new ones he invented from scratch, to implement it - I've never seen anything like it, before or since.
- progbits 1y agoSounds fascinating, can you share what it was for? Regarding your parent message, I agree, but the EMI stuff will depend on lots of other factors and so you will have to do your own modeling / measurements. While the mechanical bouncing should be pretty uniform so this is a nice data source for picking a well behaved switch and designing debouncing network. Of course I'm just realizing this is N=1 for the switch so hard to say what manufacturing tolerances each one has.
- dtgriscom 1y agoThat's overly broad. I do embedded development, where the unit has a metal box and the button is plastic. You'd have to deliberately hit it with a spark generator to cause an unexpected transition, and having the button register an unexpected transition isn't a big deal. Worse would be to have overly-enthusiastic debouncing that slows down the user interface, making the unit annoying to use.
- lambdaone 1y agoI do something very similar, but use two time constants. One to determine how many consecutive samples are needed to change from the established state, and a second one, as suggested here, to ignore subsequent input for a bit after a registered state change to allow for bouncing before going back to the receptive state. This is a bit more robust, as practical systems are always at the mercy of occasional glitches in electromagnetically noisy environments. With well-chosen constants, I've found similar behaviour to the above; low latency and high performance at once.