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