How to calculate time took by the psoc 5 chip for the instruction

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I have been trying to use clock () function to get the time used by code i have wrote. The code is in the main before infinite for loop.

   

eg. 

   

volatile clock_t start1,end1,;

   

volatile float64 c_time;

   

 start1=clock();

   

//then my code comes here

   

end1= clock();

   

 c_time =( float) (end1- start1)/ (float)(CLOCKS_PER_SEC);

   

 

   

when i debug the code and looks in the variables start1 and end1, it displays same value .

   

is there any other way by which I can try to determine the time taken by my code.

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

ammarshamim,

You can yse ARM built-in SysTick counter to measure amount of CPU cycles taken by a function or operation as shown below. You will be limited by 2^24 CPU ticks only (about 0.25sec @24MHz CPU speed), as SysTick counter on Cortex M0 and M3 can not go beyond SYSTICK_MAXVAL:

#define SYSTICK_MAXVAL 0x00FFFFFF //max allowed SysTick counter value for 24bit

uint32 SysCntVal; // The value of SysTick counter you are trying to retrieve

SysTick_Config(SYSTICK_MAXVAL); //reset counter set to max value, 1-time, will not reload

TCPWM_WritePeriod(); //do something..

SysCntVal = SYSTICK_MAXVAL - (SysTick->VAL); //get elapsed ticks (min offset 3 ticks)

sprintf(strMsg1, "%d, %f\r\n", SysCntVal, x); //report result UART_PutString(strMsg1);

/odissey1  

View solution in original post

0 Likes
9 Replies