delay need more fast

DELAY only minimum 1mSec, like delay(1);
however need more fast around 1uSec what command?

Hmmm well there is this but note the caveat for very short delays.

So I might also have a look at _delay_us.

nop?

I'm assuming you are using an AVR processor?
If so, in order to do that you will have to step outside the Arduino core code and
use the low level capabilities that are provided in the AVR libC library and/or avr-gcc.

Here is a link to the documentation for the AVR libC delay routines:
http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

However, the avr-gcc that ships with the IDE is VERY old so it is much older than
that documentation. The version of the delay routines that come with the IDE has horrible accuracy
and does not support the ROUND options.
Therefore, I would not recommend using the <util/delay.> delay routines,
unless you have updated your avr-gcc to a newer version.

I would either use the code from the delay_x project:
http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_id=665&item_type=project

OR

Roll you own using the built in avr-gcc function:
__builtin_avr_delay_cycles(ticks);
Which is available in the avr-gcc that ships with the IDE.
The argument is the number of clock ticks to delay.

i.e. do something like this:

#define _delayNanoseconds(__ns)     __builtin_avr_delay_cycles( (double)(F_CPU)*((double)__ns)/1.0e9 + 0.5 )

Then pass in the number the nano seconds you want.
i.e.

_delayNanoseconds(450);

Gives you a delay that is at least 450ns but is rounded up to the nearest F_CPU clock tick.
If you want to round down, simply remove the +0.5 in the calculation.
But normally, with very short delays like this, you need a delay that is not shorter than requested.

--- bill

aarondc:
nop?

As discussed / exampled here: http://forum.arduino.cc/index.php/topic,40916.0.html

aarondc:

aarondc:
nop?

As discussed / exampled here: http://forum.arduino.cc/index.php/topic,40916.0.html

I think using __builtin_avr_delay_cycles(ticks) is better since it will generate other instructions and even loops
to create the desired number of clock cycle delays so the code will be smaller than a string of inline NOPs.
My preference is to wrap it with a function-like macro as above so that uses actual time like nanoseconds
rather than cpu ticks.
That way it self adjusts for any CPU clock speed, which is particularly convenient when using the
IDE since the IDE automatically sets F_CPU.

--- bill

This __builtin_avr_delay_cycles(ticks) interests me. I would like to use it, but I can't get it to compile correctly. I can see the declaration in builtins.h, and I can see that it is used in delay.c, but I can't get it to link. Could you point me to somewhere that explains how I could actually use it? I'm using Arduino IDE 1.0.5.

Right yeah I got it, thanks.

delayMicroseconds();

I make a code for transmitter remote which use Indoor power sockets/switches Wireless Remote Control, I recorded the control signals by computer while all I have to do is to start recording, and press each of the buttons on the remote control, then I had zoom in and analyze the signals I picked sequence bits, I figured out that a long on/off and short on/off in times. I got 25-bit like 0111010011100011010111100, I tested with Arduino connect the transmitter module 433Mhz its works send to power sockets/switches turn on and off done! because need use Microseconds like delayMicroseconds(960); long on/off, and delayMicroseconds(300); short on/off. But my code is long list, somehow simple small code addresses 25-bit like 01110100 11100011 01011110 0 show example;

//-------------------------------  1
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(311);          
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);           
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);         
 
   digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);             
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);   
   //-------------------------------  2
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);           
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);             
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);        
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);             
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);        
 
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);           
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);       
   //-------------------------------  3
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);         
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);        
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);        
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);        
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);        
 
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);       
   //-------------------------------  4
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);        
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);        
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);       
 
   digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301); 
   //-------------------------------  5
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);        
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);        
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);       
 
   digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);        
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301); 
   //-------------------------------  6 
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);        
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);        
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);       
  
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(957);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(301);       
 
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);       
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(957);        
    //-------------------------------  7
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(301);      
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(9662);

I will search how make a short code addresses/bits, because I'm a new Arduino after I had experience with Picaxe, but I glad I'm done with this, its works well.

you can wrap the repeating parts in functions.. and call the functions ..

void h()
{
  digitalWrite(outPin, HIGH);    
  delayMicroseconds(957);           
  digitalWrite(outPin, LOW);
  delayMicroseconds(301);
}

void l()
{
  digitalWrite(outPin, HIGH);    
  delayMicroseconds(301);           
  digitalWrite(outPin, LOW);
  delayMicroseconds(957);
}

TanHadron:
This __builtin_avr_delay_cycles(ticks) interests me. I would like to use it, but I can't get it to compile correctly. I can see the declaration in builtins.h, and I can see that it is used in delay.c, but I can't get it to link. Could you point me to somewhere that explains how I could actually use it? I'm using Arduino IDE 1.0.5.

Well, darn. It is a bit complicated depending on which OS you use and
by what the Arduino team has done in recent Arduino IDE releases.
First, here is an example sketch of how to use it:

extern void __builtin_avr_delay_cycles(unsigned long);
void setup()
{
	Serial.begin(9600);
}

void loop()
{
        __builtin_avr_delay_cycles(F_CPU); // delay 1 second
	Serial.println("Loop");
}

