Page 1 of 1

How to figure LEDC max resolution?

Posted: Wed Aug 08, 2018 10:20 pm
by Greg Corson
In the docs they mention that for the LEDC the higher you set the PWM frequency the less bits of resolution you can have, but I'm not clear on how you figure the max resolution for a given frequency.

I'm using 20khz PWM frequency, what would the max resolution be at this frequency? I would like to use 12 bits.

I imagine there is a simple formula for figuring this out, I just haven't found it in the references yet.

Re: How to figure LEDC max resolution?

Posted: Thu Aug 09, 2018 6:01 pm
by ESP_krzychb
Hi Greg Corson,

The max duty resolution and PWM frequency is achieved when clk_src = LEDC_APB_CLK (80 MHz).

In such a case you can calculate duty resolution as: integer (log 2 (LEDC_APB_CLK / frequency)).

For example, for 20kHz PWM frequency:
* 80 MHz / 20 kHz = 4000
* log 2 (4000) = 11.965...
* integer(11.96) = 11 bits

If you like to get 12 bits, then slightly lower PWM frequency from 20 kHz to 80 MHz / 2^12 = 19.531 kHz