Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEDC Timer for ESP32-S3 and C3 appears to be half the speed of the timer for the ESP32 WROOM Module #11173

Closed
1 task done
lft8 opened this issue Mar 25, 2025 · 2 comments
Closed
1 task done
Labels
Area: Peripherals API Relates to peripheral's APIs. Type: Question Only question

Comments

@lft8
Copy link

lft8 commented Mar 25, 2025

Board

ESP32-S3 and ESP32-C3

Device Description

ESP32-S3 and ESP32-C3 Dev Boards

Hardware Configuration

PWM issue occurs on all GPIOs on the Dev boards.
Only UART1 is connected to anything external.
Wifi/Bt are not used.

Version

latest master (checkout manually)

IDE Name

Arduino

Operating System

Windows 11

Flash frequency

80MHZ

PSRAM enabled

no

Upload speed

921600

Description

I am migrating a design from an ESP32 Wroom Module to a SOC, preferably the S3.
I am using LEDC to produce PWM outputs.
On both the S3 and C3 dev boards I have tested, the PWM output does not work at the frequency and resolution I was using on the Wroom module (3,000Hz 14 Bit).
It almost seems like the clock used for LEDC on the S3 and C3 is running at half the speed it is on the Wroom module.
I can't find anything in the hardware documentation to suggest this is the case so I assume it is to do with the implementation of LEDC? Or a bug?

Sketch

Tested with the Arduino LEDC examples, modifying the frequency and resolution accordingly.

Debug Message

N/A

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@lft8 lft8 added the Status: Awaiting triage Issue is waiting for triage label Mar 25, 2025
@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Mar 25, 2025

Hi @lft8, by default the XTAL clock is used for the LEDC peripheral on newer chips.
You can change the clock source by calling:

/**
 * @brief Set the LEDC clock source.
 *
 * @param source LEDC clock source to set.
 *
 * @return true if LEDC clock source was successfully set, false otherwise.
 */
bool ledcSetClockSource(ledc_clk_cfg_t source);

Example clock sources for C3:

/**
 * @brief Type of LEDC clock source, reserved for the legacy LEDC driver
 */
typedef enum {
    LEDC_AUTO_CLK = 0,                              /*!< LEDC source clock will be automatically selected based on the giving resolution and duty parameter when init the timer*/
    LEDC_USE_APB_CLK = SOC_MOD_CLK_APB,             /*!< Select APB as the source clock */
    LEDC_USE_RC_FAST_CLK = SOC_MOD_CLK_RC_FAST,     /*!< Select RC_FAST as the source clock */
    LEDC_USE_XTAL_CLK = SOC_MOD_CLK_XTAL,           /*!< Select XTAL as the source clock */

    LEDC_USE_RTC8M_CLK __attribute__((deprecated("please use 'LEDC_USE_RC_FAST_CLK' instead"))) = LEDC_USE_RC_FAST_CLK,   /*!< Alias of 'LEDC_USE_RC_FAST_CLK' */
} soc_periph_ledc_clk_src_legacy_t;

If you want to know all possible frequencies/resolution continuations, you can run this example and check the Serial output with results: https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/AnalogOut/ledcFrequency/ledcFrequency.ino You can also add the other Clock sources to check even more options.

@P-R-O-C-H-Y P-R-O-C-H-Y added Type: Question Only question Area: Peripherals API Relates to peripheral's APIs. and removed Status: Awaiting triage Issue is waiting for triage labels Mar 25, 2025
@Jason2866
Copy link
Collaborator

Closing since no issue. Behaviour is as designed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Type: Question Only question
Projects
None yet
Development

No branches or pull requests

3 participants