• Welcome to Andy's Workshop Forums. Please login or sign up.
 
April 28, 2024, 07:12:28 am

News:

SMF - Just Installed!


Interrupt performance

Started by Markus Reinhardt, October 12, 2014, 11:04:26 am

Previous topic - Next topic

Markus Reinhardt

Hi Andy,

I am unclear about the big difference in the reaction time of timer triggered interrupts service routines with GPIO output and simple timer triggered GPIO output.
I have generated two test files timer1_interrupts.cpp for the interrupt based GPIO output and
timer_gpio_out.cpp for the simple timer triggered GPIO output.

I observed the following:
With the interrupts triggered version I can only achieve a period of around 30 microseconds although I increase the frequency of the timer.
With the simple timer triggered version I can achieve a period of 1 microseconds (and maybe even lower).

My suspicion is that it is due to the overhead involved in calling a interrupt service routine, but I have no idea, where to find the code to cross-check that suspicion.
My first question is, if this were true, is there any means to reduce the overhead ?
My second question is, where could I find the code that shows the calling of the interrupt service routine?

I have to use in a further development step the interrupt service routine approach because there shall be further tasks
executed within the routine, but if the overhead is so big, it might not work as planned.

Any help from you very much appreciated.

Best regards,

Markus

Andy Brown

Hi Markus,

Yes there will definitely be a substantial overhead in using an ISR to manually toggle a GPIO output. Even if you stripped it right back to just your code inside the ISR then you're still going to be much slower than having the hardware do it all for you with a timer routed to an output pin. As you raise the frequency of your ISR eventually you starve the main code of cycles to the point where eventually it will not execute at all.

Last week I pushed a change to the master branch on Github that reduces the overhead of the library's ISR processing by a factor of 2 for the common case of just a single subscriber to the ISR so you might like to get the latest code to see if that helps you.

- Andy
It's worse than that, it's physics Jim!

Markus Reinhardt

Hi Andy,

thank you very much for the quick reply.
I will try the updated code.

Best regards,

Markus