Code to output master clock frequency to CLK_OUT pin?

wdbwdb1
Posts: 6
Joined: Sat Aug 22, 2020 10:43 pm

Code to output master clock frequency to CLK_OUT pin?

Postby wdbwdb1 » Thu Oct 21, 2021 7:42 pm

What is some code I can use to output the master clock frequency to CLK_OUT(0) pin which is GPIO0? I am not able to find it in the programming guide, only info concerning EMAC_CLK_OUT. I want to use GPIO0 because I already have my boot mode button there and I can just probe that to get the signal as I am trying to measure the master clock frequency accurately with a frequency counter. Should this frequency reading be divided at all in code to attain an accurate output? If so how is this done? Additionally, I am using an ESP32-D0WDQ6 and not a module so I don’t have access to the other CLK_OUT pins. Also, will the output to this pin through this function produce a perfectly accurate signal of the master clock worthy of tuning the crystal with?

wdbwdb1
Posts: 6
Joined: Sat Aug 22, 2020 10:43 pm

Re: Code to output master clock frequency to CLK_OUT pin?

Postby wdbwdb1 » Sat Nov 06, 2021 5:21 am

I figured it out.

Code: Select all

#include <stdio.h>
#include "driver/ledc.h"
#include "esp_err.h"

static void ledc_init(void)
{
    ledc_timer_config_t ledc_timer = {};
    ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
    ledc_timer.timer_num = LEDC_TIMER_0;
    ledc_timer.duty_resolution = LEDC_TIMER_1_BIT;
    ledc_timer.freq_hz = 40000000;
    ledc_timer.clk_cfg =  LEDC_USE_APB_CLK; 
 
    ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));

    ledc_channel_config_t ledc_channel = {};
    ledc_channel.speed_mode     = LEDC_HIGH_SPEED_MODE;
    ledc_channel.channel        = LEDC_CHANNEL_0;
    ledc_channel.timer_sel      = LEDC_TIMER_0;
    ledc_channel.intr_type      = LEDC_INTR_DISABLE;
    ledc_channel.gpio_num       = 0;
    ledc_channel.duty           = 1; 
    ledc_channel.hpoint         = 0;

    ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}

extern "C" {
    void app_main() {

        ledc_init();

    }
}

Who is online

Users browsing this forum: No registered users and 126 guests