This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28035: Simple loop delay does not match with CPU clock

Part Number: TMS320F28035

Tool/software: TI C/C++ Compiler

Hi,

I want to implement a loop delay using simple delay function like this

void DelayUs(unsigned long usec)
{
usec = usec * (Instruction_Multiplier);  //3 to 4  cycles
while (usec--)  // two cycles
__asm(" NOP"); //one cycles
}

My 28035 clock is 60Mhz and instruction time is 0.016666 micro seconds. So each decrement will take 3 cycles approx. 

Considering clock speed, I should have approx 166 decrements in one microsecond. 

While(usec--);__asm(" NOP") will take 3 cycle for each decrement. So Ideally I should use 166/3 = 55 as Instruction_Multiplier in the code.

But when I tested the code, it was 10 times slower. I had to use 5 as Instruction_Multiplier, then only I was able to match the delay.

Could I be using a slower clock? 

 

1.66667E-08
  • How did you arrive at 3 cycles for the execution time of the loop?  I would expect more like 10-12 cycles for this because the compiler has to decrement and check a counter inside the loop, then branch on the result.  The branch alone will take 4 or 7 cycles, depending on how the compiler implements it.

    There is an assembly delay function for this device in the file "DCP2803x_usDelay.asm" which implements this.  I recommend using that function.

    Regards,

    Richard

    DSP2803x_usDelay.asm