🌐
ESP32 Forum
esp32.com › viewtopic.php
Nanosecond delay - ESP32 Forum
April 12, 2024 - // the clock is set to 125 MHz => 1 tick == 8 ns // init SysTick timer systick_hw->csr = 0x05; // enable systick at 1 cycle resolution (8ns) systick_hw->rvr = 0xffff; // 16 bit // delay 13 ticks or 102 nanoseconds uint16_t ticks = 13; // 13*8 = 102 nanos uint16_t start = systick_hw->cvr; ...
🌐
Reddit
reddit.com › r/arduino › sub microsecond delays on esp32
r/arduino on Reddit: Sub microsecond delays on esp32
December 18, 2021 -

Do I have to write instructions in assembly? Im using Arduino IDE and im trying to sample a signal at 44.1khz. I come from a PIC Micro background where I would just use a TMR. Whats the play here in Arduino Land?

Fractional Microsecond Delay; Oct 5, 2021
r/esp8266
4y ago
Precise nanosecond Delays in C for AVR/Arduino Dec 27, 2017
r/c_language
8y ago
ESP32 Timer Interrupt Mar 17, 2025
r/esp32
last yr.
ESP 32 Interrupt handling Jul 24, 2023
r/arduino
2y ago
More results from reddit.com
People also ask

Why does delayMicroseconds(1) not actually delay 1 µs?
At 1–2 µs, the function's own setup overhead is larger than the requested delay. The minimum reliable delay is around 3 µs. Use direct port manipulation and NOP instructions for sub-3-µs timing if needed.
🌐
controllerstech.com
controllerstech.com › home › arduino › core tutorials › delaymicroseconds() tutorial
Arduino delayMicroseconds() Tutorial: Precise Timing, Pulses & ...
What is the difference between delay() and delayMicroseconds()?
delay() takes milliseconds. delayMicroseconds() takes microseconds. 1 ms = 1,000 µs. Use delayMicroseconds() when you need pauses shorter than 1 ms.
🌐
controllerstech.com
controllerstech.com › home › arduino › core tutorials › delaymicroseconds() tutorial
Arduino delayMicroseconds() Tutorial: Precise Timing, Pulses & ...
Can I use delayMicroseconds() inside an interrupt service routine (ISR)?
Technically yes, but it is bad practice. ISRs should be as short as possible. Blocking inside an ISR prevents other interrupts from firing on time. Use it only if the delay is very short (a few µs) and absolutely necessary.
🌐
controllerstech.com
controllerstech.com › home › arduino › core tutorials › delaymicroseconds() tutorial
Arduino delayMicroseconds() Tutorial: Precise Timing, Pulses & ...
🌐
Reddit
reddit.com › r/esp32 › need to have sub microsecond delay precision
r/esp32 on Reddit: Need to have sub microsecond delay precision
July 29, 2020 -

Hi guys,

I'm trying to implement something that will generate two triggers at regular intervals where the two triggers are separated by a configurable delay. The delay has to be configurable to sub microsecond resolution. Ideally, 500ns or less.

I chose the ESP32 because of its 240MHz clock, but it still seems to be having trouble.

I'm messing around with the following code:

#define cyclespermicro 240
#define microcycles(n) (n*cyclespermicro)

uint32_t startCounter, counter, cpu_cycles;
int cyclediff, totalcycles, corrected;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  startCounter = ESP.getCycleCount();
  totalcycles = startCounter + microcycles(2);
  //delayMicroseconds(1);

 while (ESP.getCycleCount() < totalcycles) {
        __asm__ __volatile__ ("nop");
 }
  
  counter = ESP.getCycleCount();
  cpu_cycles = counter - startCounter;
  corrected = cpu_cycles - 262;
  Serial.print("StartCounter: ");
  Serial.print(startCounter);
  Serial.print(" counter: ");
  Serial.print(counter);
  Serial.print(" cpu_cycles: ");
  Serial.print(cpu_cycles);
  Serial.print(" corrected: ");
  Serial.println(corrected);
}

void loop() {

}

The problem is that I get the same number of clock cycles for 1 us as I do for 2 us. I'm guessing this is because the while loop overhead is overwhelming the 1 us delay.

The problem is I need to have the amount of delay configurable and I don't know the best way to do this. Anyone have any ideas how to efficiently create configurable sub-microsecond delays?

EDIT: I am also noticing, when I get rid of the while loop entirely, and just straight up copy in NOP lines, it works as expected for like 3 NOPs, but once I hit 5 NOPS, the overhead jumps to like 500 cycles. What is going on here?

