diff --git a/src/FreqCountESP.cpp b/src/FreqCountESP.cpp index 6e5b696..cdeeefc 100644 --- a/src/FreqCountESP.cpp +++ b/src/FreqCountESP.cpp @@ -122,7 +122,9 @@ void _FreqCountESP::_begin(uint8_t freqPin, uint8_t freqPinIOMode) #endif // USE_PCNT if(mTriggerPin == 0) { // Not external trigger, start internal timer. - timerAlarmEnable(mTimer); + //https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html?highlight=timerAlarm + //remove old timerAlarm API + //timerAlarmEnable(mTimer); } } @@ -131,9 +133,10 @@ void _FreqCountESP::begin(uint8_t freqPin, uint16_t timerMs, uint8_t hwTimerId, // Count frequency using internal timer. // mTriggerPin == 0 means we're using internal timer. mTriggerPin = 0; - mTimer = timerBegin(hwTimerId, 80, true); - timerAttachInterrupt(mTimer, &onTimer, true); - timerAlarmWrite(mTimer, timerMs * 1000, true); + // Set timer frequency to 1Mhz + mTimer = timerBegin(1000000); + timerAttachInterrupt(mTimer, &onTimer); + timerAlarm(mTimer, timerMs * 1000, true, 0); _begin(freqPin, freqPinIOMode); } @@ -169,9 +172,9 @@ void _FreqCountESP::end() detachInterrupt(mPin); #endif if(mTriggerPin == 0) { - timerAlarmDisable(mTimer); timerDetachInterrupt(mTimer); timerEnd(mTimer); + mTimer = NULL; } else { detachInterrupt(digitalPinToInterrupt(mTriggerPin)); }