Page 1 of 1

Need more timers on ESP32-S3

Posted: Tue Oct 01, 2024 3:15 am
by Slinisa
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.

Re: Need more timers on ESP32-S3

Posted: Tue Oct 01, 2024 4:47 am
by chegewara

Re: Need more timers on ESP32-S3

Posted: Tue Oct 01, 2024 11:45 am
by Slinisa
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.

Re: Need more timers on ESP32-S3

Posted: Sun Oct 20, 2024 11:23 am
by RandomInternetGuy
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.

Re: Need more timers on ESP32-S3

Posted: Sun Oct 20, 2024 12:10 pm
by ok-home
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

Re: Need more timers on ESP32-S3

Posted: Sun Oct 20, 2024 2:56 pm
by MicroController
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.