I am attempting to upgrade some code written with the older Timer library for the esp32 2.17.0 Arduino library that looks something like this:
```
askRequestTimer = timerBegin(0, 80, true);
timerAttachInterrupt(askRequestTimer, &onAskReqTimer, true);
timerAlarmWrite(askRequestTimer, 5*1000000, true);//send out an ask every 5 secs
timerAlarmEnable(askRequestTimer);
askExpireTimer = timerBegin(1, 80, true);
timerAttachInterrupt(askExpireTimer, &onAskExpireTimer, true);
timerAlarmWrite(askExpireTimer, expireLength*1000000, true);
timerAlarmEnable(askExpireTimer);
timerStop(askExpireTimer);
```
Give the changes outlined here https://docs.espressif.com/projects/ard ... o_3.0.html, timerBegin and timerAlarm have been updated, so I'm trying to reflect those changes.
This is what I currently have:
```
askRequestTimer = timerBegin(80000000); // 80MHz
timerAttachInterrupt(askRequestTimer, &onAskReqTimer);
timerAlarm(askRequestTimer, 5 * 1000000, true, 0); //send out an ask every 5 secs
askExpireTimer = timerBegin(80000000);
timerAttachInterrupt(askExpireTimer, &onAskExpireTimer);
timerAlarm(askExpireTimer, expireLength * 1000000, true, 0);
timerStop(askExpireTimer);
```
I'm wondering if this is equivalent? Or if someone could provide advice on how to update the code?
Thank you!
Converting 2.0.17 Timer code to 3.0+
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Converting 2.0.17 Timer code to 3.0+
What are you doing that needs the precision of the hardware timers? If you are running something once a second, use Ticker or a FreeRTOS timer.
If you do need to use the hardware timer, use a single timer running at 1MHz and attach multiple alarms to that timer (at the appropriate intervals).
If you do need to use the hardware timer, use a single timer running at 1MHz and attach multiple alarms to that timer (at the appropriate intervals).
Who is online
Users browsing this forum: No registered users and 76 guests