I am trying to generate a 20ns pulse using Arduino Due. But just by using this simple code I see that it generates a pulse of around 2.5us which can be seen from the image attached. Is it actually possible to generate such a pulse with Arduino Due?
void setup() {
pinMode (26, OUTPUT);
}
void loop() {
digitalWrite (26, HIGH);
digitalWrite (26, LOW);
}
(MOD EDIT)
System clock is 62.5nS, so 20nS in code is not possible.
You can get pretty quick with this:
void loop(){
while (1){
PIND = 0b00000100; // toggle whatever number Port D, pin 2 is by writing to the input port.
}
}
Select the port & pin to whatever you need, declare it as an output in setup().
DigitalWrite is very slow, and loop() adds time as well.
while() bypasses the loop() processing, and direct port manipulation only takes 1 clock cycle.
The default arduino DUE clock frequency is 84 MHz ---> A clock cycle = 11.9 ns.
You can't use digitalWrite() arduino function to get something close to 20 ns.
A 50 MHz frequency would produce 20 ns pulses every 40 ns. What precision are you looking for around 20 ns ?