Need 40 ns delay max with Arduino IDE

I am trying to use the Arduino IDE to program timings for a component, but the component requires a delay of 40 ns Max for a timing. Is there anyways i can generate this delay with a library, or is there already one in the preinstalled libraries?

TL;DR , I need to make 40 ns delay

Datasheet:
https://cdn-shop.adafruit.com/datasheets/SSD1305.pdf ,page 61

Board: Adafruit Metro

I think you need to re-phrase your query. The IDE is simply a shell that gives the programmer a fancy view plus a few programmer tools but when you press verify or upload the CLI command does the actual work.

that's the Rise Time and Fall Time when you toggle a pin, you don't control those, it's a characteristic of your MCU (and depending on pull ups, capacitance attached at the pin)

2 Likes

fixed the query (I hope)

Ok, thanks :slight_smile:

The clock speed is 16mhz, which has a minimum delay of 62.5 ns (i think?), is this still suitable for the component, and if so, how do i generate this delay?

you should be fine, a 328P at 16Mhz should meet this.

after checking, the NOP instruction should allow me to generate the right delay, so thanks for your help :smiley:

a NOP takes 62.5 ns on your Adafruit Metro (runs the ATmega328P at 16MHz)

I'm not sure which delay you are talking about.

1 Like

The Rise time and Fall time are both below the minimum delay time, but based on one of your earlier replies i assumed that it would be fine, or am i confused?

A delay routine in assembly... at 8m30s

yes unless you have something weird connected to those pins, the time taken to change the voltage of an OUTPUT pin should be below 40ns.

what do you need NOP for?

i was going to use NOP for delay, but after just checking, NOP is for assembly, not C++.

is there a way i can do something similar with C++, or do i have to use assembly in this circumstance.

C++ supports assembly code.

you could have a function like this

void inline nop() {
  asm volatile("nop");
}

and you would call it when needed

  nop(); // Call the nop function
1 Like

thanks

This one is a bit more reliable.

....    inline __attribute__((always_inline))   ....

Just in case.
Spent many days debugging a PPC code where GCC ignored "inline" for a function :-/

Yes, this is how everyone do very short delays: using NOP's. Either single nop or
a sequence of them.

Your topic does not indicate a problem with the IDE and therefore has been moved to a more suitable location on the forum.

Indeed !

As @J-M-L already pointed out in #3, you missinterpret the datasheet. There is no need to create a delay of 40ns. Rise- and fall times cannot be influenced by software. That's HW specific. If they are too slow, a delay will not help. But the risetime of a 386P output should definitely be less than 40ns.

3 Likes
System Clock Frequency : 16 000 0000 Hz
==> Period of i Cycle = 1/16 000 0000 = 0.0000000625 s = 62.5 ns

Use TC1 of UNO as Counter1 to count 1 CPU cycle.
Hints:

TCCR1A = 0x00;
TCCR1B = 0x00;
TCNT1 = 65535;  // fullCount = presetCount + actualCount
Start TC1 with prescaler 1.
Check when the TOV1 assumes HIGH state indicating the elapse of 62.5 ns time.
Use Oscilloscope to view the output.