ESP32 LEDC PWM Calculator
Calculate ESP32 LEDC PWM frequency, duty resolution, divider, and duty values. Use practical settings for ESP-IDF and Arduino firmware projects.
What is ESP32 LEDC PWM?
LEDC is the ESP32 PWM peripheral used for LED dimming, motor control, buzzers, and many firmware timing tasks with configurable frequency and duty resolution.
PWM frequency vs duty resolution
Higher PWM frequency usually requires lower duty resolution. Lower frequency gives more room for higher resolution, which is useful for smoother dimming.
How to calculate ESP32 LEDC divider
A practical formula is pwm_freq = clock / (divider * 2^resolution). Rearranging gives divider = clock / (pwm_freq * 2^resolution).
Common ESP32 PWM settings
| Use case | Frequency | Resolution | Notes |
|---|---|---|---|
| LED dimming | 1 kHz | 10-12 bit | Smooth brightness control |
| Servo control | 50 Hz | 12-16 bit | Pulse width control |
| Motor PWM | 20 kHz | 8-10 bit | Above audible range |
| Buzzer | 2 kHz | 8 bit | Simple tone output |
| High speed PWM | 40 kHz | 8 bit | Lower resolution at higher frequency |
Arduino and ESP-IDF output notes
Clock source options, divider range, and APIs can vary by ESP32 family and SDK version. Use these values as practical starting points and verify in your target environment.
FAQ
What is ESP32 LEDC?
ESP32 LEDC is a hardware PWM block that controls output frequency and duty with configurable timer and resolution settings.
How do frequency and duty resolution affect each other?
For a fixed clock, increasing frequency leaves less divider room, so the maximum usable duty resolution decreases.
What PWM frequency should I use for motors or LEDs?
It depends on the load. LEDs often use around 1 kHz, while motor PWM is often set near or above the audible range such as 20 kHz.
Why is my ESP32 PWM frequency not exact?
Divider steps and hardware constraints can force rounding, so actual frequency can differ slightly from the requested target.