Converting 2.0.17 Timer code to 3.0+

penguin
Posts: 1
Joined: Fri Aug 16, 2024 3:11 am

Converting 2.0.17 Timer code to 3.0+

Postby penguin » Fri Aug 16, 2024 3:16 am

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!

lbernstone
Posts: 789
Joined: Mon Jul 22, 2019 3:20 pm

Re: Converting 2.0.17 Timer code to 3.0+

Postby lbernstone » Fri Aug 16, 2024 4:34 am

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).

Who is online

Users browsing this forum: Bing [Bot] and 96 guests