You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PWM: Changing the PWM frequency affects the duty cycle on some ports. #7909
PWM: with some frequency changes the duty cycle is affected as well.
MicroPython v1.17-84-gba940250a on 2021-10-17; ESP32 module with ESP32
Examples:
Code:
from machine import PWM, Pin
p=PWM(Pin(4), 100000)
Result: No output, until duty cycle is set, e.g. to 512 = 50%.
Then, starting at 100k: p.freq(10000)
Duty cycle changes to 256
After setting duty cycle again to 512: p.freq(100000)
Result: output is off, a call to duty() reports 1024, which b.t.w. cannot be set manually.
I expect the duty cycle to stay the same or at least as close as possible at the set value, when the frequency is changed, since it is ratio, not related to physical units like frequency or time. Contrary to that, I expect the on-time of the duty-cycle to be frequency-invariant if it was set with duty_ns().
Edit: The RP2040 and STM32 ports show a similar behavior. ESP8266 seems ok. I did not test NRF ports.
changed the title [-]ESP32: Changing the frequency affects the duty cycle.[/-][+]ESP32: Changing the PWM frequency affects the duty cycle.[/+]on Oct 17, 2021
@IhorNehrutsa I faintly recall that you contributed the PWM module. May I ask you to take care of this unexpected behavior. It could be sufficient to memorize the duty cycle setting and set if again after a frequency change.
Yeah, it seems that not only the ESP32 port shows that behavior. I tested the RP2040, pyboard, ESP8266 and W600. The RP2040 and pyboard fail too. The ESP8266 and W600 are fine. The mimxrt port as well. While the fix for the rp2040 seems easy, it seems more complicated for the pyboard.
changed the title [-]ESP32: Changing the PWM frequency affects the duty cycle.[/-][+]PWM: Changing the PWM frequency affects the duty cycle on some ports.[/+]on Oct 19, 2021
Activity
[-]ESP32: Changing the frequency affects the duty cycle.[/-][+]ESP32: Changing the PWM frequency affects the duty cycle.[/+]robert-hh commentedon Oct 18, 2021
@IhorNehrutsa I faintly recall that you contributed the PWM module. May I ask you to take care of this unexpected behavior. It could be sufficient to memorize the duty cycle setting and set if again after a frequency change.
IhorNehrutsa commentedon Oct 18, 2021
Under construction at
esp32/machine_pwm: Add PWM duty_u16() and duty_ns(). #7907
IhorNehrutsa commentedon Oct 19, 2021
Please rename
ESP32: Changing the PWM frequency affects the duty cycle.
to
PWM: Changing the PWM frequency affects the duty cycle.
This issue about all hardware PWM's
esp32/machine_pwm.c: Fix Changing the PWM frequency affects the duty …
robert-hh commentedon Oct 19, 2021
Yeah, it seems that not only the ESP32 port shows that behavior. I tested the RP2040, pyboard, ESP8266 and W600. The RP2040 and pyboard fail too. The ESP8266 and W600 are fine. The mimxrt port as well. While the fix for the rp2040 seems easy, it seems more complicated for the pyboard.
[-]ESP32: Changing the PWM frequency affects the duty cycle.[/-][+]PWM: Changing the PWM frequency affects the duty cycle on some ports.[/+]IhorNehrutsa commentedon Oct 19, 2021
The Latest commits of #7907 fix this issue for ESP.
Please report bugs to #7907
Merge pull request micropython#7909 from mjsir911/msirabella/shallow_…