From 2aa7e9a62309c9c0274804ca1f2ffa8c3f04e935 Mon Sep 17 00:00:00 2001 From: mishkashishka0 <107191711+mishkashishka0@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:53:05 +0300 Subject: [PATCH 1/3] Update FreqCountESP.cpp Corrected with new ESP-IDF 5.1 API --- src/FreqCountESP.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/FreqCountESP.cpp b/src/FreqCountESP.cpp index 6e5b696..d3be038 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); + timer = NULL; } else { detachInterrupt(digitalPinToInterrupt(mTriggerPin)); } From 7e49542c6146ff4a66f0b73f28f29d162a596218 Mon Sep 17 00:00:00 2001 From: adiat Date: Tue, 17 Dec 2024 09:06:35 +0330 Subject: [PATCH 2/3] Update FreqCountESP.cpp --- src/FreqCountESP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FreqCountESP.cpp b/src/FreqCountESP.cpp index d3be038..1c34eab 100644 --- a/src/FreqCountESP.cpp +++ b/src/FreqCountESP.cpp @@ -174,7 +174,7 @@ void _FreqCountESP::end() if(mTriggerPin == 0) { timerDetachInterrupt(mTimer); timerEnd(mTimer); - timer = NULL; + mtimer = NULL; } else { detachInterrupt(digitalPinToInterrupt(mTriggerPin)); } From 3c80270167968fad8750f3d30f31f43a68136b38 Mon Sep 17 00:00:00 2001 From: adiat Date: Tue, 17 Dec 2024 09:08:16 +0330 Subject: [PATCH 3/3] Update FreqCountESP.cpp --- src/FreqCountESP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FreqCountESP.cpp b/src/FreqCountESP.cpp index 1c34eab..cdeeefc 100644 --- a/src/FreqCountESP.cpp +++ b/src/FreqCountESP.cpp @@ -174,7 +174,7 @@ void _FreqCountESP::end() if(mTriggerPin == 0) { timerDetachInterrupt(mTimer); timerEnd(mTimer); - mtimer = NULL; + mTimer = NULL; } else { detachInterrupt(digitalPinToInterrupt(mTriggerPin)); }