Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "esp_err.h"
void app_main() {
// Configure the LEDC timer
ledc_timer_config_t timer_conf;
timer_conf.speed_mode = LEDC_LOW_SPEED_MODE;
timer_conf.duty_resolution = LEDC_TIMER_1_BIT;
timer_conf.timer_num = LEDC_TIMER_0;
timer_conf.freq_hz = 40000000;
//timer_conf.clk_cfg = APB_CLK;
timer_conf.clk_cfg = LEDC_USE_XTAL_CLK;
timer_conf.deconfigure = false;
ledc_timer_config(&timer_conf);
// Configure the LEDC channel
ledc_channel_config_t channel_conf;
channel_conf.gpio_num = 10; // Pin 16 GPIO-10
channel_conf.speed_mode = LEDC_LOW_SPEED_MODE;
channel_conf.channel = LEDC_CHANNEL_0;
channel_conf.intr_type = LEDC_INTR_DISABLE;
channel_conf.timer_sel = LEDC_TIMER_0;
channel_conf.duty = 0;
channel_conf.hpoint = 0;
ledc_channel_config(&channel_conf);
// Start the output
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
// Keep the task running
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));
}
}