Best practices for slow frequency measurement on ESP32

I have been using the PCNT module in the ESP32 for frequency measurement of signals with frequencies between 100 Hz and 1 kHz. It has worked very well, but now I am facing the challenge of measuring the frequency of very slow signals (on the order of 0.1 Hz).

I had previously measured such signals using an interrupt and a timer in software, where I would measure the time that had passed between interrupts and saved it into an array of a fixed size (say 5). I would then use a moving average to compute the frequency from the samples collected.

Do you have any recommendations on alternative approaches? Is there something that could be done "in hardware"? Say, that the ESP32 would automagically save the timestamp on each rising edge of the signal?

Hi @danalvarez ,

Welcome to the forum..

You know interesting, just found this..
Pulse Counter (PCNT)
Looks like this might do the trick..
You could of course still use your other methods mentioned and at that slow speed, could do it in the loop..
Pulse counters looks interesting though, so might be worth a read..

good luck.. ~q

Then you'll have to wait 10 seconds for a single wave. You can measure the time between two (raising) edges for a first guess and build a walking average with following edges.

The ESP32 does have a Capture Compare submodule which is part of the Motor Control Pulse Width Modulator (MCPWM) peripherial.
I've never used it.

1 Like