You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debouncing the Elliot's way has multiple disadvantages:
Needs to be polled so it consumes a task and the polling frequency should be constant (it's not on a FreeRTOS task).
Can't detect 000101011111 like bouncing pattern. The mask used to detect a button press edge is 00xxx111. So there is at least a frequency of the bouncing that'll fail detection. In your code, you're using longer patterns, but it's the same issue.
Use of a Queue takes a lot of resources (with cross CPU interrupts) on ESP32. It's a huge amplification of the debouncing cost.
Button pressed is only detected after multiple polling. So you have a high latency.
I think it'd be better if you used relaxing timers or counters instead:
Relaxing timer
Set an interrupt on any edge of the button
In the interrupt handler, you're checking if you are in the relax period or not
If you are in the relax period, return and ignore the interrupt
Else, start the relax period, and call the user's GPIO handler directly (or use a Queue if you need cross task here)
Optional: The GPIO handler can store/maintain the state of the button
This typically react as fast as possible to the first button press (no latency) and is not sensitive to bounce frequency or task scheduling
Counters
Set an interrupt on any edge of the button
In the interrupt handler, you're checking if you are pressed or released. If pressed, increase counter. If released, decrease it.
If the counter is above a given threshold, call the GPIO pressed counter.
If the counter is below a given (negative) threshold, call the GPIO released counter.
This adds a bit of latency to the processing, but is a bit safer to EMI discharge in the GPIO input (where you get a 000010000 like event). You can combine the with the other method for robustness.
The text was updated successfully, but these errors were encountered:
Debouncing the Elliot's way has multiple disadvantages:
I think it'd be better if you used relaxing timers or counters instead:
Relaxing timer
This typically react as fast as possible to the first button press (no latency) and is not sensitive to bounce frequency or task scheduling
Counters
This adds a bit of latency to the processing, but is a bit safer to EMI discharge in the GPIO input (where you get a 000010000 like event). You can combine the with the other method for robustness.
The text was updated successfully, but these errors were encountered: