Creating >10MHz clock using PWM and LEDC
Posted: Sun Dec 20, 2020 11:03 pm
Hi,
I'm hoping someone can help as this is driving me mad!
I'm trying to generate a square wave clock signal from the ESP32 GPIO0 with a frequency of 13MHz and a 50% duty cycle. From what I've read elsewhere, it seems that a clock up to 40MHz should be possible using LEDC with a timer duty resolution of 1 bit. The best I can get is 4MHz (see below) before other effects seem to happen (like inconsistent duty cycles and unexpected frequencies). For example, when I set the frequency to 13MHz, I get the attached waveform at 1.6/2.66MHz. Even below 4MHZ, I cannot seem to set precise frequencies with a 50% duty cycle.
Would anyone have any ideas? Could it be an issue with the LEDC_HIGH_SPEED_MODE perhaps?
Thanks,
I'm hoping someone can help as this is driving me mad!
I'm trying to generate a square wave clock signal from the ESP32 GPIO0 with a frequency of 13MHz and a 50% duty cycle. From what I've read elsewhere, it seems that a clock up to 40MHz should be possible using LEDC with a timer duty resolution of 1 bit. The best I can get is 4MHz (see below) before other effects seem to happen (like inconsistent duty cycles and unexpected frequencies). For example, when I set the frequency to 13MHz, I get the attached waveform at 1.6/2.66MHz. Even below 4MHZ, I cannot seem to set precise frequencies with a 50% duty cycle.
Would anyone have any ideas? Could it be an issue with the LEDC_HIGH_SPEED_MODE perhaps?
Thanks,
Code: Select all
void init_lecd() {
// set LEDC timer
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_timer.duty_resolution = LEDC_TIMER_1_BIT;
ledc_timer.timer_num = LEDC_TIMER_0;
ledc_timer.freq_hz = 4000000;
// set LEDC channel
ledc_channel.channel = LEDC_CHANNEL_0;
ledc_channel.duty = 1;
ledc_channel.gpio_num = 0;
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_channel.timer_sel = LEDC_TIMER_0;
// Set timer configuration
ledc_timer_config(&ledc_timer);
// Set channel configuration
ledc_channel_config(&ledc_channel);
//PIN_FUNC_SELECT(PIN_CTRL, CLK_OUT1_S);
//PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
}