0

I try to setup a 10bit pwm with analogWriteResolution(LED_R, 10); but I get the following output:

[esp32-hal-ledc.c:793] analogWriteResolution(): analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first

then I tried to explicitely set the frequency analogWriteFrequency(LED_R,1000);

then I get an additional message:

[esp32-hal-ledc.c:785] analogWriteFrequency(): analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first

void setup() {
  ledcSetClockSource(LEDC_USE_APB_CLK);
  analogWriteFrequency(LED_R,1000);
  analogWriteFrequency(LED_G,1000);
  analogWriteFrequency(LED_B,1000);
  analogWriteResolution(LED_R, 10);
  analogWriteResolution(LED_G, 10);
  analogWriteResolution(LED_B, 10);
}

I really do not understand the problem. 10bit @ 1khz requires a timerfrequency of 1Mhz which should be achievable without problems.

my platormio.ini

[env:esp32]

platform =  https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
board = upesy_wroom
board_build.mcu = esp32

board_build.f_cpu = 240000000L

framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
#build_type = debug
#upload_port = COM6
board_build.filesystem = littlefs

build_unflags = -std=gnu++11
                -std=c++11

build_flags =
    -std=c++17
    -std=gnu++17
4
  • First, what pins are you using? Second, what if you used 'ledcAttach(..)' and set the resolution and freqeuncy at the same time? This might give a less contradictory error message than the two you're getting from breaking this into two steps. Commented Jul 23 at 13:49
  • Pins are 0,4,5. Using ledc-API seems to work correctly - so most probably some bug in the Framework-Library?! but using the esp specific lib function means I would have to change all components from the arduino functions to the esp-specific ones Commented Jul 23 at 14:23
  • Yeah I would agree it's a bug, or some non trivial expectation of how those functions would be called. Is there some reason you don't want to use the esp-specific libraries? Your platormio.ini already specifies an esp for the platform, and your already calling an ledc function with 'ledcSetClockSource(..)'. Doing a little searching around I don't see why your custom setting of the freq and resolution isn't working as intended. But, the ledc api does seem to accomplish the same thing. Commented Jul 23 at 15:23
  • @hcheung what does the analogReadResolution has to do with this? Commented Jul 24 at 20:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.