← index #5737PR #12114
Off-topic · high · value 3.129
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 · PULL REQUEST

ports/mimxrt: Three bug fixes.

mergedby robert-hhopened 2023-07-29updated 2023-08-16
port-mimxrt
  • Fix stopping the Pin IRQ by calling Pin.irq() with handler set to None. It worked before, but caused in some cases a crash during soft reset.
  • Align the PWM edge cases of duty_u16=0 and duty_u16=65536 for all three internal PWM mechanisms. For duty_u16=0, the output is set to low level, for duty_u16=65536 the output is set to high level.
  • Deinitialize all UART instances on soft reset. Otherwise the board will crash, if new data at a previously used UART arrives before it is instantiated again.

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