Code: Select all
#include "driver/ledc.h"
#include "driver/periph_ctrl.h"
#include "esp_system.h"
#include "sdkconfig.h"
#include <stdio.h>
#include <math.h>
#define var_gpio_num 15
#define var_freq_hz 305
#define var_pulse_length 0.00000005
#define var_duty_resolution LEDC_TIMER_18_BIT
void app_main()
{
periph_module_enable(PERIPH_LEDC_MODULE);
int var_duty = var_freq_hz*var_pulse_length*262144;
ledc_timer_config_t ledc_timer = {
.duty_resolution = var_duty_resolution,
.freq_hz = var_freq_hz,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_num = LEDC_TIMER_0,
};
ledc_timer_config(&ledc_timer);
ledc_channel_config_t channel_config = {
.channel = LEDC_CHANNEL_0,
.duty = var_duty,
.gpio_num = var_gpio_num,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_sel = LEDC_TIMER_0
};
ledc_channel_config(&channel_config);
}