The problem is that the Arduino team is still using avr-gcc 4.3.2 from back in 2008 for their tools
and that version does not support this.
The windows IDE shipped with the compiler but the linux IDE didn't ship with compiler tools
until 1.0.1
So on Linux you got a more recent compiler with Arduino until the 1.0.1 IDE which
"downgraded" your compiler tools by shipping its own and using it instead of the one
installed on the OS.
At least you can go down in the Arduino install directory and rename or remove a directory
and get the IDE to use the linux OS version of the tools instead. (I do this on each release now)

On Windows it is kind of the same in that you can rename the directory under the IDE install
to be able to use a WinAVR toolset instead of the tools supplied with the IDE.

So unfortunately, the way the IDE ships now on Windows and Linux, you get a very old
set of compiler tools that don't support the builtin delay cycles function, even
if you have more recent tools installed on your OS.
It is possible to get and use newer avr-gcc tools, but you first have to install a newer set of tools
on your OS and then patch your IDE installation (just rename or remove a directory)
so the IDE won't see the compiler tools that it supplied, and will instead use the compiler tools installed on the OS.

It would be nice if the Arduino team would move on and start using a compiler
that is more recent than 2008.

-- bill

bperrybap:
The problem is that the Arduino team is still using avr-gcc 4.3.2 from back in 2008 for their tools and that version does not support this.

It does.

In addition, the prototype is not necessary.

"It does" as in "use an old version"?
or
"It does" in that "it is old and doesn't support it"?

With Arduino 1.0.5
What I see is that avr-gcc 4.3.2 which ships with the Linux IDE doesn't support it.
avr-gcc 4.5.3 which comes in the linux Mint repository does support it.

-- bill

Getting close, I think.

It is possible to get and use newer avr-gcc tools, but you first have to install a newer set of tools
on your OS and then patch your IDE installation (just rename or remove a directory)

I did a sudo apt-get avr-gcc and it installed version 4.5.3. I went in and renamed the hardware/tools/avr/bin directory, and it may have been the right one, because my IDE is now using avr-g++ instead of /home/tanhadron/Programs/arduino-1.0.5/hardware/tools/avr/bin/avr-g++ like it was before. However, now it is giving me another problem.

In file included from sketch_aug22a.ino:1:0:
/home/tanhadron/Programs/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:4:20: fatal error: stdlib.h: No such file or directory
compilation terminated.

Did I rename the wrong directory, or is this a different problem?

On my installation IDE 1.04 I can see the version is avr-gcc-4.3.2 and is dated 04-12-2008
I use Windows Vista.

The sketch compiles and run without problems

void setup()
{
  pinMode(12,OUTPUT);
}

void loop()
{
  __builtin_avr_delay_cycles(8000); // delay
  PORTB ^=0x10;
}

TanHadron:
Did I rename the wrong directory, or is this a different problem?

I rename/remove the directory:
{installdir}/hardware/tools/avr

--- bill

Note: I have all these packages installed:
binutils-avr
avr-libc
avrdude
gcc-avr

Ah. It was avr-libc that I needed. Thank you.

Erni:
On my installation IDE 1.04 I can see the version is avr-gcc-4.3.2 and is dated 04-12-2008
I use Windows Vista.

The sketch compiles and run without problems

Interesting.
With the Linux IDE it doesn't compile using the tools that come with IDE 1.0.4 or 1.0.5
Well it will compile if you add the external declaration/prototype but
then fails the link.

If you upgrade the compiler tools from 4.3.2 to 4.5.3 it works and you don't
need the external declaration.

Here is the version information from the 4.3.2 that comes with Windows 1.0.5

gcc (WinAVR 20081205) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And here is the version information from the 4.3.2 that comes with Linux 1.0.5

avr-gcc (GCC) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clearly these to "4.3.2" versions are not the same.

For example, the windows version has a builtins.h down in
hardware/tools/avr/avr/include/avr
while the linux version does not have it down in
hardware/tools/avr/lib/avr/include/avr

It looks like the version of the avr-gcc tools shipped with the Windows IDE has been patched up so some
intermediate level beyond 4.3.2 while the version shipped with Linux IDE has not.

Spooky/Scary and VERY irritating especially now that the linux IDE
ships an avr-gcc toolset with the IDE. You now get an inferior version of the
compiler tools with the linux IDE that overrides your more recent/better
avr-gcc compiler tools unless you go give the linux IDE a lobotomy so it forgets
about the avr-gcc tools that shipped with the IDE.

--- bill

robtillaart:
you can wrap the repeating parts in functions.. and call the functions ..

void h()

{
  digitalWrite(outPin, HIGH);   
  delayMicroseconds(957);           
  digitalWrite(outPin, LOW);
  delayMicroseconds(301);
}

void l()
{
  digitalWrite(outPin, HIGH);   
  delayMicroseconds(301);           
  digitalWrite(outPin, LOW);
  delayMicroseconds(957);
}

Yeah, never think can use more void each, also another code I recorded the signal, its four voids each, thankyou very much 8)