Part Number: TMS320F28335
Hello,
I am coming up with a DELAY_US() cycle count that is different than what is described in the DSP28x_usDelay() function's source file.
Could someone please verify my analysis shown below.
Stephen
The comments in DSP28x_usDelay function file say the following:
;There is a 9/10 cycle overhead and each loop
;takes five cycles. The LoopCount is given by
;the following formula:
; DELAY_CPU_CYCLES = 9 + 5*LoopCount
; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
; The macro DELAY_US(A) performs this calculation for you
I counted 3 (3 mov instructions) +4 (LCR) + 4 (LRETR) = 11 cycles of overhead (see assembly for main() and DSP28x_usDelay() below) . Is that correct?
Also, if the computed delay loop count passed to DSP28x_usDelay() is n, I found that the the number of loop interations in DSP28x_usDelay() is n+1. Is that correct?
For example, if n=4 (i.e. 0.210us for 150MHz 28335), the total cycle count will be 11+(n+1)*5 = 11+25 = 36 cycles, which is equivalent to 36*6.667ns = 0.240us. Is that correct?
C CODE:
/*
* main.c
*/
#define CPU_RATE 6.667L
extern void DSP28x_usDelay(long int delayTime);
#define COMPUTED_LOOP_COUNT(A) (long int)(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)
#define DELAY_US(A) DSP28x_usDelay((long int)(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L))
volatile long int a = 0;
int main(void)
{
a = COMPUTED_LOOP_COUNT(0.210);
DELAY_US(0.210);
return 0;
}
main() assembly code:
main(): 009101: 0204 MOVB ACC, #4 009102: 761F0300 MOVW DP, #0x300 009104: 1E0A MOVL @0xa, ACC 14 DELAY_US(0.210); 009105: 76400050 LCR $../DSP2833x_usDelay.asm:62:75$ 15 return 0; 009107: 9A00 MOVB AL, #0x0 16 } 009108: 0006 LRETR
DSP28x_usDelay Assembly Code:
62 SUB ACC,#1
$../DSP2833x_usDelay.asm:62:75$(), DSP28x_usDelay:
000050: 1901 SUBB ACC, #1
63 BF _DSP28x_usDelay,GEQ ;; Loop if ACC >= 0
000051: 56C3FFFF BF -1, GEQ
64 LRETR