Skip to content

Add missing LEDC light sleep requirements to documentation #9292

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

Closed
1 task done
zackees opened this issue Feb 27, 2024 · 5 comments
Closed
1 task done

Add missing LEDC light sleep requirements to documentation #9292

zackees opened this issue Feb 27, 2024 · 5 comments
Assignees
Labels
Area: ESP-IDF related ESP-IDF related issues

Comments

@zackees
Copy link

zackees commented Feb 27, 2024

Board

ESP32*

Device Description

This is a generic bug report and applies to all devices with the ESP32 that can do light sleep for the LEDC

Hardware Configuration

I'm personally using the XIAO ESP32C3, but it applies to other devices as well.

Version

latest development Release Candidate (RC-X)

IDE Name

PlatformIO

Operating System

Windows10

Flash frequency

default

PSRAM enabled

no

Upload speed

115200

Description

This page in the documentation for LEDC does not contain all the required information to allow the LEDC device to continue functioning in light sleep: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html

It's currently missing the following:

ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC8M, ESP_PD_OPTION_ON));
ESP_ERROR_CHECK(gpio_sleep_sel_dis(PIN_LEDC)); // Needed for light sleep.

Sketch

I've posted the minimal code sample here

#include <math.h>
#include <Arduino.h>
#include <stdio.h>

#include "driver/ledc.h"
#include "esp_err.h"
#include "driver/ledc.h"

#include "defs.h"
#include "pseudo_i2s.h"

#include "esp32-hal-ledc.h"

#define LEDC_TIMER LEDC_TIMER_0
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#define LEDC_CHANNEL LEDC_CHANNEL_0
#define LEDC_DUTY_RES LEDC_TIMER_1_BIT // Set duty resolution to 13 bits
#define LEDC_FREQUENCY (1024 * 1024)  // 1 mhz clock.
#define PIN_PSUEDO_I2S GPIO_NUM_6

// #define LEDC_CLOCK LEDC_USE_RC_FAST_CLK  // still clocks during light sleep.
#define LEDC_CLOCK LEDC_USE_RTC8M_CLK  // still clocks during light sleep.

namespace
{
  enum {
    // use bith manipuation against the LEDC_TIMER_8_BIT to come to a max duty.
    // For example, if LEDC_TIMER_8_BIT is 8, then the max duty is 255.
    kMaxDuty = (1 << LEDC_DUTY_RES) - 1,
  };
  ledc_timer_config_t ledc_timer = {
      //.duty_resolution  = LEDC_TIMER_13_BIT, // resolution of PWM duty
      .speed_mode = LEDC_MODE,
      .duty_resolution = LEDC_DUTY_RES,
      .timer_num = LEDC_TIMER,
      .freq_hz = LEDC_FREQUENCY, // Set output frequency
      .clk_cfg = LEDC_CLOCK
    };

  // Prepare and then apply the LEDC PWM channel configuration
  ledc_channel_config_t ledc_channel = {
      .gpio_num = PIN_PSUEDO_I2S,
      .speed_mode = LEDC_MODE,
      .channel = LEDC_CHANNEL,
      .intr_type = LEDC_INTR_DISABLE,
      .timer_sel = LEDC_TIMER,
      .duty = 0,
      .hpoint = 0,
      .flags = {
        .output_invert = 1,
      }
  };

} // namespace

void pseudo_i2s_start()
{
  //rtc_clk_slow_freq_set(RTC_SLOW_FREQ_8MD256);
  std::cout << "pseudo_i2s_start\n";
  std::flush(std::cout);
  ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC8M, ESP_PD_OPTION_ON));
  ESP_ERROR_CHECK(gpio_sleep_sel_dis(PIN_PSUEDO_I2S)); // Needed for light sleep.
  // Prepare and then apply the LEDC PWM timer configuration
  ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
  ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
  ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 1));
  std::cout << "pseudo_i2s_start done\n";
  std::flush(std::cout);
  ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  std::cout << "pseudo_i2s_start done\n";
  std::flush(std::cout);

}

void pseudo_i2s_stop()
{
  ESP_ERROR_CHECK(ledc_stop(LEDC_MODE, LEDC_CHANNEL, 0));
  pinMode(PIN_PSUEDO_I2S, INPUT);
}


### Debug Message

```plain
There is no debug message. This is a documentation request.

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.
@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Feb 27, 2024

Hi @zackees, you are using LEDC driver directly from ESP-IDF, so I am not sure how it's related to the ESP32 Arduino core? Is it just about missing info/example in docs?

@P-R-O-C-H-Y P-R-O-C-H-Y self-assigned this Feb 27, 2024
@zackees
Copy link
Author

zackees commented Feb 27, 2024

Oh, this is actually ESP-IDF. I didn't realize this was the arduino-esp32 repo. Should I refile the bug in the proper repo?

Yes, this is only a request for a documentation update.

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

@igrr @Alvin1Zhang Can we transfer this issue to the ESP-IDF repository? Thanks

@zackees
Copy link
Author

zackees commented Feb 27, 2024

I think they need to copy it, I'll go ahead and do it.

@zackees
Copy link
Author

zackees commented Feb 27, 2024

I've gone ahead and moved this to the esp-idf repo.

espressif/esp-idf#13278

@zackees zackees closed this as completed Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ESP-IDF related ESP-IDF related issues
Projects
None yet
Development

No branches or pull requests

2 participants