ESP32-C3 trying to output 40MHz on GPIO10
Posted: Mon Jul 07, 2025 9:46 pm
In order to probe the crystal frequency without touching it, I want to create a periodic wave on GPIO10 to measure using my frequency counter. This is commonplace in other MCUs with a MCO (master clock output) function.
Unfortunately when I program the ESP32-C3 chip with the above code, it fails to ouput a periodic wave on GPIO10. I'm not sure what is wrong, want to take a look?
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));
}
}