Need more timers on ESP32-S3

Slinisa
Posts: 32
Joined: Sat Oct 07, 2023 8:21 am

Need more timers on ESP32-S3

Postby Slinisa » Tue Oct 01, 2024 3:15 am

I used all 4 timers on my ESP32-S3 project and I found out I'll need some more. I previously worked on some other MCU that had a similar number of timers, but had a MCP module that had it's own timers that were available. I can see that ESP32-S3 also has MCPWM module with timers so I was wondering if it's possible to use it (together with callback on timeout), I tried to write some code to utilize it, but it didn't work, and there are so little examples on the internet. If this is indeed possible, can anyone point me to where to find a code example? Or some other solution?

Thanks in advance.

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Need more timers on ESP32-S3

Postby chegewara » Tue Oct 01, 2024 4:47 am


Slinisa
Posts: 32
Joined: Sat Oct 07, 2023 8:21 am

Re: Need more timers on ESP32-S3

Postby Slinisa » Tue Oct 01, 2024 11:45 am

Thanks for your reply.
I would prefer to have a hardware timer, but if nobody offers a different solution, I'll have to use them.

RandomInternetGuy
Posts: 52
Joined: Fri Aug 11, 2023 4:56 am

Re: Need more timers on ESP32-S3

Postby RandomInternetGuy » Sun Oct 20, 2024 11:23 am

The UNIX kernel, like a lot of other RTOSes, got away with a single timer source for a long time. I'm not saying that didn't have excuses, but it was workable.

Just brush up on having one montonically increasing value of "time" and a list of events scheduled to be serviced in the future. If you have lots of such events - and the discipline to unit test them, probably in user space, because locks matter - you can have multiple listss, like a short one of events that'll happen in the next couple of ticks and a longer oneof things you'll need to tend to "one of these days".

Think of one as the egg timer in the kitchen controlling the things you have to deal with NOW (ish) and the other as the list scribbled on the calendar of things that are upcoming, but not immediate. Once every once in a while, you have to grab events from that long list, sort them effectively, and THEN move them to the list of things to be checked on every timer tick or so.

Fiddly? Perhaps. But many of the world's OSes run on very similar schemes.

User avatar
ok-home
Posts: 78
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Need more timers on ESP32-S3

Postby ok-home » Sun Oct 20, 2024 12:10 pm

Slinisa wrote:
Tue Oct 01, 2024 3:15 am
I used all 4 timers on my ESP32-S3 project and I found out I'll need some more. I previously worked on some other MCU that had a similar number of timers, but had a MCP module that had it's own timers that were available. I can see that ESP32-S3 also has MCPWM module with timers so I was wondering if it's possible to use it (together with callback on timeout), I tried to write some code to utilize it, but it didn't work, and there are so little examples on the internet. If this is indeed possible, can anyone point me to where to find a code example? Or some other solution?

Thanks in advance.
https://github.com/espressif/esp-idf/bl ... ple_main.c

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Need more timers on ESP32-S3

Postby MicroController » Sun Oct 20, 2024 2:56 pm

RandomInternetGuy wrote:
Sun Oct 20, 2024 11:23 am
... having one montonically increasing value of "time" and a list of events scheduled to be serviced in the future. ...
Fiddly? Perhaps.
Which is why the IDF's "high resolution timer" implements exactly this for you.
As do the lower-resolution FreeRTOS timers.
There's no need for microsecond accuracy to blink an LED, so different timer constructs can be used for different things, reducing potential contention on high-accuracy timers.

Who is online

Users browsing this forum: Accound and 96 guests