Page 1 of 1

evaluate the execution time

Posted: Tue Mar 04, 2014 10:58 pm
by yushanh
Hi all,

I wonder if anyone could suggest some methods to evaluate the program execution time? I have a project with an ISR which has some SPI transactions. When I checked my scope it took around half second for an ISR, which takes really long time for the SPI clock rate of 16 MHz... I'm trying to find some ways to debug and narrow down the problem. Is there any way to get the current kernel time stamp for debugging purpose? Or any debugging method is welcomed... Thanks a lot. :D

~S

Re: evaluate the execution time

Posted: Wed Mar 05, 2014 12:42 am
by yushanh
I found some discussions on the forum that SysTick could be used to evaluate time. But in the current kernel, CH_FREQUENCY has been set to 1000, which I assume is 1 ms for each SysTick? How could be measure the time of micro-second level?

Thanks!

~S

Re: evaluate the execution time

Posted: Wed Mar 05, 2014 2:17 am
by jscott
You can use halGetCounterValue()

You can find more information at:

http://chibios.sourceforge.net/html/gro ... a55b7fd74c

-John Scott

Re: evaluate the execution time

Posted: Wed Mar 05, 2014 9:15 am
by Giovanni
Please also enable the state checker in chconf.h, such a long time makes me think you are doing something wrong somewhere.

Giovanni

Re: evaluate the execution time

Posted: Wed Mar 05, 2014 2:39 pm
by Marco
Maybe you should do SPI transactions in a seperate thread instead of in the ISR?

Re: evaluate the execution time

Posted: Wed Mar 05, 2014 8:10 pm
by yushanh
Yes, I woke up the thread for SPI transaction in ISR.

Thanks to jscott for pointing out the halGetCounterValue(). That really helped me to narrow down my problem. The reason was that I had an empty while loop in my main thread, which kept it really really really busy... :roll: After I added a sleep function there, the SPI performance becomes much much much better! Thanks for you guys' help! :)