🌐
ControllersTech®
controllerstech.com › home › arduino › core tutorials › delaymicroseconds() tutorial
Arduino delayMicroseconds() Tutorial: Precise Timing, Pulses & Alternatives
May 29, 2026 - No interrupts are serviced (unless they were already pending). The processor is occupied for the full duration. On a 16 MHz Arduino (UNO, Nano, Mega), one clock cycle is 62.5 nanoseconds.
🌐
Mechatronics LAB
mechatronicslab.net › home › lessons › protected: esp32 arduino programming handbook › chapter 12: timers, delays & interrupts › delaymicroseconds() function for esp32 arduino programming
delayMicroseconds() Function for ESP32 Arduino Programming - Mechatronics LAB
int trigPin = 5; int echoPin = ... Serial Monitor to see distance values printed every second. What You’ll See (Output) The ESP32 will send a 10-microsecond pulse and measure how long the echo takes to return....
🌐
ESP32 Forum
esp32.com › viewtopic.php
Wait microsecond - ESP32 Forum
The RTOS tick period is (by default) 1ms, so vTaskDelay() will round this down to 0 ticks, and you'll either get no delay or a full time slice (1ms) delay while another task runs. It's not advisable to make the tick period any shorter than 1ms. The ROM function ets_delay_us() (defined in ...
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 282
micros() & delayMicroseconds() not good enough · Issue #282 · espressif/arduino-esp32
March 23, 2017 - void IRAM_ATTR delayMicroseconds(uint32_t us) { if(us){ uint32_t m = micros(); while( (micros() - m ) < us ){ NOP(); } } }
Author   espressif
🌐
Arduino Forum
forum.arduino.cc › other hardware › leds and multiplexing
Blink with nanosecond resolution delay - LEDs and Multiplexing - Arduino Forum
October 29, 2020 - Using "delayMicroseconds()", that delay can be specified with microsecond resolution. I did need a multiple MHz blink, and thus a nanosecond delay between state changes (for utilization ...
Find elsewhere
🌐
ESP32 Forum
esp32.com › viewtopic.php
Microsecond or fraction of microsecond delay - ESP32 Forum
March 11, 2018 - function delay(period) { start = CCOUNT; while (CCOUNT - start < period) { // do nothing } }[ This would busy wait (waste) the cycles, but it should work. You might also have to disable some of the interrupts if you need absolutely delays no matter what.
🌐
PlatformIO Community
community.platformio.org › platformio core
How to delay microseconds on ESP32 under a Free RTOS task - PlatformIO Core - PlatformIO Community
September 8, 2022 - I have some code running as a FreeRTOS task on my ESP32. I would like to toggle an output pin in the order of microseconds so use the function delayMicroseconds. However, this crashes my ESP32 every time. Even a simple loop causes it to crash: for ( int i = 0 ; i
🌐
ESP32 Forum
esp32.com › viewtopic.php
esp32 get time with nanoseconds precision - ESP32 Forum
Hi, I am looking for a way to get the time since boot with nanoseconds precision. Currently, the best I can do is esp_timer_get_time() which returns time with microsecond precision. I connected my board to an oscilloscope and found out that it takes around 1.29 us for the esp_timer_get_time() function to return time.
🌐
Arduino Forum
forum.arduino.cc › other hardware › home automation
Is it possible to use ESP32 delayMicroseconds() while connected to Wifi? - Home Automation - Arduino Forum
April 25, 2020 - Hi ladies and gentleman, Because of the outbreak I am stuck out of my home country and have to work online. I sadly dont have an ESP32 with me at the moment, so I cant check it myself. My question is wether or not it is possible to use delayMicroseconds() on the ESP32 while sustaining an ...
🌐
DeepBlue
deepbluembedded.com › home › blog › arduino delay() function tutorial
Arduino delay() Function Tutorial
July 26, 2025 - The lowest we can get is 1 CPU Cycle which turns out to be 62.5 nanoseconds. If it’s mandatory for your project to generate a very precise time delay or measure an incoming pule (or event) at this level of resolution, you should consider finding ...
🌐
Instructables
instructables.com › circuits › arduino
6.25 Nanosecond Resolution Timer for Any Microcontroller! - Instructables
September 27, 2017 - 6.25 Nanosecond Resolution Timer for Any Microcontroller!: While designing a solid state replacement for a vacuum-tubes-and-CRT radar display subsystem, I was stuck at getting a suitable system to time the period between the synch pulse and ...
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 5000
Bug in delayMicroseconds() · Issue #5000 · espressif/arduino-esp32
April 1, 2021 - There was an error while loading. Please reload this page · ESP32 crashes when I call the function after ~1 hour 20 minutes of usage, because esp_timer_get_time() return a int64_t value and is parsed as uint32_t in delayMicroseconds()
Author   espressif
🌐
Medium
aliafshar.medium.com › esp-idf-tutorials-part-2-delay-75a6c29e05e4
ESP-IDF for Arduino Users, Tutorials Part 2: Delay | by Ali Afshar | Medium
January 6, 2021 - https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html · Delay doesn’t have to block like Arduino. Delay some milliseconds like this: vTaskDelay(pdMS_TO_TICKS(10)); Since vTaskDelay accepts ticks, the ...
🌐
ESP32 Forum
esp32.com › board index › english forum › discussion forum › esp-idf
[SOLVED] My function for microseconds delay doesn't work properly - ESP32 Forum
September 9, 2021 - Thank you for your replies! @mbratch, with your message, now I understand why my first piece of code wasn't working, the condition was wrong! Hence if I use the esp_rom_delay_us (instead of the while loop and esp_timer_get_time) it should not give any kind of problem.
🌐
Arduino
docs.arduino.cc › language-reference › en › functions › time › delayMicroseconds
delayMicroseconds() | Arduino Documentation
June 5, 2025 - The largest value that will produce an accurate delay is 16383; larger values can produce an extremely short delay.
🌐
GitHub
github.com › espressif › ESP8266_RTOS_SDK › issues › 914
Nanosecond delay using "nop" (GIT8266O-487) · Issue #914 · espressif/ESP8266_RTOS_SDK
June 10, 2020 - Using "nop" command gives me 0.5us delay when ESP works at 80MHz. It should be much faster. Aswell "for" loop with 1 iteration takes longer then on OPEN RTOS SDK.
Author   espressif
🌐
RNT Lab
rntlab.com › question › esp32-replacement-for-arduino-delay
ESP32 replacement for Arduino "delay()" ??
When it get’s a request it checks what it’s for and sends the response. Most of the time it’s idling so you can do a lot. Also remember that the ESP32 has two cores so you can set one to handle HTTP requests and the other to handle everything else. ... Hi Steve, Thanks.. I am looking at NOT using regular delay()..