PCNT module for esp32

argsngh18
Posts: 2
Joined: Fri Mar 26, 2021 4:38 pm

PCNT module for esp32

Postby argsngh18 » Thu Jun 24, 2021 5:30 am

Hi,

For my frequency calculation application, ranging from 0.1Hz to 50KHz, running on ESP32, I am using a PCNT(Pulse counter) module to accumulate pulse and a 1-millisecond software timer to monitor the sampling period.

Complication : I am capturing the time stamp and start sampling period at the start of first-falling edge of pulse-train and upon elapse of sampling-period, flagged by s/w timer of 1ms, and then calculating frequency. However the pcnt_get_counter st some instances give +/-x counts where x -ranges from 5-50ish. To which there is error in calculate frequency.

P.S. : For frequency below 5KHz the mentioned complication is not observed

Till now I have confirmed that the s/w timer 95% of times is accurate but most of the time pcnt counts retrieved from API are not correct

I am planning to use high resolution esp_timer in place of software timer

Welcome your help !

biterror
Posts: 30
Joined: Thu Apr 30, 2020 11:00 am

Re: PCNT module for esp32

Postby biterror » Thu Jun 24, 2021 6:00 pm

I would do the pulse "gating" completely in hardware to avoid the unpredictable delays and jitter of interrupt code. I haven't used the PCNT peripheral, but isn't it possible to enable/disable the counting using the CTRL input - maybe you could generate a 1 ms long pulse using a timer / PWM / SPI / whatever and loop it back to the CTRL input and then read the counter value after the pulse has occurred?

Who is online

Users browsing this forum: StanInexeon and 116 guests