Skip to content

analogWriteResolution not working #11670

@vladtepesch

Description

@vladtepesch

Related area

analogWriteResolution and analogWriteFrequency only output errors

Hardware specification

ESP Wroom32

Is your feature request related to a problem?

I Initially posted this here: pioarduino/platform-espressif32#230 (comment)

But I was told I should open an issue here.

PROBLEM DESCRIPTION

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);
  analogWriteResolution(LED_R, 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

The (start of the) build output (used Packages)

Processing esp32 (platform: https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip; board: upesy_wroom; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/upesy_wroom.html
PLATFORM: Espressif 32 (54.3.21) > uPesy ESP32 Wroom DevKit
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.2.1
 - framework-arduinoespressif32-libs @ 5.4.0+sha.858a988d6e
 - tool-esptoolpy @ 5.0.0
 - toolchain-xtensa-esp-elf @ 14.2.0+20241119
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft

TO REPRODUCE

see code above

EXPECTED BEHAVIOUR

correct pwm setup

SCREENSHOTS

n.a.

ADDITIONAL CONTEXT

I posted this Problem on SO

A sugestion was to set resolution and frequency by directly using ledcAttach. this works as expecteds - so we came to the conclusion that most probably this is a library bug.

(Please, remember to close the issue when the problem has been addressed)

Describe the solution you'd like

working arduino api functions

Describe alternatives you've considered

No response

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.

Metadata

Metadata

Assignees

Labels

Area: LibrariesIssue is related to Library support.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions