Counting time intervals using for loop!
2006-04-27 by ghetto_shinobi
Hi!!
I wanted to replace my current timer function with simple "for' loop
to measure time interval.So i added in my code function
void delay (volatile unsigned int j )
{
for (;j ;--j);
}
To obtain how much time it takes to do single loop in debbuger i tried
to count cycles in disassembly window.
After that i turned on exectution time profiling in uvision3 to
compare my otcome but my result was differ from keils.
Here are result for j=2 taken from uvision3:
0.033us void delay (volatile unsigned int j )
{
0.150us for (;j ;--j);
0.067us }
According to this first rotate takes 0.1us and each another
0.050us(which gives only 3 cycles Im running lpc2148 with 60MHz).
But in disassembly window i got:
4: for (;j ;--j);
5:
0.050us 0x00000366 E002 B 0x0000036E
0.100us 0x00000368 9800 LDR R0,[SP,#0x0000]
0.033us 0x0000036A 3801 SUB R0,#0x01
0.067us 0x0000036C 9000 STR R0,[SP,#0x0000]
0.150us 0x0000036E 9800 LDR R0,[SP,#0x0000]
0.050us 0x00000370 2800 CMP R0,#0x00
0.117us 0x00000372 D1F9 BNE 0x00000368
6: }
Did i miss something and which result should i trust?
Regards!!