Last active
November 12, 2024 00:22
-
-
Save mwicat/085e11cfd0171fac29cb5adc796d759e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include "freertos/FreeRTOS.h" | |
#include "freertos/task.h" | |
#include "driver/ledc.h" | |
void setup() | |
{ | |
ledc_timer_config_t ledc_timer; | |
memset(&ledc_timer, 0, sizeof(ledc_timer_config_t)); | |
ledc_timer.duty_resolution = LEDC_TIMER_8_BIT; // resolution of PWM duty | |
ledc_timer.freq_hz = 500; // frequency of PWM signal | |
ledc_timer.speed_mode = LEDC_LOW_SPEED_MODE; // timer mode | |
ledc_timer.timer_num = LEDC_TIMER_0; // timer index | |
ledc_timer_config(&ledc_timer); | |
ledc_channel_config_t channel_config; | |
memset(&channel_config, 0, sizeof(ledc_channel_config_t)); | |
channel_config.channel = LEDC_CHANNEL_0; | |
channel_config.duty = 127; | |
channel_config.gpio_num = GPIO_NUM_16; | |
channel_config.speed_mode = LEDC_LOW_SPEED_MODE; | |
channel_config.timer_sel = LEDC_TIMER_0; | |
channel_config.intr_type = LEDC_INTR_DISABLE; | |
ledc_channel_config(&channel_config); | |
printf("Freq: %u\n", ledc_get_freq(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0)); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment