Skip to content

ESP32-S3 Ledc different resolutions cause wrong duty update #11373

@handmade0octopus

Description

@handmade0octopus

Board

Custom ESP32-S3 board

Device Description

Custom Gauge.S board

Hardware Configuration

[    123][I][esp32-hal-ledc.c:166] ledcAttachChannel(): LEDC attached to pin 10 (channel 0, resolution 8)
[  1791][I][esp32-hal-ledc.c:166] ledcAttachChannel(): LEDC attached to pin 3 (channel 1, resolution 14)

Version

v3.2.0

IDE Name

PlatformIO

Operating System

W11

Flash frequency

80mhz

PSRAM enabled

yes

Upload speed

Default

Description

When setting different resolutions on different channels, second one called disrupts duty resolution calculation and frequency.

Basically I set first one to pin 10 to control backlight LED at 500hz frequency and 8 bit resolution.

Then I use 400Hz PWM output on 14 bit resolution.

After second one is setup the first one goes from very well working to 29 Hz at ~1% duty cycle (measured with scope).

Sketch

not relevant

Debug Message

Got scope trace but its not very interesting.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Activity

self-assigned this
on May 19, 2025
P-R-O-C-H-Y

P-R-O-C-H-Y commented on May 19, 2025

@P-R-O-C-H-Y
Member

Hi @handmade0octopus, Thank you for reporting that. I will try to reproduce and will keep you updated about next steps.

P-R-O-C-H-Y

P-R-O-C-H-Y commented on May 29, 2025

@P-R-O-C-H-Y
Member

Hi @handmade0octopus, I have tested this issue today and I was able to reproduce. How ever, the solution for you will be to specify the channels to use to avoid this.
The thing is that ESP32S3 have 8 LEDC channels and 4 LEDC Timers. So each 2 channels are sharing 1 timer:
Channel 0 and 1 -> TIMER 0
Channel 2 and 3 -> TIMER 1
Channel 4 and 5 -> TIMER 2
Channel 6 and 7 -> TIMER 3

So you cannot set different timer resolutions for the same timer, as in your case you was probably using auto channel picking so it was 0 and 1. I was able to reproduce your behavior with those channels. Please do this instead:

ledcAttachChannel(10, 400, 14, 0); // the last parameter is channel
ledcAttachChannel(11, 500, 8, 2);

I will add some check if the timer is used with different resolution to log an Error message to avoid this in future.
PLease test and let me know if that solves the issue. I have tested and it works fine when using another group of channels that uses different timers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @handmade0octopus@P-R-O-C-H-Y

    Issue actions

      ESP32-S3 Ledc different resolutions cause wrong duty update · Issue #11373 · espressif/arduino-esp32