Remix.run Logo
mrob an hour ago

>averaging the last 50 reads and wait till the majority is either off or on.

This is a bad way to do it because it adds avoidable latency. A moving average is a low-pass filter. The switch bounce is better handled by hysteresis. Change state as soon as you see an edge, then ignore further edges until a timer expires, e.g. 5 ms, which should be enough for the bouncing to settle. A 5 ms timeout limits your repetition rate to 100 presses per second, which is beyond human capabilities.

You might want a tiny bit of hardware low-pass filtering too, for EMI resistance, but that's with microsecond-scale time constant, not milliseconds.

inigyou 35 minutes ago | parent [-]

They didn't say how often the reads are - 50 reads could be only 5ms.

mrob 26 minutes ago | parent [-]

Latency is cumulative, so avoidable latency is never acceptable. Maybe the hardware will change. Maybe somebody will run your software in an emulator. That 5ms could be enough to push the total latency into the "annoying" level.

And even with no additional latency, 5ms is perceptible in some cases anyway. Microsoft Research has a video demonstration:

https://www.youtube.com/watch?v=vOvQCPLkPt4

inigyou 8 minutes ago | parent [-]

It's not an embedded programmer's job to consider how people may later run their software in an unauthorized emulator. That is a problem for the makers of the emulator. Do you really think the people who programmed your microwave should have taken that into consideration?