Page 1 of 1

Interrupt low Latency - again

Posted: Thu Nov 15, 2018 7:27 pm
by bmakovecki
How can I minimize latency and execution time for interrupt ?

I register interrupt as:

Code: Select all

mcpwm_isr_register(MCPWM_UNIT_0, isr_handler, NULL, ESP_INTR_FLAG_IRAM, NULL);
in interrupt I have simple float operation as :

Code: Select all


void IRAM_ATTR isr_handler(void *ctrl)
{

uint32_t mcpwm_intr_status = MCPWM[MCPWM_UNIT_0]->int_st.val; //Read interrupt status
MCPWM[MCPWM_UNIT_0]->int_clr.val = mcpwm_intr_status;

uint32_t cp_state = xthal_get_cpenable();

if (cp_state)
{
// Save FPU registers
xthal_save_cp0(cp0_regs);
}
else
{
// enable FPU
xthal_set_cpenable(1);
}

angle += step; // ***** simple float operation
// set duty for all 6 switches as MCPWM[MCPWM_UNIT_0]->channel[MCPWM_TIMER_0].cmpr_value[MCPWM_OPR_A].cmpr_val = lookup(angle);

if (cp_state)
{
// Restore FPU registers
xthal_restore_cp0(cp0_regs);
}
else
{
// turn it back off
xthal_set_cpenable(0);
}
}
Suggestions are welcomed, I hope I don't have to learn low level assembly language and CPU architecture for this.

Regards, Boris

Re: Interrupt low Latency - again

Posted: Fri Nov 16, 2018 4:02 am
by ESP_Sprite
An obvious solution would be to not calculate as a float, so you don't have to mess around with floats. Instead, store it as a fixed-point number. I'm also not sure what your lookup() function does, but if it uses floating point numbers, you may also be able to get away with smallifying it by making it integer-only.

Re: Interrupt low Latency - again

Posted: Fri Nov 16, 2018 8:59 pm
by bmakovecki
Thanks for pointing me to fixed-point number. I think i can reduce interrupt execution time with your solution.
How about latency?
Can I make interrupt to trigger more precisely (cca 1us delay would be fantastic)?
Regards, Boris

Re: Interrupt low Latency - again

Posted: Sun Nov 18, 2018 3:11 am
by ESP_Sprite
Unfortunately, that is harder as the Xtensa needs a fair bit of code to get from an interrupt vector back into an environment that is usable for C... what kind of latency are you getting now?

Re: Interrupt low Latency - again

Posted: Sun Nov 18, 2018 3:32 pm
by bmakovecki
This is what I see on osciloscope:
latency.png
latency.png (11.48 KiB) Viewed 5306 times