I agree with you, don’t let it discourage you from embedded hardware. If you want to be successful in the embedded space, though, this is a great easy example to show that you need to take into account a bunch of physical effects when you’re doing hardware. Capacitors change their value with temperature and applied voltage (!), resistors have capacitance and inductance (which may or may not matter), clock crystals change frequency with temperature, switches bounce, ADCs have sampling capacitors that need to charge, chips power themselves up from active-high TTL lines, etc.
I’ve been doing embedded for 20 years now and one of the biggest things I’ve encountered with new learners is that the Arduino platform is amazing for people to get into the field but they’ll hit a point where something mostly works and they don’t have the rest of the background necessary to debug or understand why it doesn’t work as well as they thought it would. Or works great and then “randomly” blows fuses/burns out of there isn’t a fuse.
The MCU already has schmitt trigger inputs (handles hysteresis). And it also has a high value pull up resistor. The tiny capacitor from input to ground complete the low pass filter.
When you press the button, it quickly empties the capacitor to ground. Because it is so tiny, combined with the intrinsics parasitic resistance, this is a small enough EMI for hobby work.
The MCU input will register the state change right away, the pull up resistor will slowly recharge the capacitor (we talking a few dozen of milliseconds here). The schmitt trigger will handle the transition cleanly.
Nothing to do in code. Interrupts just work as expected without anything special. I think it's worth it.
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.
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.
With well-chosen constants, I've found similar behaviour to the above; low latency and high performance at once.
However, these traces look more chaotic.
Anyone know why?
A good switch will decouple your finger from the contact by some nonlinear/bistable linkage, so once you accumulate a fixed amount of travel distance it will snap the contacts with the same speed/force. But of course even that isn't perfectly decoupled nor perfectly deterministic.
Traces were highly predictable if you pressed it just gently past the detent. But if you did it too slowly (restricting the detent force) or used too much follow through (adding to the detent force) the result was very chaotic. Sometimes you could get the bounce period to extend by 10x if you took enough samples.
And if there’s too much current or other problems i saw decent ground and supply bounce too. That definitely makes it toucher to measure the behavior- in some respects a diff or current probe gave even more interesting results.
formerly_proven•7mo ago
It’s worth pointing out that due to the x1 probe there’s an input capacitance of about 50-60 pF, which would result in a 200 kHz low-pass for opening and dampen high speed oscillations in general. You can see this in the graphs with the rising transitions being slightly rounded. MCUs have much lower capacitance in their pins, so reality would tend to look even messier than this, especially zoomed in.
lambdaone•7mo ago