Page 1 of 1

Using PCNT as both filter and interrupt trigger

Posted: Wed May 24, 2023 8:36 am
by Lancsrick
Hi all,

I have been planning some code but along the way I've discovered the Pulse Counter (PCNT) and I'm wondering if there's a simpler way...

- Objective - When an input goes to High, and the pulse is at least 50ms long, record that as an event and include the timestamp (microseconds).
- Previous intent - Capturing all events and using a queue whilst comparing timestamps to filter out pulses that were under 50ms

- Potentially a better way? - Use PCNT, with the interrupt adding the timestamp to the queue, and a glitch filter with a max of 50ms


Would this be a better approach? Very new to ESP32.

Thanks.

Re: Using PCNT as both filter and interrupt trigger

Posted: Wed May 24, 2023 8:50 pm
by MicroController
Simple idea: On the rising edge of the input (GPIO interrupt?), start a 50ms (single-shot) timer which, upon expiry, will call code to handle a valid signal. On a falling edge of the input, stop/cancel the timer. It is permissible to "stop" a timer that already expired and in that case it just does nothing.