Hello,
I am working on MIMXRT1176 controller.
1.I need to find the execution time of my code Instruction.
i am using systick timer in the following sequence
SysTick->VAL = 0UL; //clear current timer value
SysTick->LOAD = 0x00FFFFFF;
cal_systick_read_overhead();
cnt_start_value = SysTick->VAL;
/****code-function*/
cnt_end_value = SysTick->VAL;
execution_cycle = cnt_start_value - cnt_end_value - overhead;
SysTick->VAL = 0UL;
but the problem is if the counter value is overflowed i am getting the wrong value in calculation.
how to find the number of reload times of the systick timer.
2.Which is the best way to find the execution time of an function or an instruction?
Regards,
Sanath
Hi @S_Rai ,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
To provide the fastest possible support, I'd highly recommend you refer to the post。
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi
It is unusual to use the SYSTICK for instruction timing measurement since the M7 has a dedicated instruction counter to do this easier and more accurately.
It is used like this:
// One time initialisation
//
DEMCR |= DEMCR_TRCENA; // enable trace for DWT features
DWT_LAR = DWT_LAR_UNLOCK; // unlock access to DWT registers
unsigned long ulTimeStamp1 = DWT_CYCCNT; // time stamp before starting the function to be measured
unsigned long ulTimeStamp2;
...
...
...
ulTimeStamp2 = DWT_CYCCNT; // time after the function has executed
// Calculate the the result in us
//
ulTimeStamp = ((DWT_CYCCNT - ulTimeStamp) / (SYSTEM_CLOCK / 1000000)); // calculate the time the calculation took
Regards
Mark
Hello Sanath, I had a similar requirement aswell. I tried the following method and it worked I suggest you to try it out.
{
pSystickStruct->RVR = 0xFFFFFFFF;
pSystickStruct->CSRr = 0x7;/* The below block of code for the starting point */
UINT32 u32SysStart = pSystickStruct->CVR;/* put this part after at the end point */
UINT32 u32SysStop = pSystickStruct->CVR;
volatile UINT32 u32Differnce = u32SysStart - u32SysStop;
}
The above block of code worked in my system which runs on a cortex M7, hopefully it works out for you too.
By using programming fundamentals you can create a variable for keeping tab of your counter variable and it can generate a flag incase the value overflows, however I don't have much experience about that scenario as I was using an unsigned 32 bit variable and the length of the code for which I was measuring was also not long, so didn't face that issue. And just for the sake of my name, it's prabhat :') hope you don't mind.
Hello Sanath, I got an update on my solution, I missed to provide that which Systick structure has to be accessed for doing the timestamp calculations. The pointer to the struct that I am using in my solution .i.e. pSystickStruct is actually a pointer to the the S32_SysTick_Type. In my case the S32 means the processor which uses cortex M7 and it works just fine. Thankyou.