Pulse Counter Library

Can anybody explain to me how the Pulse Counter Library works in lua? I have watched John Lauers video on it and I am still not clear on how it works.
I want to be able to count pulses and call a method when the counter reaches a specific value.

Library docs: pulsecnt - NodeMCU Documentation

Were you able to install Lua on the ESP32 yet?

Meaning using the Nodemcu ESP32 project?

Yes I was able to install the necessary firmware(I used the cloud based solution) and I have tested some of the examples like the ones with the button GPIO. Im having a difficult time understanding how the pulsecnt increments.
I have been testing it with a motor controller and its producing output when a triggering event occurs, but the count never gets higher than 5 even though the high limit(HLim) is set to 32227. the counter fluctuates weirdly between 0,1,2,3,4 or 5.

You probably have noise on the line then. Are you running the sample code that’s included in the docs?

Yes I am using the sample code. Noise seems like a reasonable cause but ill have to test and see.
Attached is a snippet of the output I was getting in the console.
snippity

Have you tried the filter to debounce?

– Set clock cycles for filter. Any pulses lasting shorter than
– this will be ignored when the filter is enabled. So, pulse
– needs to be high or low for longer than this filter clock
– cycle. Clock is 80Mhz APB clock, so one cycle is
– 1000/80,000,000 = 0.0000125 ms. 1023 cycles = 0.0127875 ms
– so not much of a debounce for manual push buttons.
pcnt:setFilter(1023)

The code already had the debounce filter(1023) applied. Ill play around more with the filter and see if there is a difference.

In your video, you have code for a Counting the steps from a stepper motor. Is that code posted anywhere in this forum?