Re:Switch bouncing reference traces for a variety of differe...
by dtgriscom on Sunday May 04, 2025 @05:17AM
(#43885575)
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.
[ Parent
| on HN ]
Re:Switch bouncing reference traces for a variety of differe...
by lambdaone on Sunday May 04, 2025 @05:43AM
(#43885681)
I 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.
Re:Switch bouncing reference traces for a variety of differe...
by progbits on Sunday May 04, 2025 @05:24AM
(#43885593)
This is mechanical bouncing.
Re:Switch bouncing reference traces for a variety of differe...
by lambdaone on Sunday May 04, 2025 @06:50AM
(#43885954)
Real 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.
Re:Switch bouncing reference traces for a variety of differe...
by lambdaone on Sunday May 04, 2025 @06:56AM
(#43885981)
A 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.
Re:Switch bouncing reference traces for a variety of differe...
by progbits on Sunday May 04, 2025 @07:48AM
(#43886189)
Sounds 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.
Re:Switch bouncing reference traces for a variety of differe...
by dtgriscom on Sunday May 04, 2025 @01:22PM
(#43888025)
That'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.