Skip to content

Instantly share code, notes, and snippets.

@benpeoples
Created June 1, 2020 16:03
Show Gist options
  • Save benpeoples/3aa57bffc0f26ede6623ca520f26628c to your computer and use it in GitHub Desktop.
Save benpeoples/3aa57bffc0f26ede6623ca520f26628c to your computer and use it in GitHub Desktop.
ESP32 LEDC Maximum frequency by resolution
Per this forum post: https://esp32.com/viewtopic.php?t=6701
The way to calculate max PWM frequency is integer (log 2 (LEDC_APB_CLK / frequency))
With a LEDC_APB_CLK == 80MHz, these are the following maximum values, in Hz:
LEDC_TIMER_1_BIT, 40000000
LEDC_TIMER_2_BIT, 20000000
LEDC_TIMER_3_BIT, 10000000
LEDC_TIMER_4_BIT, 5000000
LEDC_TIMER_5_BIT, 2500000
LEDC_TIMER_6_BIT, 1250000
LEDC_TIMER_7_BIT, 625000
LEDC_TIMER_8_BIT, 312500
LEDC_TIMER_9_BIT, 156250
LEDC_TIMER_10_BIT, 78125
LEDC_TIMER_11_BIT, 39062
LEDC_TIMER_12_BIT, 19531
LEDC_TIMER_13_BIT, 9765
LEDC_TIMER_14_BIT, 4882
LEDC_TIMER_15_BIT, 2441
LEDC_TIMER_16_BIT, 1220
LEDC_TIMER_17_BIT, 610
LEDC_TIMER_18_BIT, 305
LEDC_TIMER_19_BIT, 152
LEDC_TIMER_20_BIT, 76
@alayshoo
Copy link

alayshoo commented Jun 23, 2025

Hi,

Frustrated with setting random values on ledcAttach for an ESP32-S3 and the ledcAttach failing so I went looking and found this on a forum.

Still, trying these values didn't lead me anywhere so I tried a small routine to check the maximums on the ESP32-S3. My values seemed to be about half of these and in some Espressiff docs or datasheets I found a reference to the base clock being 40MHz for the ESP32-S3. This would indicate that one just needs to shift one value to find the right maximum (8bit max of the OG ESP32 would be the 7 bit max of the S3).

I might be wrong on this but leaving this bit of information here just in case someone with an S3 finds it useful.

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