[Solved] LEDC Highspeed PWM
Posted: Thu Mar 23, 2017 6:49 pm
Hi, I am trying to supply a clock signal to a external device at a frequency of at least 10 MHz with the LEDC peripheral. After looking through a lot of the questions and answers on the forum it sounds quite possible, but when I gave it a shot the ESP32 seemed unable to provide a square wave at that high of a frequency. Here is a screen shot of my 10 MHz signal:
Here is the setup code I used for the LEDC module with defined values given in comments:
Is there anything wrong in my LEDC config? Is LEDC the correct tool to generate this clock signal, or is there a better option?
Thanks,
- Brett
Here is the setup code I used for the LEDC module with defined values given in comments:
Code: Select all
esp_err_t image_init_clock(void) {
ledc_timer_bit_t bit_num = (ledc_timer_bit_t) XVCLK_BIT_ACCURACY; // 3
// Enable LEDC PWM peripheral
periph_module_enable(PERIPH_LEDC_MODULE);
// Set Duty
int duty = pow(2, (int) bit_num) / 2;
// setup the timer
ledc_timer_config_t xvclk_timer;
xvclk_timer.bit_num = bit_num; // 3
xvclk_timer.freq_hz = XVCLK_FREQ; // 10000000
xvclk_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
xvclk_timer.timer_num = LEDC_TIMER_0;
ledc_timer_config(&xvclk_timer);
// setup the pwm channel
ledc_channel_config_t servo_channel;
servo_channel.channel = LEDC_CHANNEL_0;
servo_channel.duty = duty;
servo_channel.gpio_num = IMG_XVCLK; // GPIO_NUM_4
servo_channel.intr_type = LEDC_INTR_DISABLE;
servo_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
servo_channel.timer_sel = LEDC_TIMER_0;
ledc_channel_config(&servo_channel);
// Set the PWM to the duty specified
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, duty);
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
return ESP_OK;
}
Thanks,
- Brett