Nanosecond delay on teensy 4.1

Hi,

I am running a teensey 4.1. I have an application where I need to incorporate 10s to 100s nanoseconds delay. The core clock of teensy is 600 MHz so I believe core clock is not limiting me on that. I did not find any simple syntax like with micro or milliseconds on the internet. Could anyone help? Thank you in advance.

I moved your topic to an appropriate forum category @vilius00.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I don't have a teensy, so I can't test it out, but the teensy has a delayNanoseconds( ) function available.

did you check

https://www.pjrc.com/teensy/td_timing_delay.html#delayMicroseconds

delay()

The simplest timing function is delay(). It waits a number of milliseconds.
digitalWrite(11, HIGH); // pin 11 high
delay(1000); // for 1 second
digitalWrite(11, LOW);
For very precise delays, you can use delayMicroseconds(), up to 16383 us. With delay(), you can wait up to 429497295 ms, or about 49.7 days.

While these functions are easy, your program can not do other work during the delay.

delayMicroseconds()

Generally use for short, hardware motivated delays. Especially when using an analog multiplexer, usually a short delay after changing the mux channel so the signal can become stable before reading.
TODO: example with mux to adc

Interrupts can change delay, especially on Teensy 2.0, LC, 3.2, 3.5, 3.6. Teensy 4 boards attempt to check actual time rather than just fixed software delay, so delayMicroseconds() is less sensitive to interrupts on Teensy 4.0, 4.1, MicroMod.

delayNanoseconds()

All Teensy boards support delayNanoseconds(). The actual delay may be longer, especially if running at a slow clock speed or using a non-const number for nanoseconds.

it's using the ARM Cortex-M cycle counter (ARM_DWT_CYCCNT).

there is a pending issue on this function so your mileage may vary...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.