I developed a time capture application using interrupts.
My code is very close to the mcpwm capture example.
if I delete line #4, tyhe code works fine,...
I call the interrupt on both edges and figure out about the edge type by calling mcpwm_capture_signal_get_edge.
This works fine with ESP-IDF 4.0.
Yesterday I updated to ESP-IDF4.1. Now the ESP32 panics as soon as the interrupt fires. This is caused by calling mcpwm_capture_signal_get_edge(....
Checking the length of mcpwm.c the newer version is about 80 lines shorter.
So I switched back to 4.0...
Problem gone...
To me, this seems like a bug.
Greetings
Georg
Code: Select all
static void IRAM_ATTR isr_handler(void)
{
if (mcpwm_capture_signal_get_edge(MCPWM_UNIT_0, MCPWM_SELECT_CAP0) == 1 ) // raising edge
isr_captured.raising_edge = mcpwm_capture_signal_get_value(MCPWM_UNIT_0, MCPWM_SELECT_CAP0);
else{
isr_falling = mcpwm_capture_signal_get_value(MCPWM_UNIT_0, MCPWM_SELECT_CAP0);
if ( (isr_falling - isr_falling_last) > isr_ticks_debounce){
toggle_22 ^=1;
gpio_set_level(22,toggle_22);
isr_captured.falling_edge = isr_falling;
xQueueSendFromISR(capture_queue, (capture_t *) &isr_captured, NULL);
};
isr_falling_last = isr_falling;
}
MCPWM0.int_clr.val = CAP0_INT_EN;
}
static void capture_config(void *arg){
mcpwm_pin_config_t pin_config = {
.mcpwm_cap0_in_num = GPIO_CAP0_IN
};
mcpwm_set_pin(MCPWM_UNIT_0, &pin_config);
mcpwm_capture_enable(MCPWM_UNIT_0, MCPWM_SELECT_CAP0, (MCPWM_POS_EDGE | MCPWM_NEG_EDGE), 0);
MCPWM0.int_ena.val = CAP0_INT_EN; //Enable interrupt on CAP0 signal
mcpwm_isr_register(MCPWM_UNIT_0, (void*)&isr_handler, NULL, ESP_INTR_FLAG_IRAM, NULL); //Set ISR Handler
vTaskDelete(NULL);
}
I just recompiled an noticed that I forgot to mention 2 modifications I made to
mcpwm.c
mcpwm.h
With these I can trigger both edges and combine them by the OR statement:
mcpwm.h: line 197ff
Code: Select all
typedef enum {
MCPWM_NEG_EDGE = 0x00, /*!<Capture starts from negative edge*/
MCPWM_POS_EDGE = 0x01, /*!<Capture starts from positive edge*/
MCPWM_BOTH_EDGE = 0x02, /*!<Capture both edges*/
} mcpwm_capture_on_edge_t;
Code: Select all
MCPWM[mcpwm_num]->cap_cfg_ch[cap_sig].mode = cap_edge + 1;