MCPWM set compare value under ISR context

panovich
Posts: 2
Joined: Tue Dec 17, 2024 5:41 pm

MCPWM set compare value under ISR context

Postby panovich » Tue Dec 17, 2024 5:49 pm

Hello everyone. I am trying to adjust duty cycle in timer capture ISR context on esp32-s3

Code: Select all

static bool IRAM_ATTR CaptureInterrupt(mcpwm_cap_channel_handle_t cap_channel, const mcpwm_capture_event_data_t *event_data, void *user_ctx) {
    //UNUSED(cap_channel);
    //UNUSED(user_ctx);


    ACFreq = event_data->cap_value - last_cap_value;
    last_cap_value = event_data->cap_value;

    uint32_t newPeriod = ACFreq / 80;
    uint32_t newPosition = get_var_slider_value() / 100.f * newPeriod;
    //printf("%x %x \n", (unsigned int)timer, (unsigned int)comparator);

    mcpwm_timer_set_period(timer, newPeriod); //
    mcpwm_comparator_set_compare_value(comparator, newPosition);

    return false;
}
when i use mcpwm_comparator_set_compare_value inside ISR it start rebooting with

Code: Select all

Core  0 register dump:
PC      : 0x403770be  PS      : 0x00060033  A0      : 0x80379768  A1      : 0x3fc96a10
--- 0x403770be: CaptureInterrupt at C:/Users/User/Documents/Firmware/lcd/main/lcd_main.c:338 (discriminator 1)

A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000000
A6      : 0x08000000  A7      : 0x00000895  A8      : 0x803770bb  A9      : 0x3fc96ab0
A10     : 0x00000032  A11     : 0x42c80000  A12     : 0x3fcae030  A13     : 0x3fcadf90
A14     : 0x3fc997e8  A15     : 0x00000000  SAR     : 0x00000020  EXCCAUSE: 0x00000004
EXCVADDR: 0x00000000  LBEG    : 0x400570e8  LEND    : 0x400570f3  LCOUNT  : 0x00000000
--- 0x400570e8: memset in ROM
0x400570f3: memset in ROM
timer and comparator is global variables, it initialized in main and i do mcpwm_capture_channel_enable only after everything is initialized.
i also set CONFIG_MCPWM_ISR_IRAM_SAFE and CONFIG_MCPWM_CTRL_FUNC_IN_IRAM, still nothing

MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: MCPWM set compare value under ISR context

Postby MicroController » Fri Dec 20, 2024 11:45 pm

A bit more of the actual error log would be helpful.

Note that you should try and avoid floating point operations in an ISR. If you must use floating point in an ISR, you need to enable support for FPU in ISR via menuconfig.

Who is online

Users browsing this forum: Applebot, Qwantbot and 8 guests