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
esp32: PWM duty will be changed when changing the frequency if more than one channel is used. #8345
After upgrading mpy from 1.17 to 1.18, my buzzer can't play low frequency sounds any more.
With further test, it shows that the pwm has no output when frequencies < 611Hz.
frommachineimportPWM, Pinpwm=PWM(Pin(5)) # also tested with Pin(2)pwm.duty(512)
pwm.freq(611) # it works, digital multimeters shows freq 1222Hzpwm.freq(610) # no pwm output, digital multimeters says freq is 0
And after switching back to mpy 1.17, pwm.freq(610) works fine. I'v tested with another board and I still got the same result. I'm sure this is an issue introduced by v1.18.
Fixed since a while. Please use a recent nightly build, and ignore the "unstable" label. The nightly builds are tested the same way than the release build.
Fixed since a while. Please use a recent nightly build, and ignore the "unstable" label. The nightly builds are tested the same way than the release build.
Thank you very much,I just tested the version "esp32-20220226-unstable-v1.18-160-g0a217624e.bin", it can work in 1Hz now, but... the duty will be changed when changing the freq.
No. It is not. That is something which show up only once after hard reset. I just tested you sequence with my own builds, and it works fine. I just downloaded the nightly build and verify, which esp-idf and version is used.
I test twice,
at the first time,only use one PWM0 channel,it works well。
at the second time,use PWM0,PWM2,PWM4 channel,it seems timers for each pwm channel will be changed when changing the freq, and it will cause the changing of duty , maybe the problem is the counter of the timer is not set right value,
You are right. If more than one channel is used, there will be issues with the duty cycle. The basic PR which changed that behavior is #7817. The PR message explains the function and one can see the root of the problem, which is also visible in your log. If a channel's frequency is set to a frequency used by the other channel, it uses this channels timer. That does not take care of potentially different duty cycles.
Dropping the timer re-use mechanism makes the PWM work as intended. However, it is then again limited to 8 channels.
changed the title [-]esp32: PWM has no output when frequencies < 611Hz.[/-][+]esp32: PWM duty will be changed when changing the frequency if more than one channel is used.[/+]on Feb 27, 2022
So I made a small change to the code which forces the duty rate to be set on frequency changes. That was omitted when setting to a frequency which was already used in a different channel. The timer for that channel was reused, but still the duty rate had to be adapted. The change is based on a different PR I made earlier, and by chance it fixes #8306 as well. Output from going though the same series as @xky183 above:
Activity
xky183 commentedon Feb 26, 2022
meet same problem by v1.18,work fine by v1.17
robert-hh commentedon Feb 26, 2022
Fixed since a while. Please use a recent nightly build, and ignore the "unstable" label. The nightly builds are tested the same way than the release build.
xky183 commentedon Feb 26, 2022
Thank you very much,I just tested the version "esp32-20220226-unstable-v1.18-160-g0a217624e.bin", it can work in 1Hz now, but... the duty will be changed when changing the freq.
Dreagonmon commentedon Feb 26, 2022
maybe #8306 is the related issue.
I created this issue and closed it soon when I realized that this is fixed in the nightly build. but it seems not really fixed.
robert-hh commentedon Feb 26, 2022
No. It is not. That is something which show up only once after hard reset. I just tested you sequence with my own builds, and it works fine. I just downloaded the nightly build and verify, which esp-idf and version is used.
robert-hh commentedon Feb 26, 2022
I cannot verify your findings. Everything looks as intended. Both the reporting in the print and the actual signal are fine.
xky183 commentedon Feb 27, 2022
I test twice,
at the first time,only use one PWM0 channel,it works well。
at the second time,use PWM0,PWM2,PWM4 channel,it seems timers for each pwm channel will be changed when changing the freq, and it will cause the changing of duty , maybe the problem is the counter of the timer is not set right value,
xky183 commentedon Feb 27, 2022
could you reopen this issue? thanks
robert-hh commentedon Feb 27, 2022
You are right. If more than one channel is used, there will be issues with the duty cycle. The basic PR which changed that behavior is #7817. The PR message explains the function and one can see the root of the problem, which is also visible in your log. If a channel's frequency is set to a frequency used by the other channel, it uses this channels timer. That does not take care of potentially different duty cycles.
Dropping the timer re-use mechanism makes the PWM work as intended. However, it is then again limited to 8 channels.
Dreagonmon commentedon Feb 27, 2022
sure
[-]esp32: PWM has no output when frequencies < 611Hz.[/-][+]esp32: PWM duty will be changed when changing the frequency if more than one channel is used.[/+]robert-hh commentedon Feb 27, 2022
So I made a small change to the code which forces the duty rate to be set on frequency changes. That was omitted when setting to a frequency which was already used in a different channel. The timer for that channel was reused, but still the duty rate had to be adapted. The change is based on a different PR I made earlier, and by chance it fixes #8306 as well. Output from going though the same series as @xky183 above:
esp32/machine_pwm: Always set the duty cycle when setting the frequency.
dpgeorge commentedon Mar 7, 2022
Fixed by 55a0125
Merge pull request micropython#8345 from tannewt/s3_watchdog
esp32/machine_pwm: Always set the duty cycle when setting the frequency.
esp32/machine_pwm: Always set the duty cycle when setting the frequency.