Systick timer to calculate the time of Instruction run time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Systick timer to calculate the time of Instruction run time

1,967 Views
S_Rai
Contributor I

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

 

0 Kudos
7 Replies

1,951 Views
jeremyzhou
NXP Employee
NXP Employee

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.
-------------------------------------------------------------------------------

0 Kudos

1,908 Views
mjbcswitzerland
Specialist V

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

1,965 Views
prabhat_
Contributor III

 

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.

0 Kudos

1,958 Views
S_Rai
Contributor I
Hi prabha,
Thank you for the reply.
But what if the counter value overflows.how will we come to know ?

Sanath
0 Kudos

1,946 Views
prabhat_
Contributor III

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.

0 Kudos

1,934 Views
S_Rai
Contributor I

 

Thank you Prabhat,

Will look into it,

 

Sanath

0 Kudos

1,914 Views
prabhat_
Contributor III

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. 

0 Kudos