[Top][All Lists]

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

[avr-gcc-list] WG: What's wrong with this preprocessor statement

From: Nicolas Nickisch
Subject: [avr-gcc-list] WG: What's wrong with this preprocessor statement
Date: Sun, 25 Feb 2001 14:40:24 +0100

Hi, I am trying to implement a delay-loop with the following

#define delay2(microseconds) { unsigned long x; x=((( (unsigned long)

in the main-program the loop is called by delay2(200)

As you can see the x-varaibale is loaded with as a counter for the
while-loop, calculated according to the MC-Frequency.

In the version stated above something is wirng. The compiler gives no
complains but in the AVR-Studio the 'delay2' is ignored. The program just
jumps to the next statement.

#define delay2(microseconds) { unsigned int x; x=(((

This version works but is limited to a delay of about 230µs (greater values
for microseconds lead to an integer overflow error - the program has an dead
end then)
It seems to be a question of long-values to get this running.
Can you help me ?

I tried to develop this as a better version of the following code:

#define delay_mcs(x)    delay((((x*F_CPU)/6000000)))
#define delay_ms(x)     delay((((x*F_CPU)/6000)))
#define delay_s(x)      delay((((x*F_CPU)/6)))

extern void delay(long);


void delay(long microseconds)
// minimale Verzögerung: 5 µs!
        while(microseconds--) {};

Any ideas ?

Dr. med. Nicolas Nickisch
Thomaestr. 6
65193 Wiesbaden


reply via email to

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