It takes too much time to execute 'for' statement

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

It takes too much time to execute 'for' statement

712 Views
jaehak9708
Contributor II

Hello All;

I use MPC5676R and set core clock 180MHz using FMPLL_init()

But some problems is generated;

1. I think eTPU clock is set rightly. because ETPU interrupt is running as I set.

   but SPI clock is weird. I set the register CPU clock 180MHz, and  eTPU / peripheral / platform clock 90MHz. 

   SPI clock is prescaled from CPU clock as shown in reference manual, I set DBR=0 / PBR = 1 / BR = 2
   it means that 180/3*1/6 = 10MHz 

   but, real SPI clock is 5MHz... Is these right that SPI clock is prescaled from CPU clock? 

2. "for" statement takes too long time.

   If I use just the command asm("nop");, It takes 11ns (It maybe consume 2 clock) 

   but when I call the function which execute the asm('nop'); such as 


   inline void delay(void)

   { asm("nop");}

   then, The execution time is 250ns... I thought that the function call time is 28clock. 

  but. if I use the "for" statement, such as

 

  inline void delay(int n)

   { for (; n-- ; ) asm("nop"); } 

  the execution time is 880ns! If I just entered "1" in the parameter. 

   Does Anyone knows about this phenomenon ?

Labels (1)
0 Kudos
3 Replies

625 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

1) There are two possible operation modes, question is whether you are using the configuration you are supposing.

pastedImage_1.png

Check SIU_SYSDIV register.

2) Loops is not right test code. Better is to use nop repetitions like this

asm("nop");

asm("nop");

asm("nop");

..

and them measure pulse witdth once with NOPs commented out and once with NOPs and subtract the time.

This way you can give valid numbers only in case the code is executed directly from cache. Otherwise it is affected by target memory access path (cache, XBAR, flash prefetch buffers) and optimizing techniques (pipelining, branch prediction and so on).

0 Kudos

625 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Hi, is this question related to SPI function running on eTPU, or DSPI module?

0 Kudos

625 Views
jaehak9708
Contributor II

Hi, The codes are in the eTPU interrupt service routine.

Using eTPU set and ASAC, I generated the eTPU channel 29 interrupt service routine which is called per PWM period. 

void eTPU29_ISR(void)

{

  GPDO[259].R=1;

  delayN(3);

  GPDO[259].R=0;

}

0 Kudos