https://toitlang.org/ logo
PWM generator start seems to cause LED to flicker ...
# help
a
We have some code such as this
Copy code
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?
f
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.
a
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?
f
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
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.
a
Hehe, what's the easiest way to go about trying that? Or is it a build my own type of situation?
f
This would be a "patch your own copy". Yes. I could build an envelope for you for testing. Which version/esp-variant?
a
Regular esp32 🙂
f
and latest released version?
a
184 currently :/
f
ok. For the testing that shouldn't make a difference.
I will try to upload one this evening.
if nothing happens, remind me every day until I do 🙂
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.
a
Amazing! The person that was looking at it is out tomorrow, so we will have a look at it next week 🙂
Many thanks
f
No rush. Let's hope it fixes your use case.