Hi again
I finally wrote a quick and dirty code to test micros() versus HighPrecTimer.
It performs 10000 calls to micros() and same thing to HPrecTimer.
Here is the result :slight_smile:
micros() has a 50ns overhead compared to High Precision Timer call. It is only a delay not a jitter or a lack… Answer from freedom2000 on community.simplefoc.com
GitHub
github.com › espressif › arduino-esp32 › issues › 282
micros() & delayMicroseconds() not good enough · Issue #282 · espressif/arduino-esp32
March 23, 2017 - Calling micros() twice is in a row, takes nearly 50uS. Something line: uint32_t t0 = micros(); uint32_t t1 = micros(); uint32_t delta_t = t1 - t0; printf( "Delta = %u\n", delta_t ); // this prints around 51 on my system. Looking at the i...
Author espressif
SimpleFOC Community
community.simplefoc.com › t › possible-bug-with-esp32-micros-function › 122
Possible "bug" with ESP32 micros() function - SimpleFOC Community
September 16, 2020 - Hi all, Being aware of the following bug with micros() function in ESP32 arduino, I have jumped into the FOCutils.cpp file and seen that the bug is probably called ☹ The bug is explained here: https://github.com/espressif/arduino-esp32/issues/1168 Trust me micros() is not reliable with ESP32.
Measuring pulse duration more accurately with ESP32
Hi everyone, I would like to measure a pulse duration of 32us (4 clock cycles at 125kHz). Therefor I set an interrupt on the according pin. The interrupt is triggered with the rising and falling edge and store the start & endtime with the funktion micros() in two diffrent variables. More on forum.arduino.cc
Troubles using micros()/millis() form esp-idf
Hardware: Board: ESP32 DEVKITV1 Core Installation/update date: 25/apr/2018 IDE name: Arduino IDE/IDF component Flash Frequency: 80Mhz Upload Speed: 115200 Description: micros() returns strange valu... More on github.com
ESP32 micros() bug
On ESP32, micros() takes about 150 cycles. More on github.com
Possible "bug" with ESP32 micros() function
I probably pointed to a wrong (old) bug. See this discussion : https://github.com/espressif/arduino-esp32/issues/282#issuecomment-288720151 It is also “closed” but not clear if something was done or not ! seems to be related to the dual cores capabilites of the ESP32 More on community.simplefoc.com
Videos
Mechatronics LAB
mechatronicslab.net › home › lessons › esp32 arduino programming handbook › chapter 12: timers, delays & interrupts › using micros() for esp32 arduino programming
Using micros() for ESP32 Arduino Programming - Mechatronics LAB
What Is micros() and Why Use It? The micros() function tells you how many microseconds have passed since the ESP32 started running. It’s like having an ultra-fast stopwatch in your program.
GitHub
github.com › peufeu2 › ESP32FastMillis
GitHub - peufeu2/ESP32FastMillis: Faster millis() and micros() for ESP32 and AceRoutine · GitHub
The fix is simple: ESP32 has timers with hardware predividers, so this small piece of code just sets up TIMG0_T0 to run on 1 MHz, dividing APB clock by 80. Then, micros() is just two instructions to read the 32-bit micros value from the timer.
Author peufeu2
Arduino Forum
forum.arduino.cc › projects › programming
Measuring pulse duration more accurately with ESP32 - Programming - Arduino Forum
May 31, 2022 - Hi everyone, I would like to measure a pulse duration of 32us (4 clock cycles at 125kHz). Therefor I set an interrupt on the according pin. The interrupt is triggered with the rising and falling edge and store the start & endtime with the funktion micros() in two diffrent variables.
GitHub
github.com › espressif › arduino-esp32 › issues › 1357
Troubles using micros()/millis() form esp-idf · Issue #1357 · espressif/arduino-esp32
April 26, 2018 - Board: ESP32 DEVKITV1 Core Installation/update date: 25/apr/2018 IDE name: Arduino IDE/IDF component Flash Frequency: 80Mhz Upload Speed: 115200 · micros() returns strange values when using arduino-esp32 as component of esp-idf, millis() returns ...
Author espressif
GitHub
github.com › pstolarz › OneWireNg › issues › 38
ESP32 micros() bug · Issue #38 · pstolarz/OneWireNg
March 12, 2022 - On ESP32, micros() takes about 150 cycles. I'm using 80MHz CPU clock to avoid wasting power, delayMicroseconds() calls micros() at least twice. This means delayMicroseconds() takes at least 330 cycles, corresponding to a delay of more th...
Author pstolarz
ESP32 Forum
esp32.com › viewtopic.php
how to SET esp_timer_get_time() ? - ESP32 Forum
unsigned long IRAM_ATTR micros() { return (unsigned long) (esp_timer_get_time()); } How can i solve this, without hacking the library? Is there a way to add an offset by app to esp_timer_get_time()? - Perhaps by using a wake stub, which adds a sleep time offset immediately after wake up? - Or is there a way to overwite the micros() function of arduino-esp32 with a customized version?
Top answer 1 of 7
2
Hi again
I finally wrote a quick and dirty code to test micros() versus HighPrecTimer.
It performs 10000 calls to micros() and same thing to HPrecTimer.
Here is the result :slight_smile:
micros() has a 50ns overhead compared to High Precision Timer call. It is only a delay not a jitter or a lack…
2 of 7
0
That bug was fixed a few years ago. I’ve not seen any strangeness.
YouTube
youtube.com › hollanda academy
Mastering Time Control on ESP32: millis and micros Explained | Arduino IDE Tutorial - YouTube
Description:🚀 Unlock the power of time control in your ESP32 projects! In this comprehensive tutorial, I walk you through the usage of Time Delay, millis(),...
Published October 10, 2021 Views 887
ESP32 Forum
esp32.com › board index › english forum › discussion forum › esp32 arduino
Question re: sub-microsecond timing, performance tuning - ESP32 Forum
January 14, 2020 - uint32_t base = getBaseTime(); unsigned long startTime = micros(); waitForElapsedNs(base, 3000); unsigned long plus3us = micros(); waitForElapsedNs(base, 3000*1000); unsigned long plus3ms = micros(); waitForElapsedNs(base, 3000); unsigned long immediately = micros(); waitForElapsedNs(base, 1000*1000*1000); unsigned long plus1s = micros(); waitForElapsedNs(base, 3000); unsigned long another = micros(); Serial.print("3us later "); Serial.println(plus3us - startTime); Serial.print("3ms laster "); Serial.println(plus3ms - startTime); Serial.print("Immediately return "); Serial.println(immediately - startTime); Serial.print("1 second "); Serial.println(plus1s - startTime); Serial.print("Immediately "); Serial.println(another - startTime); The "immediately" and "another" should be returning VERY fast, with the while loop dropping out almost immediately.
GitHub
github.com › espressif › arduino-esp32 › issues › 1168
strange micros() behavior · Issue #1168 · espressif/arduino-esp32
March 3, 2018 - Here is the code test code: void test() { unsigned long startUs = micros(); unsigned long startMs = millis(); while (millis() < startMs + 10000) delay(1); unsigned long nowUs = micros(); unsigned long nowMs = millis(); Serial.printf("milliseconds elapsed: %ld\n", nowMs - startMs); Serial.printf("microseconds elapsed: %ld\n", nowUs - startUs); } When I call this test() function near program initialization, this is what I get: milliseconds elapsed: 10000 microseconds elapsed: 9999563
Author espressif
ESP32 Forum
esp32.com › viewtopic.php
Wait microsecond - ESP32 Forum
Hi All, Please let me know if anyone has achieved this type of micro seconds delay support in application firmware. I need 10 and 40 microseconds delay support as per request. ... The arduino-esp32 core achieves this using the following code for the delayMicroseconds() func.
GitHub
github.com › espressif › arduino-esp32 › issues › 384
micros() and millis() are uint32_t (unsigned int), instead of unsigned long · Issue #384 · espressif/arduino-esp32
May 18, 2017 - How I found it specifically in my case is I have a function that is passed the reference of either millis or micros to use to determine timing mathmatics for frequency calculations. It was expecting the pointer to be an unsigned long because that's what micros and millis are in everything Arduino, except for ESP32's codebase.
Author espressif
Espressif
docs.espressif.com › projects › esp-idf › en › latest › esp32 › api-reference › system › esp_timer.html
ESP Timer (High Resolution Timer) - ESP32 - — ESP-IDF Programming Guide latest documentation
Get time in microseconds since boot. ... Get the timestamp when the next timer will expire. This function returns the alarm time of the timer that will expire soonest across all dispatch methods (TASK and ISR).
Espressif
docs.espressif.com › projects › esp-idf › en › v5.0 › esp32 › api-reference › system › esp_timer.html
High Resolution Timer (ESP Timer) - ESP32 - — ESP-IDF Programming Guide v5.0 documentation
This function returns the number of microseconds since esp_timer was initialized, which usually happens shortly before app_main function is called.
TutorialsPoint
tutorialspoint.com › arduino › arduino_micros_function.htm
Arduino - micros () function
The micros() function returns the number of microseconds from the time, the Arduino board begins running the current program. This number overflows i.e. goes back to zero after approximately 70 minutes.
Arduino
docs.arduino.cc › language-reference › en › functions › time › micros
micros() | Arduino Documentation
June 5, 2025 - This function returns the number of microseconds since the Arduino board began running the current program.