guild icon
Toit
#PWM generator start seems to cause LED to flicker once?
Thread channel in help
addshore
addshore 09/23/2025 04:08 PM
We have some code such as this

for i := 0; i < 3; i++: leds[i] = gpio.Pin pins[i] --output=true --value=1 sleep --ms=1000 for i := 0; i < 3; i++: channels[i] = generator.start leds[i] --duty-factor=1 sleep --ms=1000 sleep --ms=10000

Where we control an RGB LED.
First looping to setup the pins, with value 1 which in this case is LED OFF
We then look through to start the generators, and calling .start seems to cause a small flicker once for each color.

Is there a way to avoid this / a bug that can be fixed?
floitsch
floitsch 09/25/2025 07:17 AM
Is it that the channels are set individually, which is noticeable?
So you want to change 3 channels at exactly the same time?
I skimmed the esp-idf documentation but haven't seen anything that would allow to do that yet.
addshore
addshore 09/25/2025 08:06 AM
So, yes setting the 3 at once leads to 3 different little flashes of the LED
Ideally we would expect it to just remain off during this time.
I assume that even if there was a way to set all 3 at once, this would still lead to there being an LED flick?
floitsch
floitsch 09/25/2025 09:22 AM
Hmm. Probably it's because the LEDs are off when the channel is high. The esp-idf might try to not flicker by keeping the output low, which does the opposite for you.
I will have another look at the options
💟1
floitsch
floitsch 09/25/2025 10:56 AM
Could you maybe try to invert the pin?
https://github.com/toitlang/toit/blob/ffc3b1be5c5a82107576fff783a5667b3f6b81ca/src/resources/pwm_esp32.cc#L220
If that works for you, we can make that an option.
Program your microcontrollers in a fast and robust high-level language. - toitlang/toit
addshore
addshore 09/25/2025 11:08 AM
Hehe, what's the easiest way to go about trying that? Or is it a build my own type of situation?
floitsch
floitsch 09/25/2025 11:09 AM
This would be a "patch your own copy". Yes.
I could build an envelope for you for testing.
Which version/esp-variant?
(edited)
addshore
addshore 09/25/2025 11:09 AM
Regular esp32 :🙂:
floitsch
floitsch 09/25/2025 11:10 AM
and latest released version?(edited)
addshore
addshore 09/25/2025 11:10 AM
184 currently :/
floitsch
floitsch 09/25/2025 11:10 AM
ok. For the testing that shouldn't make a difference.
💟1
floitsch
floitsch 09/25/2025 11:10 AM
I will try to upload one this evening.
floitsch
floitsch 09/25/2025 11:10 AM
if nothing happens, remind me every day until I do :🙂:
👍1
addshoreOPaddshore
184 currently :/
floitsch
floitsch 09/25/2025 08:29 PM
I uploaded firmware-esp32-pwm-invert.envelope.gz.
You should be able to use it with jag flash esp32-pwm-invert. I didn't test it yet, as I didn't want to downgrade my Jaguar.
I see 3 scenarii:
- it doesn't work for you at all (version mismatch or so). In that case I will downgrade and make sure it works.
- it flashes, but doesn't fix your issue. In that case we need to dig deeper. I will probably create repro (with an LED that is inverted...)
- it works and fixes your issue. In that case I will expose the 'invert' flag.
addshore
addshore 09/25/2025 08:29 PM
Amazing!
The person that was looking at it is out tomorrow, so we will have a look at it next week :🙂:
👍1
addshore
addshore 09/25/2025 08:29 PM
Many thanks
floitsch
floitsch 09/25/2025 08:30 PM
No rush. Let's hope it fixes your use case.
17 messages in total