🌐
ESP32 Forum
esp32.com › viewtopic.php
Wait microsecond - ESP32 Forum
The ROM function ets_delay_us() (defined in rom/ets_sys.h) will allow you to busy-wait for a correct number of microseconds.
🌐
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 ESP-IDF
esp32tutorials.com › home › esp32 esp-idf freertos timer and delay using esp-idf
ESP32 ESP-IDF FreeRTOS Timer and Delay using ESP-IDF
August 15, 2022 - In the output we can see the two timer values (time in microseconds since boot) that we obtained after a delay of 1 tick. The difference between them is 5383 microseconds. As we mentioned before, the tick time period is predefined as 10 milliseconds.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
ESP32 delay() doesn't work - Programming - Arduino Forum
November 18, 2022 - Hi all, I am using ESP32 to do a project by using delay() function. It seems to me that the delay() function never works! I tried using the millis() as well and it doesn't work so well neither. unsigned long ini= 0 ; void setup() { Serial.begin(115200); delay(10); wifisecure.setInsecure(); while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network.
🌐
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
🌐
Reddit
reddit.com › r/esp32 › vtaskdelay with long wait times
r/esp32 on Reddit: vTaskDelay with long wait times
October 24, 2023 -

Hello,

I am working on a project in IDF with FreeRTOS. Among all the tasks, the project has one task that needs to run every day at midnight (00:00 UTC). To do this, I have an external RTC with which I calculate how many seconds are left until midnight (I have verified that the calculation is correct). From there, I convert it to milliseconds and calculate the number of ticks to wait using pdMS_TO_TICKS(), passing this tick number to vTaskDelay(). However, the task runs much earlier. Does anyone know why this might be? The Tick rate (Hz) is 1000.

On the other hand, I have verified that when I convert X milliseconds to ticks using pdMS_TO_TICKS() and then calculate how many milliseconds those ticks are with pdTICKS_TO_MS(), the milliseconds value does not match the initial one. Does anyone know why this might be? Here's an example:

43200 seconds to milliseconds: 43200000
43200 seconds to ticks: 250327 
43200000 milliseconds to ticks: 250327 
250327 ticks to milliseconds: 250327

Thank you very much in advance.

🌐
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?

🌐
Esp32developer
esp32developer.com › programming-in-c-c › delays › delays
Delays – ESP32 Developer
The RTOS tick period is (by default) 10ms · N.B. vTaskDelay is no good for small mS delays. It is based on the RTOS tick rate. If you select a value < portTICK_PERIOD_MS you may get a zero delay or you may get a delay of portTICK_PERIOD_MS (so 10mS)
🌐
Mechatronics LAB
mechatronicslab.net › home › lessons › esp32 arduino programming handbook › chapter 12: timers, delays & interrupts › non-blocking delays with millis() for esp32 arduino programming
Non-Blocking Delays with millis() for ESP32 Arduino Programming - Mechatronics LAB
Unlike delay(), which stops everything, ... programs smoother and more responsive. What Is millis() and Why Use It? The millis() function returns the number of milliseconds since your ESP32 started running....
Find elsewhere
🌐
ESP32 Forum
esp32.com › viewtopic.php
IDF documentation suggests microsecond delay - should be millisec - ESP32 Forum
December 8, 2018 - For example, when esp_wifi_start returns ESP_ERR_NO_MEM, the recoverable-error code vTaskDelay can be called, in order to get a microseconds’ delay for another try. Suggested change -- change "microseconds" to "milliseconds" because vTaskDelay is based on FreeRTOS time tic which is in multiple ...
🌐
Mechatronics LAB
mechatronicslab.net › home › lessons › esp32 arduino programming handbook › chapter 12: timers, delays & interrupts › delay() function for esp32 arduino programming
Delay() Function for ESP32 Arduino Programming - Mechatronics LAB
What Is delay() and Why Use It? The delay() function tells your ESP32 to “wait” before running the next line of code. One millisecond equals one-thousandth of a second. For example, delay(1000) makes the ESP32 pause for one second.
🌐
ESP32 Forum
esp32.com › viewtopic.php
freeRTOS microsecond delay - ESP32 Forum
September 23, 2022 - Here is the sample code : for(int32_t i = stepper1.curr_pos; i<=stepper1.pos;i++) { gpio_set_level(STEP_PIN , 0); ets_delay_us(5); gpio_set_level(STEP_PIN , 1); } It is the just basic movement for stepper motor. Thanks for helps It is better to avoid ets_delay_us() and esp_rom_delay_us() (read ...
🌐
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 - Firstly, I didn't included esp_timer.h, I think the compiler didn't recognize esp_timer_get_time() and that's why it wasn't working (but no errors during compiling). Am I right? Then, I tried your esp_rom_delay_us but it gives a possible problem (and here the second question): it stops the processor for a certain time, giving the impossibility of performing other tasks.
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 2981
delay() function doesn't work for less than 10ms · Issue #2981 · espressif/arduino-esp32
July 11, 2019 - Current code is: void delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); } // My suggestion is: void delay(uint32_t ms) { uint32_t delay_end = millis() + ms; vTaskDelay(ms / portTICK_PERIOD_MS); while (delay_end > millis()) { NOP(); } }
Author   espressif
🌐
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?

🌐
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; ...
🌐
DeepBlue
deepbluembedded.com › home › blog › arduino delay() function tutorial
Arduino delay() Function Tutorial
July 26, 2025 - The delay() function pauses the program for the amount of time (in milliseconds) specified as a parameter.
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 1343
Timer Interrupt vs Delay · Issue #1343 · espressif/arduino-esp32
April 22, 2018 - I currently have a metering pump that is controlled by the ESP32. To apply the correct dosage, I use a delay (ms). This is a big problem for larger dosages, it locks the system for a long time. Studying a bit on the web, I realized that I could use the Timer Interrupt to avoid locking the system. Unfortunately I could not implement it. Can you guide me? Basically I have a · digitalWrite (PIN, HIGH); delay (ms); digitalWrite (PIN, LOW); ms is a variable in milliseconds, how to adapt to Timer Interrupt?
Author   espressif
🌐
Xplore-DNA
xplore-dna.net › mod › page › view.php
Coding ESP32: delay() | DNA
February 18, 2021 - Pausiert die Ausführung des Programms für die angegebenen Millisekunden. Zudem dienen Verzögerungen der Stabilität des Programms