Configuring MCPWM in ESP32
Posted: Sat Jan 17, 2026 10:43 pm
Hi I was trying to configure the MCPWM in ESP32 DEV V3. At first I was trying to configure it manually through the registers and the data sheet, no success. Then I tried to use the "driver/mcpwm.h" library (code below) and it still didn't work.It should give me a both 1 and 0 on the serial or at least something similar to a PWM on the plotter; however it returns me only 0 or 1. Any tips? Kinda new to the ESPs chips. I am using PROGRAM.IO with the arduino framework.
Code: Select all
#include "driver/mcpwm.h"
#include "soc/mcpwm_struct.h"
#include "soc/gpio_struct.h"
#include <Arduino.h>
// Definições
#define PIN_PWM 25
#define UNIT MCPWM_UNIT_0
#define TIMER MCPWM_TIMER_0
#define OPERATOR MCPWM_OPR_A
void setup() {
Serial.begin(115200);
mcpwm_gpio_init(UNIT, MCPWM0A, PIN_PWM);
mcpwm_config_t pwm_config;
pwm_config.frequency = 1000;
pwm_config.cmpr_a = 50;
pwm_config.counter_mode = MCPWM_UP_COUNTER;
pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
mcpwm_init(UNIT, TIMER, &pwm_config);
Serial.println("MCPWM Inicializado!");
}
void loop() {
Serial.println(((GPIO.in>>25)&0x01));
delay(100);
}
}