Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/FreqCountESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}
Expand Down