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 resolution issue #11164

Closed
1 task done
Vladislav-Jovanov opened this issue Mar 22, 2025 · 3 comments
Closed
1 task done

LEDC resolution issue #11164

Vladislav-Jovanov opened this issue Mar 22, 2025 · 3 comments
Labels
Type: Question Only question

Comments

@Vladislav-Jovanov
Copy link

Vladislav-Jovanov commented Mar 22, 2025

Board

ESP32 Dev Board

Device Description

Terminal adapter

Hardware Configuration

GPIO 5,2,14 were tested out

Version

latest master (checkout manually)

IDE Name

Arduion IDE

Operating System

Linux Mint

Flash frequency

40 MHz

PSRAM enabled

yes

Upload speed

115200

Description

I am not sure if this is a software or hardware issue.
I was testing out different combinations of frequency and ledc resolution and duty cycle. I wanted to set resolution to LEDC_TIMER_1_BIT and duty to 1 (50%) and then to vary frequency from really low (few Hz to MHz).

What I noticed was that combination LEDC_TIMER_1_BIT and duty of 1 does not work for low frequencies below 489 Hz. I don't understand why. Is that a software or hardware issue? In technical documentation there is no information about this. An answer to this issue would be sufficient.

Sketch

#include "driver/ledc.h"

#if defined (ESP32)
    #define LEDC_TIMER              LEDC_TIMER_0
    #define LEDC_MODE               LEDC_HIGH_SPEED_MODE
    #define LEDC_CHANNEL            LEDC_CHANNEL_0
    #define LEDC_DUTY_RES           LEDC_TIMER_1_BIT // Set duty resolution to 13 bits
    #define LEDC_DUTY               1 // Set duty to 50%. (2 ** 8) * 50% = 4096
    #define LEDC_FREQUENCY          1 // Frequency in Hertz. Set frequency at 4 kHz
#endif

#define LED_GPIO 5

void setup() {
  #if defined (ESP32)
        ledc_timer_config_t ledc_timer = {
            .speed_mode       = LEDC_MODE,
            .duty_resolution  = LEDC_DUTY_RES,
            .timer_num        = LEDC_TIMER,
            .freq_hz          = LEDC_FREQUENCY,  // Set output frequency at 5 kHz
            .clk_cfg          = LEDC_AUTO_CLK
        };

        ledc_channel_config_t ledc_channel = {
            .gpio_num       = LED_GPIO,
            .speed_mode     = LEDC_MODE,
            .channel        = LEDC_CHANNEL,
            .intr_type      = LEDC_INTR_DISABLE,
            .timer_sel      = LEDC_TIMER,
            .duty           = LEDC_DUTY, // Set duty to 0%
            .hpoint         = 0 //phase shift
        };
        ledc_timer_config(&ledc_timer);
        ledc_channel_config(&ledc_channel);
    #endif
}

void loop() {

}

Debug Message

No message.

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.
@Vladislav-Jovanov Vladislav-Jovanov added the Status: Awaiting triage Issue is waiting for triage label Mar 22, 2025
@lbernstone
Copy link
Contributor

This is a hardware issue. The peripheral is designed primarily for controlling LEDs, so it is not capable of working at very low frequencies. There are other peripherals that will work. I don't know your use case, but I would recommend either SDM or the wave generator

@P-R-O-C-H-Y
Copy link
Member

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

Hi, also you are using ESP-IDF APIs, please refer to https://docs.espressif.com/projects/arduino-esp32/en/latest/api/ledc.html
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

@P-R-O-C-H-Y P-R-O-C-H-Y added Type: Question Only question and removed Status: Awaiting triage Issue is waiting for triage labels Mar 25, 2025
@Jason2866
Copy link
Collaborator

Closing since not an issue. The question is answered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Only question
Projects
None yet
Development

No branches or pull requests

4 participants