1

Last week for some reason I reinstalled my lap and also arduino ide. The issue I have is that on a code which worked fine on some esp's written before reinstall, now when i deploy it I get this error.

This is the piece of code :

const int PinCh1 = 13;
const int PinCh2 = 15;
const int freq = 5000;
const int Channel1 = 0;
const int Channel2 = 1;
const int resolution = 16;

ledcSetup(Channel1, freq, resolution);
ledcSetup(Channel2, freq, resolution);

This is the error:

E (76891) ledc: requested frequency and duty resolution can not be achieved, try reducing freq_hz or duty_resolution. div_param=63

First time I assumed that is something wrong with the new esp's I bough, but I took one of the old one and I just wrote that code again on it and got same error. So I am almost sure that is something in this last version which I installed on arduino ide...I have no idea what I had before ..

Any idea on this ?

Thanks

lucian_v
  • 111
  • 3
  • 12

1 Answers1

2

Yes, because the resolution depends on the frequency you want to generate. For higher frequencies, you are limited to lower resolutions.

You will have to change this -

const int resolution = 13;

As, 5 kHz can have a maximum duty resolution of 13 bits.

This table lists some commonly used frequencies along with their maximum resolution.

https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf#table.14.1

Note that the max resolution and frequency also depend on the timer you are using. In the Arduino API for LEDC, the selection of timer and other timer configs are taken care of in the background. However, there are 3 timers available to you, each with its own frequency.

There is a formula mentioned just above the table, you can use that formula to calculate the maximum available resolution for your desired frequency.

  • 1
    Hi, and thanks for your answer. You are right, but why that worked like it is BEFORE I did reinstall? So is not an assumption, is tested thing ...same code, same esp32 just different ide ..what has been changed between some versions ? – lucian_v Jan 23 '23 at 07:05
  • 1
    LEDC is a hardware peripheral. You have 3 timer options to implement LEDC. The fastest one is APB_CLK (80 MHz). 5Khz is for the fastest clock gives you a 13-bit resolution. Choosing other slower clocks will get you even lower resolution. So, that quite unlikely. – Tashfi Nowroz Jan 23 '23 at 10:26