1365Views2Replies

Author Options:

ESP32 and Pulse Counter Answered

Hi.

I can't find a small simple code to know if I receive pulses of a signal from an ESP32 pin.

The pulses are about 100ns in amplitude and can be of variable frequency between 100 and 6000Hz.

I just know if that pin is receiving pulses, I don't need to count them or anything else.

Can you help me, please.

Greetings

Tags:help

Discussions

The forums are retiring in 2021 and are now closed for new topics and comments.
0
ruilviana
ruilviana

7 months ago

Hi,
To detect a pulse, you can use the Compare Feature of the ESP32 MCPWM peripheral.
You configure this feature so that when it detects a pulse, it generate an interruption.
You can use this interrupt routine to inform your program that a pulse has been received.

RV

0
meweini25
meweini25

1 year ago

With the input filter disabled, the PCNT module should be able to count
up to a 40MHz input clock (half the 80MHz APB frequency). I'm not sure
why this specification isn't listed in the datasheet or the TRM. https://mywegmansconnect.onl/



Do I understand that what you need to do is count the number of cycles
from the Si5351 clock output that occur within a single 1 second period,
as delimited by the GPS PPS signal?



Each PCNT channel can be connected to both a pulse input and a control
input. You can configure the control input to read the PPS signal to
disable counting when the PPS signal inverts, and you can also enable a
GPIO interrupt on the same pin so this triggers a software interrupt
(totally independent to the PCNT module). This way, hardware pulse
counting should stop immediately when the PPS signal occurs, and you can
process the PCNT output (and reconfigure PCNT for the next period)
after the associated GPIO interrupt.



Note that because PCNT counters are only 16 bits wide, you'll need to
count overflow events via a software interrupt handler when
f>65535Hz. This should be OK though, even at 40MHz there is ~1.6ms to
handle this interrupt before PCNT overflows a second time.