Hi, can be arduino UNO set with an external crystal or some other circuit so as to be able to sleep 1000ns ?
Here is the trick.
Explain what you want to do.
So far, your question is nonsense. Did you make a mistake when typing it?
If you fully explain what you want to do, you will get a useful answer; otherwise you will most likely get a complete thread of mockery. :astonished:
I want to simulate optic communication, so I send pulse on led every 10ns.
So, you need to send a pulse every 10ns, so that's our period /frequency. How about the duration of the pulse itself ? How long ( or short) does it need to be ?
Do you really need the Arduino to be asleep between each pulses ? Wouldn't it be sufficient to toggle the I/O without going into sleep mode ? What is the requirement or advantage to go in sleep mode ?
10 ns? That's crazy fast.
Not on a traditional arduino. Most Arduino boards run at 16mhz. 16mhz = 16 clock cycles per microsecond, 16 clock cycles per 1000 nanoseconds.
1000/16 = 62.5ns.
That's the fastest that the arduino can do anything - and presumably you want it to actually think about the pattern of pulses, which means it needs time to do that as well.
The traditional arduinos are far too slow for this, and I don't think even the Due/Zero are fast enough to make controlled ~10ns pulses... Maybe if you don't need to do anything other than output constant pulses?
Sleep is out of the question - it takes a bunch of clock cycles to enter and leave sleep.
I badly expressed. I do not need sleep Arduino, I just need to call the delay () with very little value.
I'm sorry my fault.
DrAzzy: 16mhz = 16 clock cycles per microsecond
I need 1000ns(1us), NO 10ns. SORRY :)
And if I use some external crystal ?
Oh! 1us! Easy!
delayMicroseconds(1) will give you a ~1 us delay
I don't think you can use delayMicroseconds(1); reliably: https://www.arduino.cc/en/Reference/DelayMicroseconds Caveats and Known Issues This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.
Got an oscilloscope? Try it.
It looks like it'd be a little more than 1us, if you called it with 1, if the comments in the code are to be trusted. (I get 1.25 us - 20 clock cycles).
You will definitely need to use direct port manipulation though, since digitalWrite() takes like 50-some clock cycles to run. https://www.arduino.cc/en/Reference/PortManipulation
You could take over a timer to get more precise timing.
Look at it and let you know.
joci: I need 1000ns(1us), NO 10ns. SORRY :)
As I thought.
Now we're talking. :grinning:
CrossRoads: I don't think you can use delayMicroseconds(1); reliably: https://www.arduino.cc/en/Reference/DelayMicroseconds Caveats and Known Issues This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.
Got an oscilloscope? Try it.
Yes, I'm recommending to use avrlib's delay_us() instead. This function provides accurate delay.
But you have to take into account the time involved in the code itself, including the test to break out of the loop.