Hi.
I'm trying to multiplex some LED's for a 7-segment display, and for this I use timer0.
To get rid of flickering, I have to set the timer interval to at least 2ms.
But the timer doesn't trigger consistently, there's random flicker.
I assume that there are other tasks in the background that sometimes cause the timer to trigger late or even not at all.
Can I solve this somehow?
Timers aren't running consistently
-
- Posts: 522
- Joined: Tue Jun 21, 2022 2:17 pm
- Location: South coast UK
- Has thanked: 292 times
- Been thanked: 164 times
Re: Timers aren't running consistently
Might depend on which board you are using.
Any single core device will certainly suffer what you describe.
Dual core, possibly not. Maybe cicciocb can offer more insight into the internal workings of the timers or possible workarounds.
Any single core device will certainly suffer what you describe.
Dual core, possibly not. Maybe cicciocb can offer more insight into the internal workings of the timers or possible workarounds.
- cicciocb
- Site Admin
- Posts: 2792
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 592 times
- Been thanked: 1993 times
- Contact:
Re: Timers aren't running consistently
As there are other activities in the background, it can happens that the timer do not respect the time, in particular for short timings @ 2msec.
It is obviously worse for the single core modules
It is obviously worse for the single core modules
Re: Timers aren't running consistently
Sorry, I should've mentioned that I'm using an ESP32-S3 module.
Nevertheless, it's flickering.
Is there any chance of using the ULP coprocessor for this?
Nevertheless, it's flickering.
Is there any chance of using the ULP coprocessor for this?
- cicciocb
- Site Admin
- Posts: 2792
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 592 times
- Been thanked: 1993 times
- Contact:
Re: Timers aren't running consistently
The ULP is another mini-core mainly oriented for doing tasks when the main chip is sleeping.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Jan 07, 2025 1:29 pm Sorry, I should've mentioned that I'm using an ESP32-S3 module.
Nevertheless, it's flickering.
Is there any chance of using the ULP coprocessor for this?
It has a limited set of instructions, a limited memory space and a very limited memory access space so it can do only very basic stuff (such as read a i2c sensor while the processor is sleeping).
It is very complicate to program (assembler) and is practically very rarely used (I've only seen it used for very specific tasks).
What you would achieve should be done using a dedicated driver that rely on H/W interrupts.
-
- Posts: 522
- Joined: Tue Jun 21, 2022 2:17 pm
- Location: South coast UK
- Has thanked: 292 times
- Been thanked: 164 times
Re: Timers aren't running consistently
One thought, maybe setup PWM on one pin and connect it to another that has interrupts enabled.
It might even be possible to setup interrupts on the same pin as the PWM.
It might even be possible to setup interrupts on the same pin as the PWM.
Re: Timers aren't running consistently
I don't know if the interrupt has a higher priority than the timer, because both are handled by an interpreter task running on top of an OS.
Where not talking about raw code here.
I'd expect the interrupt to show the same problems as the timer event, but it's worth a try.
I mean, sure, I could always use a small microcontroller running C or assembler to handle the realtime LED multiplexing, but that's somehow not the point. I have the incentive to use a single, bare ESP32 board to do everything, because I know it CAN do it.
To give an idea about what I want to achieve, here's a schematic:
I want to use 3V LED filament pieces to build retro 7-segment displays inside glass cylinders that resemble radio/nixie tubes.
I built one prototype and it looks nice.
The LEDs are driven directly by the ESPs ports, so what I'm doing is in fact charlieplexing, but I use only some of the LEDs that charlieplexing can drive.
If cicciocb wants to write a generic charlieplexing driver for Annex, I wouldn't mind
Where not talking about raw code here.
I'd expect the interrupt to show the same problems as the timer event, but it's worth a try.
I mean, sure, I could always use a small microcontroller running C or assembler to handle the realtime LED multiplexing, but that's somehow not the point. I have the incentive to use a single, bare ESP32 board to do everything, because I know it CAN do it.
To give an idea about what I want to achieve, here's a schematic:
I want to use 3V LED filament pieces to build retro 7-segment displays inside glass cylinders that resemble radio/nixie tubes.
I built one prototype and it looks nice.
The LEDs are driven directly by the ESPs ports, so what I'm doing is in fact charlieplexing, but I use only some of the LEDs that charlieplexing can drive.
If cicciocb wants to write a generic charlieplexing driver for Annex, I wouldn't mind

You do not have the required permissions to view the files attached to this post.
- cicciocb
- Site Admin
- Posts: 2792
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 592 times
- Been thanked: 1993 times
- Contact:
Re: Timers aren't running consistently
What you want do cannot be done with the interpreter, is is not enough fast and, by its nature, annex do other stuff in parallel. Only a dedicated driver (embedded inside) can do that job (like is the case, for example, for the HUB75 or the VGA).
Anyway, you should try to write this directly using the Arduino SDK, should not be hard to do.
Anyway, you should try to write this directly using the Arduino SDK, should not be hard to do.
Re: Timers aren't running consistently
No, the multiplexing itself is trivial.
As is connecting to the internet and getting the time via ntp.
I've done it dozens of times.
It's just that Annex gives a nice environment for other stuff, like getting weather info or adding a nice config web page, etc.
Having said that, a charlieplexing driver for Annex WOULD be nice.
I'm just not sure if many people would have a use for it.
As is connecting to the internet and getting the time via ntp.
I've done it dozens of times.
It's just that Annex gives a nice environment for other stuff, like getting weather info or adding a nice config web page, etc.
Having said that, a charlieplexing driver for Annex WOULD be nice.
I'm just not sure if many people would have a use for it.
- cicciocb
- Site Admin
- Posts: 2792
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 592 times
- Been thanked: 1993 times
- Contact:
Re: Timers aren't running consistently
Why you don't simply hack a TM1367 module and use it as a driver for your "clock" ?
The TM1637 are really cheap .. remove the existing led module and rewire your (adapting the wiring at the same time)
The TM1637 are really cheap .. remove the existing led module and rewire your (adapting the wiring at the same time)