ESP32-C3-DevKitM-1 PWM problem
Posted: Wed Apr 27, 2022 3:30 am
Hello everyone,
We are interfacing an IR camera with the ESP32-C3-DevKitM-1. Because the camera needs a 3MHz clock to drive so we used LEDC to generate a 3MHz PWM signal with 50% duty cycle.
But we found out that the negative edge of PWM signal is glittering: May we have any suggestions to the problem? Thank you all.
Here is our code :
We are interfacing an IR camera with the ESP32-C3-DevKitM-1. Because the camera needs a 3MHz clock to drive so we used LEDC to generate a 3MHz PWM signal with 50% duty cycle.
But we found out that the negative edge of PWM signal is glittering: May we have any suggestions to the problem? Thank you all.
Here is our code :
Code: main.c Select all
/* LEDC (LED Controller) basic example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "driver/ledc.h"
#include "esp_err.h"
/*
* PWM Output configuration
*/
#define LEDC_TIMER LEDC_TIMER_0 //Using Timer0 as clock source
#define LEDC_MODE LEDC_LOW_SPEED_MODE //Setting speed mode to low
#define LEDC_OUTPUT_IO (2) //Using GPIO 2 as PWM output
#define LEDC_CHANNEL LEDC_CHANNEL_0 //Using PWM channel 0
#define LEDC_DUTY_RES LEDC_TIMER_4_BIT //Setting duty resolution
#define LEDC_DUTY (8) //Setting duty cycle to 50%. ((2 ** 2) - 1) * 50% = 8
#define LEDC_FREQUENCY (3000000) //Setting PWM Frequency (Hz)
/*
* pwm_init
*
* Initialise PWM controller
*/
static void pwm_init(void)
{
// Prepare and then apply the LEDC PWM timer configuration
ledc_timer_config_t ledc_timer = {0};
ledc_timer.speed_mode = LEDC_MODE;
ledc_timer.timer_num = LEDC_TIMER;
ledc_timer.duty_resolution = LEDC_DUTY_RES;
ledc_timer.freq_hz = LEDC_FREQUENCY;
ledc_timer.clk_cfg = LEDC_AUTO_CLK;
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
// Prepare and then apply the LEDC PWM channel configuration
ledc_channel_config_t ledc_channel = {0};
ledc_channel.speed_mode = LEDC_MODE;
ledc_channel.channel = LEDC_CHANNEL;
ledc_channel.timer_sel = LEDC_TIMER;
ledc_channel.intr_type = LEDC_INTR_DISABLE;
ledc_channel.gpio_num = LEDC_OUTPUT_IO;
ledc_channel.duty = 0;
ledc_channel.hpoint = 0;
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}
/*
* app_main
* Program entry point
*/
void app_main(void)
{
pwm_init();
// Set duty to 50%
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
// Update duty to apply the new value
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
while(1);
}