Fixing frequency measurements with PCNT when using open collector configuration #8368
danalvarez
started this conversation in
Show and tell
Replies: 2 comments 10 replies
-
Conceptually, I see no issues with your circuit. It does introduce the following changes:
I suspect your issue is the slower rising edge. You can see this on your scope measurements: Rise=486ns vs Fall= 82ns. You can fix this with the following methods:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Please note that anybody might not be a programming guru. Where does it need to be added those two operators, in setup, in library? |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Writing this in case it might ever help someone else. Using an ESP32-WROOM-32UE.
I am using the FreqCountESP library, which lets you use the PCNT module to count pulses on a pin. I had been testing it with a signal generator connected directly to
IO4
, no problems at all! Very precise and exact, to within 1 Hz which is what I needed. However, I then connected the signal as in the following schematic:Which is what I was going to ultimately use to sample an RPM signal. To my surprise, frequency measurements became very inexact and noisy. For example, I'd set a 500 Hz test signal on the base of the transistor, and
IO4
would read anything between 500 and 510 Hz. If I disabled the usage of the PCNT module and simply used interruptions to measure the frequency, it would work OK again.After some reading, I came across some posts mentioning that the glitch filter could help. I configured it by setting
pcnt_set_filter_value(PCNT_UNIT, 1);
and enabled it withpcnt_filter_enable(PCNT_UNIT);
, and this solved the issue!Still don't know why, I can't see any glitches with my oscilloscope, signal looks perfectly clean:

If anyone has any ideas as to why this solved it, I'd appreciate it!
Beta Was this translation helpful? Give feedback.
All reactions