Este ejemplo configura el temporizador LEDC PWM a 10 kHz con resolución de 12 bits, emitiendo un PWM con ciclo de trabajo del 50% en IO14. Este código usa la API de ESP-IDF directamente para configurar el PWM
esp32-minimal-ledc-pwm-configuration-example.cpp
#include <Arduino.h>
#include <driver/ledc.h>
void setup() {
Serial.begin(115200);
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_HIGH_SPEED_MODE,
.duty_resolution = LEDC_TIMER_12_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = 10000,
.clk_cfg = LEDC_AUTO_CLK
};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ledc_channel_config_t ledc_channel = {
.gpio_num = GPIO_NUM_14,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = 2048, // Establecer ciclo de trabajo al 50%
.hpoint = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}
void loop() {
}
Echa un vistazo a artículos similares por categoría:
Arduino ESP8266/ESP32 PlatformIO
Si este artículo te ha ayudado, considera invitarme a un café o hacer una donación vía PayPal para apoyar la investigación y publicación de nuevos artículos en TechOverflow