Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

ESP32 PWM (LEDC) calculator

On the ESP32, faster PWM means fewer duty steps. Pick a frequency, see how fine your control can be.

Hz
bits
—

Common frequencies

FrequencyUseMax bits (ESP32)Max bits (C3/S3)
50 HzHobby servo2014
1 kHzLED dimming (visible flicker-free)1614
5 kHzLED dimming, Arduino-ESP32 examples1313
20 kHzDC motor (above hearing)1111
25 kHzPC fan (Intel 4-wire spec)1111

How it works

The LEDC peripheral counts a source clock. In one PWM period it can count at most source ÷ frequency ticks, so the number of duty steps is limited by:

max bits = floor(log₂(80 000 000 ÷ f))    (capped by the chip's timer width)

We assume the 80 MHz APB clock, which Arduino-ESP32's ledcAttach() uses for these frequencies. The timer width limit is 20 bits on the original ESP32 and the C6, and 14 bits on the S2, S3 and C3 (ESP-IDF LEDC driver documentation, SOC_LEDC_TIMER_BIT_WIDTH).

Notes

  • Arduino-ESP32 3.x: ledcAttach(pin, freq, bits) then ledcWrite(pin, duty) with duty from 0 to 2bits − 1. The 2.x API (ledcSetup/ledcAttachPin) is gone.
  • If you ask for more bits than allowed, ledcAttach() fails and returns false — check its return value.
  • Servos need 50 Hz; 14–16 bits gives smooth angle control (a 1–2 ms pulse spans about 820–1640 steps at 14 bits).

↑↓ to move · Enter to open