ESP32-C3: LEDC output during light sleep / low power mode

TorinCB
Posts: 1
Joined: Thu May 26, 2022 2:12 pm

ESP32-C3: LEDC output during light sleep / low power mode

Postby TorinCB » Thu May 26, 2022 2:37 pm

Hello all,

My goal is simple: to get an ESP32-C3 LEDC peripheral to output a PWM signal during light sleep.

The technical reference manual states that this is possible if FOSC_CLK is selected as the common clock source for the LEDC peripheral. This is achieved in ESP-IDF by setting `ledc_timer_config_t.clk_cfg` to `LEDC_USE_RTC8M_CLK` (if you dig into the HAL, you'll see that this results in `APB_CLK_SEL` being set to 2, which is the value for FOSC_CLK according to the manual).

My simple test program below sets up the LEDC peripheral and then toggles between power-on and light sleep. (I have it hooked up to a power profiler, so I can definitely tell that light sleep is achieved.)

Code: Select all

extern "C" {

void app_main()
{
    const ledc_timer_config_t timer_cfg = {
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .duty_resolution = LEDC_TIMER_14_BIT,
        .timer_num = LEDC_TIMER_0,
        .freq_hz = 1000,
        .clk_cfg = LEDC_USE_RTC8M_CLK,
    };
    ESP_ERROR_CHECK(ledc_timer_config(&timer_cfg));

    const ledc_channel_config_t chan_cfg = {
        .gpio_num = 8,
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .channel = LEDC_CHANNEL_0,
        .intr_type = LEDC_INTR_DISABLE,
        .timer_sel = LEDC_TIMER_0,
        .duty = 0,
        .hpoint = 0,
        .flags = {
            .output_invert = 0,
        },
    };
    ESP_ERROR_CHECK(ledc_channel_config(&chan_cfg));

    ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 1 << 13));
    ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));

    while (true) {
        // full power 1 sec
        vTaskDelay(pdMS_TO_TICKS(1000));

        // low power 1 sec
        ESP_ERROR_CHECK(esp_sleep_enable_timer_wakeup(1000000));
        ESP_ERROR_CHECK(esp_light_sleep_start());
    }
}

}
I've tried with IO7 and IO8 (on this board, there are limited exposed free GPIO).

I find consistently that the output is perfect during power-on, but remains at 0V during light sleep.

Can anyone please spot what I may have missed?

My board is using a ESP32-C3-MINI-1 module. We utilise a 32.768 kHz external crystal as our RTC source (to allow BLE modem sleep during light sleep), but for the purposes of this, I've disabled it in sdkconfig.

Who is online

Users browsing this forum: MicroController and 112 guests