To get the algorithm time.

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

To get the algorithm time.

842 Views
vipindas
Contributor I

Hi,

I am using a K60 twr board, and i have a delay function like this.

void delay()

{

  unsigned int i, n;

  for(i=0;i<1000;i++)

  {

      asm("nop");

  }

}

When i checked the number of cpu cycles (using the systick) it takes,it showed around 3000, which is theoretically correct (optimized code for speed, so 1000nop + 1000 add + 1000 cmp)

Since my cpu is 120Mhz, if i set and reset a gpio before and after calling this delay, i expect

theoritically -> 3000 cpu cycles X 0.0083micro seconds = 25 micro seconds

but, practically (by setting and resetting gpio) i am seeing it as  around 143 micro seconds.

Any idea why this difference? I am really running my core @ 125?, or is my calcultion wrong somewhere?

My systick configurtaio

SYST_RVR = 0xFFFFFFFF;

SYST_CSR = 0x7;

int nStart = SYST_CVR;

delay()

int nStop = SYST_CVR;

thanks in advance

0 Kudos
6 Replies

699 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Vipindas,

Thank you very much for your focus on Freescale Kinetis product. I'm glad to provide service for you.

And I'd like to suggest that you should get the corresponding assembly instruction when you debug the set and reset a GPIO with the delay function in IDE.

I think it will give you more detail about the code execute operation.
Have a great day,

Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

699 Views
vipindas
Contributor I

Hi,

pls find the routine attached

c code

while(1) {

toggle led();

delay();

}

Assembly routine

          delay:

1fff02b6:   nop

1fff02b8:   subs r0,r4,#1

1fff02ba:   nop

1fff02bc:   subs r4,r0,#1

1fff02be:   bne delay (0x1fff02b6)      ; 0x1fff02b6

1fff02c0:   b main+0x38 (0x1fff0294)  ; 0x1fff0294

1fff02c2:   nop

          exit:

0 Kudos

699 Views
vipindas
Contributor I

delay routine

void delay()

{

  unsigned int i, n;

  for(i=0;i<1000;i++)

  {

      asm("nop");

  }

}

0 Kudos

699 Views
yasuhikokoumoto
Senior Contributor I

Hello vipindas,

how much time does it take for execution without the delay() function?

Isn't it around 120 micro seconds?

Best regards,

Yasuhiko Koumoto.


0 Kudos

699 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Vipindas,

According your statement, I'd like to confirm one things with you.

Was the 143 ms the period of the pin swing?

Did you ever use the oscilloscope capture the signal?
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

699 Views
vipindas
Contributor I

Yes, i used the oscilloscope to measure the timings and the timings between pin swing is 143 micro seconds (not milli seconds).

0 Kudos