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.
How to figure LEDC max resolution?
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: How to figure LEDC max resolution?
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
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
Who is online
Users browsing this forum: No registered users and 92 guests