kapraran / FreqCountESP

A frequency counter library for esp32
https://kapraran.github.io/FreqCountESP/
MIT License
31 stars 7 forks source link

Use Hardware Pulse Counter to support higher frequencies. #4

Closed dpwe closed 1 year ago

dpwe commented 1 year ago

Thanks for the very clean FreqCountESP class.

I wanted to use it to measure my new 10 MHz OCXO. However, getting input pulses at 10 MHz overwhelmed the interrupt handler and the code wouldn't run.

It turns out that the ESP32 has a hardware pulse counter, pcnt. This patch adapts FreqCountESP to use the pcnt hardware counter. (The old code is preserved, and can be restored by removing the #define USE_PCNT at the top of FreqCountEsp.h.

With this change, I am successful in measuring my 10 MHz xtal. I also verified the modified code against the original by using both versions to measure a stabilized 32 kHz oscillator.