Sorry for posting to wrong category but it is always a quest for me to find proper category.
Looks like it is a bug in the Arduino Core, in esp32-hal-ledc.c somewhere.
Steps to reproduce (esp32-s3)
- GPIO0 is attached to LEDC Channel#0, freq=10Mhz, duty resolutions=2 bits:
[3869801][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x4205447c
[3869812][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 0 successfully set to type GPIO (1) with bus 0x1
[3869822][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type LEDC (9) successfully set to 0x4200c4c4
[3869834][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 0 successfully set to type INIT (0) with bus 0x0
[3869844][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 0 successfully set to type LEDC (9) with bus 0x3fca3880
[3869855][I][esp32-hal-ledc.c:166] ledcAttachChannel(): LEDC attached to pin 0 (channel 0, resolution 2)
- GPIO4 is attached to the same channel#0, but freq=100Hz, while duty resolutions is 14 bits:
[3970483][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x4205447c
[3970495][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 4 successfully set to type GPIO (1) with bus 0x5
[3970505][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type LEDC (9) successfully set to 0x4200c4c4
[3970517][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 4 successfully set to type INIT (0) with bus 0x0
[3970527][I][esp32-hal-ledc.c:123] ledcAttachChannel(): Channel 0 is already set up, given frequency and resolution will be ignored
[3970539][I][esp32-hal-ledc.c:154] ledcAttachChannel(): Channel 0 frequency: 10000000, resolution: 2
[3970548][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 4 successfully set to type LEDC (9) with bus 0x3fca3aa4
.. and then:
[3970559][I][esp32-hal-ledc.c:166] ledcAttachChannel(): LEDC attached to pin 4 (channel 0, resolution 14)
- Subsequent reading of the duty cycle (ledcRead(2), ledcRead(4)) showed duty cycle of 8187 on both pins.
Expected behaviour: new frequency and duty cycle must be ignored, just as it was said in the debug output above:
"[3970527][I][esp32-hal-ledc.c:123] ledcAttachChannel(): Channel 0 is already set up, given frequency and resolution will be ignored"