[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Strange thing...

From: E . Weddington
Subject: Re: [avr-gcc-list] Strange thing...
Date: Mon, 22 Sep 2003 14:13:30 GMT

> Hi all.
> I'm trying to measure the execution time (in CPU cycles) 
of a simple for
> loop. For my settings refer to the PS section of my e-
mail. Imagine the
> following situ:
> unsigned short value = 62;
> unsigned short i;
> start_timer();
> for (i = 0; i < value; i++) ;
> stop_timer();
> The loop in AVR assembly, is shown below:
> When 'value' equals to 62, I get a time value of 190 
cycles. When I
> set 'value' to 64, the time measured is 16 cycles! What 
am I doing wrong?

You should not implement any timing by an empty for loop. 
If you do an empty for loop, your index variable i should 
be declared as volatile. If you don't declare it as 
volatile and you have optimization turned on, the compiler 
may decide to optimize your "do nothing" loop completely 
away, or it can optimize it however it sees fit which can 
usually seem strange to people and not usually what they 
want. The best way to implement a time out is to use a 
hardware timer.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]