← index #5737Issue #4758
Related · high · value 2.703
QUERY · ISSUE

ESP32 Confusing behaviour of PWM after soft reset

openby peterhinchopened 2020-03-08updated 2023-09-17
port-esp32

Consider:

from machine import Pin, PWM
pin = Pin(23, Pin.OUT)
pwm = PWM(pin, freq=38000, duty=338)

This works as expected. If you issue ctrl-d the waveform on the pin continues unchanged. If you paste the above code again, you cause a low output with

pwm.duty(0)

Subsequently changing the duty value to a value > 0 has no effect. This is surprising.

There is a simple workround of issuing pwm.deinit() at the start. The current state could be confusing to newcomers. It should either be documented or changed so that a soft reset de-initialises any PWM instance.

CANDIDATE · ISSUE

pwm.deinit() can not close Pin if Duty Cycle set to 1023

closedby ghostopened 2019-05-07updated 2019-05-26
port-esp8266

Hi I was using the latest nightly built for esp8266 that is esp8266-20190430-v1.10-304-g8031b7a25. I setup GPIO Pin 5 as a PWM pin and set the frequency to 1000. the deinit() method works fine for all the other duty cycles except when the duty cycle is set to max 1023.

Code
from machine import Pin, PWM
pwm = PWM(Pin(5))
pwm.freq(1000)
pwm.duty(1023)
pwm.deinit()##Does not work in this case

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied