New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp32: Fix PWM not allowing frequencies < 611 Hz (16 bit resolution). #8210
Conversation
ESP-IDF doesn't like changing the PWM resolution.
These tests are executed with uncommented lines micropython/ports/esp32/machine_pwm.c Lines 325 to 337 in 30b6ce8
In this PR
In #8200
|
That's what I get if I run #8200 with your script. Board ESP32_GENERIC_SPIRAM. Everything fine, and on the oscilloscope it looks right as well.
|
Same result with UM_FEATHERS2 and GENERIC_C3. Only for the C3 I had to use the 10 <= f < 20 range. |
Note: I have a glitch in my build system, in that changes to machine_pwm.c do not cause a re-compile of it. I did not look for the reason yet, but remove machine_pwm.c.obj manually instead to force the re-compile. |
Second note: Sometimes, after a a power cycle. I see the phenomenon that the PWM does start extremely slow at the first frequency set with your test code, whatever it is, 1 Hz or 10 Hz. The next setting then is fine. So there seems to be an uninitialized state somewhere. When starting with 1Hz, the duty_u16 shown is 65538, when starting with 9Hz the duty shown is 262144(2**18). But the PWM output is fine. It runs at the proper frequency and duty cycle. |
Have you uncommented PWM_DBG?
P.S. Sorry for the delay and excuse me for spending your time. |
I uncommented the block in set_duty_u16(). Whatever, I have seen this glitch in the PWM trace itself: there are disturbed clock cycles when the resolution changes. Here is another example when switching between 1220 and 1221 Hz (resolution 16->15). The same happens when switching between resolution 15<->14, and so on. |
Yes, most likely in micropython/ports/esp32/machine_pwm.c Lines 322 to 323 in 30b6ce8
|
I've seen also states where the PWM does not start at all without a resolution change happening. That's even more strange. |
It seems that issue is resolved 3 hours ago (but I don't see a commit with fixes): @espressif-bot espressif-bot added Resolution: NA Status: Done Resolution: Done and removed Status: In Progress Resolution: NA labels 3 hours ago |
May I rename |
Sure. But we should make only one PR for that issue. Do you want to keep yours? |
Yes if you not against. |
OK. So I'll close mine then. Tell me, if you are finished, Then I can make a few tests, |
Ready |
Did a test series with GENERIC_SPIRAM, GENERIC_C3 and UM_FEATHERS2 The glitch when changing between resolutions still exists.It must be fixed in the esp-idf. The UM_FEATHERS2 has a glitch on EVERY frequency change, sometimes for several signal periods, when the resolution changes as well. According to that test, the machine_pwm.c code works, but bugs in the esp-idf still cause glitches. But that should have existed already before and is identified by espressif. |
@IhorNehrutsa There is another tiny hiccup. For frequencies < 611, the duty rate cannot be set with the constructor after hard reset. It will always be 512. See this post in the forum: https://forum.micropython.org/viewtopic.php?f=18&t=11975&p=65175#p65083 |
This is another version of
esp32: Fix PWM not allowing frequencies < 611 Hz. #8200
It uses a maximum of 16bit PWM resolution.
Tested on ESP32