ESP32-C6的LEDC PWM讯号在light sleep时无法持续产生
Posted: Mon May 06, 2024 9:29 am
大家好!
我使用IDF里的”ledc_basic” example code,并加入了esp_light_sleep_start()进入light sleep。我有参考一些相关问题的帖子,在进入前有设置了ledc timer clock为LEDC_USE_RC_FAST_CLK;及RC_FAST在sleep mode电源打开;并将ledc的gpio 禁止sleep模式。这样的设定,仍无法在light sleep模式下持续产生LEDC讯号。想请问大家是否能提供一些建议? 謝謝。
IDF version: (master)5.4.0
Development board: ESP32-C6-DevKitM-1
Development Platform: Windows, VS Code
底下是我目前使用的程序:
我使用IDF里的”ledc_basic” example code,并加入了esp_light_sleep_start()进入light sleep。我有参考一些相关问题的帖子,在进入前有设置了ledc timer clock为LEDC_USE_RC_FAST_CLK;及RC_FAST在sleep mode电源打开;并将ledc的gpio 禁止sleep模式。这样的设定,仍无法在light sleep模式下持续产生LEDC讯号。想请问大家是否能提供一些建议? 謝謝。
IDF version: (master)5.4.0
Development board: ESP32-C6-DevKitM-1
Development Platform: Windows, VS Code
底下是我目前使用的程序:
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include "esp_sleep.h"
#define LEDC_TIMER LEDC_TIMER_0
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#define LEDC_OUTPUT_IO (7) // Define the output GPIO
#define LEDC_CHANNEL LEDC_CHANNEL_0
#define LEDC_DUTY_RES LEDC_TIMER_10_BIT
#define LEDC_DUTY (16)
#define LEDC_FREQUENCY (4000)
static void example_ledc_init(void)
{
// Prepare and then apply the LEDC PWM timer configuration
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.duty_resolution = LEDC_DUTY_RES,
.timer_num = LEDC_TIMER,
.freq_hz = LEDC_FREQUENCY,
.clk_cfg = LEDC_USE_RC_FAST_CLK
};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
// Prepare and then apply the LEDC PWM channel configuration
ledc_channel_config_t ledc_channel = {
.speed_mode = LEDC_MODE,
.channel = LEDC_CHANNEL,
.timer_sel = LEDC_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = LEDC_OUTPUT_IO,
.duty = 0,
.hpoint = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}
static void ledc_task(void *args)
{
// Set the LEDC peripheral configuration
example_ledc_init();
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
esp_sleep_pd_config(ESP_PD_DOMAIN_RC_FAST, ESP_PD_OPTION_ON);
gpio_sleep_sel_dis(LEDC_OUTPUT_IO);
while(1)
{
printf("Entering light sleep\n");
/* Enter sleep mode */
esp_light_sleep_start();
vTaskDelay(100/portTICK_PERIOD_MS);
}
}
void app_main(void)
{
xTaskCreate(ledc_task, "ledc_task", 4096, NULL, 6, NULL);
}