Need Help 100 ns Delays

Hi, I am working on a project and I need to design a circuit which gives digital logic-1 for 100 nanoseconds then it is logic-0 for 10 microseconds. This should be a loop. I wrote a code, but I am not sure it works clearly
here is the code

unsigned long s1time, s2time;
void setup(){
Serial.begin(9600);
pinMode(8,OUTPUT);
}

void loop(){

digitalWrite(8,HIGH);
s1time = micros();
delayMicroseconds(0.1);
digitalWrite(8,LOW);
delayMicroseconds(10);
s2time = micros();
Serial.print("s1time = ");
Serial.println(s1time);
Serial.print("s2time = ");
Serial.println(s2time);
Serial.print("Fark = "); // Fark means difference
Serial.println(s2time - s1time);

}

One of my code's serial monitor result is

s1time = 18204
s2time = 35044
Fark = 16840 // Fark means difference

s1time = 41620
s2time = 58460
Fark = 16840

so does it seem correct?

At 16MHz, 100ns is less than two instruction cycles.

AWOL:
At 16MHz, 100ns is less than two instruction cycles.

so should I change 100 ns to 50 ns or less than 62.5 ns?

delayMicroseconds(0.1);

Have you looked at the reference page? The parameter for delayMicroseconds() is an unsigned int.

http://arduino.cc/en/Reference/DelayMicroseconds

Also:

This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.

An exact 100ns delay is not going to be possible with a regular arduino board. You could get close, but you'd probably have to use some assembly code, not the arduino language.

Here is a pointer to a set of inline functions that can do small delays:
http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_id=665&item_type=project
I'm not sure that the arduino IDE will compile them correctly, you may have to fix up a makefile with the correct compiler options.

Even then, the closest you could get is 2 cycles, which is 125ns.

Not only that, but you realize that digitalWrite() itself takes much more than one cycle to complete. In fact, your code is spending much more time in all the other functions than in the delayMicroseconds function calls. That's why you'd have to use AVR assembly instead.

If you really need 100 nanoseconds exactly, I'd look for some kind of external chip to do it for you.

Serial.print("Fark = "); // Fark means difference

Thanks for clarifying that.

As for the 100nS delay, forget it with an Arduino, just maybe if you clock it at 20MHz and get down and dirty with some assembler, but otherwise no chance.


Rob

thank you very much for your replies.

I will look for some external chips, or I will change the delay time to 1 microseconds if it is possible for my project.

Thanks again. Have a good day...

Don't forget:

This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.

Actually, this just might be possible with the proper settings for PWM. You'd have to mess around with the internal registers to get it to run at the right frequency though.

If you set: digital out pit ------
|
--- C

|
|

< R

|
_ GND
you can get as short pulse as you want, 10 nsec or less.