PlatformIO Community

MCPWM Capture not working on ESP32 with Arduino framework

I’m using PlatformIO on VS Code with ESP-IDF 3.3.5 and I the ISR on the following code won’t fire.

I’ve attached an external PWM signal on GPIO 25 and I call ADC_PWM_Init() on setup(). When I read the adc_pwm_ticks (during the main loop()), the struct fields are all zero. I can tell that the ISR is not firing because I’ve placed Serial.print(“isr is firing”); on the first of the ISR on a previous code version and got no message on the UART…

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "soc/rtc.h"
#include "driver/mcpwm.h"
#include "soc/mcpwm_reg.h"
#include "soc/mcpwm_struct.h"
#include "esp_attr.h"
#include "adc/adc_pwm.h"

#define CAP0_INT_EN BIT(27)  //Capture 0 interrupt bit

#define ADC_PWM_PIN    GPIO_NUM_25

//this struct is actually contained in the header file, not the .cpp file...
typedef struct {
    uint32_t period;
    uint32_t duty_cycle;

volatile uint32_t pos_edg_0 = 0;
volatile uint32_t pos_edg_1 = 0;
volatile uint32_t neg_edg_0 = 0;
volatile uint8_t first_meas = 1;

float ticks2us;

//this struct is declared as "extern" on the header file...
volatile ADC_PWM adc_pwm_ticks={0,0};

static void IRAM_ATTR ADC_PWM_ISR_handler(void*) {
    if(mcpwm_capture_signal_get_edge(MCPWM_UNIT_0, MCPWM_SELECT_CAP0) == MCPWM_POS_EDGE) {
        if(first_meas) {
            pos_edg_0 = mcpwm_capture_signal_get_value(MCPWM_UNIT_0, MCPWM_SELECT_CAP0);
        } else {
            pos_edg_1 = mcpwm_capture_signal_get_value(MCPWM_UNIT_0, MCPWM_SELECT_CAP0);
            adc_pwm_ticks.period = pos_edg_1 - pos_edg_0;
            pos_edg_0 = pos_edg_1;
    } else {
            neg_edg_0 = mcpwm_capture_signal_get_value(MCPWM_UNIT_0, MCPWM_SELECT_CAP0);
            adc_pwm_ticks.duty_cycle = neg_edg_0 - pos_edg_0;
    MCPWM0.int_clr.val = CAP0_INT_EN;

void ADC_PWM_Init() {
    ticks2us = 1000000.0 / rtc_clk_apb_freq_get();
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_CAP_0, ADC_PWM_PIN);
    mcpwm_capture_enable(MCPWM_UNIT_0, MCPWM_SELECT_CAP0, MCPWM_BOTH_EDGE, 0);
    MCPWM0.int_ena.val = CAP0_INT_EN;
    mcpwm_isr_register(MCPWM_UNIT_0, ADC_PWM_ISR_handler, NULL, ESP_INTR_FLAG_IRAM, NULL);

What am I missing?
Thanks in advance.