esp32-hal-misc.c: unsigned long IRAM_ATTR millis() { return (unsigned long) (esp_timer_get_time() / 1000ULL); } Of course, that just begs the question .... why would you ever use millis() on an ESP32? The esp_timer_get_time() function returns a 64-bit integer, has microsecond-resolution, and w… Answer from gfvalvo on forum.arduino.cc
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Question about ESP32 millis() counter? - Programming - Arduino Forum
March 8, 2021 - Hello, I have this kind of question. Is there any limitation about max millis() counter? I mean does it matter if currenttime in millis counts up certain value and the whole loop stops? I'm using millis() in order to set one counter to 0. At the moment ESP32 plugged to serial monitor about 23hours ticking, the millis() was working fine.
Discussions

Where is the definition of function millis() located used for ESP32
Hi everybody, recently somebody asked a question about the rollover of millis() on ESP32-boards. I tried to find the definition of the function millis() but had no luck so far. I found something in ...packages\arduin… More on forum.arduino.cc
🌐 forum.arduino.cc
4
0
November 21, 2021
ESP32 millis() overflows break the loop - Need Help With My Project - Blynk Community
Hardware: Board: ESP32 Dev Module Core Installation/update date: Mon Jan 7 Blynk library: 0.5.4 Blynk server: local IDE name: Arduino IDE 1.8.6 Flash Frequency: 40Mhz PSRAM enabled: no Upload Speed: 921600 Computer OS: Mac OSX Description: Hello, I got the strange behaviour of the ESP32 millis() ... More on community.blynk.cc
🌐 community.blynk.cc
1
1
January 16, 2019
Millis overflow
I find uint32_t difficult to think in, but uint16_t is easier. So, without overflow, we have something like t1 = 100, millis = 750: millis - t1 = 650, which is greater than 500, so true. OK, so what about overflow? t1 = 65505 (31 milliseconds before overflow), millis = 200, what's 200 - 65505 in integer math? So it turns out that 200 - 65505 = 231, which is... exactly what we want. This works in uint32_t too, so if your code looks like this: if(millis() - t1 > 500) { // ... do something t1 = millis(); } It will work exactly as you intend, even if millis overflows. More on reddit.com
🌐 r/esp32
14
1
May 9, 2023
Serious problem with millis()
Hardware: Board: ESP32 Dev Module nodeMCU 32s Core Installation version: latest git IDE name: Arduino IDE Flash Frequency: 40Mhz PSRAM enabled: ?no? ?yes? Upload Speed: default speed Computer OS: Ubuntu Description: millis() is not worki... More on github.com
🌐 github.com
16
February 6, 2019
🌐
ESP32 Forum
esp32.com › viewtopic.php
ESP-IDF, esp_timer, and how to replace millis() - ESP32 Forum
I'm working on an application that I'm moving some code from the arduino environment. I'm attempting to make if ESP-IDF only and the code I'm changing uses millis(). It appears from the ESP docs and some searching here on the forums that esp_timer_get_time() would be the replacement.
🌐
ESP32Cube
esp32cube.com › post › how-to-use-millis-instead-of-delay
How to use millis() instead of delay() | ESP32Cube
November 25, 2024 - So we know that delay() is a relative time clock. While millis() is an absolute time clock.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Where is the definition of function millis() located used for ESP32 - Programming - Arduino Forum
November 21, 2021 - Hi everybody, recently somebody asked a question about the rollover of millis() on ESP32-boards. I tried to find the definition of the function millis() but had no luck so far. I found something in ...packages\arduino\hardware\mbed\1.1.6\cores\arduino\wiring.cpp unsigned long millis() { return t.read_ms(); } but I'm still unsure if this is the defintion used if I compile for the platform ESP32 So does somebody know where this definition is or a method to really find it? best regards S...
🌐
Blynk Community
community.blynk.cc › need help with my project
ESP32 millis() overflows break the loop - Need Help With My Project - Blynk Community
January 16, 2019 - Hardware: Board: ESP32 Dev Module Core Installation/update date: Mon Jan 7 Blynk library: 0.5.4 Blynk server: local IDE name: Arduino IDE 1.8.6 Flash Frequency: 40Mhz PSRAM enabled: no Upload Speed: 921600 Computer OS: Mac OSX Description: Hello, I got the strange behaviour of the ESP32 millis() overflows and the blynk Heartbeat timeout.
Find elsewhere
🌐
GitHub
github.com › peufeu2 › ESP32FastMillis
GitHub - peufeu2/ESP32FastMillis: Faster millis() and micros() for ESP32 and AceRoutine · GitHub
Then, micros() is just two instructions to read the 32-bit micros value from the timer. It is also possible to read a 64 bit microseconds value. For milliseconds, TIMG0_T1 is configured to run at 2 kHz.
Author   peufeu2
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 2430
Serious problem with millis() · Issue #2430 · espressif/arduino-esp32
February 6, 2019 - At the time of the evaluation of the while condition, micros() will be 0xFFFFFFFF + 100 is 99, because of 2’s complement arithmetic. So millis() will be 99 / 1000 is 0.
Author   espressif
🌐
ESP32 Forum
esp32.com › viewtopic.php
get current time in millis() - ESP32 Forum
July 21, 2017 - This is how arduino gets millis https://github.com/espressif/arduino-es ... misc.c#L50 You can also call esp_log_timestamp() from esp_log.h which is the same timestamp used in the ESP_LOGx() functions. You can also use arduino in esp-idf https://github.com/espressif/arduino-es ... -component ... This might be a useful previous post: https://esp32.com/viewtopic.php?t=1468 If it were me, I'd probably use "gettimeofday".
🌐
Reddit
reddit.com › r/esp32 › question about millisecond timestamp on esp32
r/esp32 on Reddit: Question about millisecond timestamp on ESP32
April 15, 2023 -

Hi,

Does anybody knows any library that is able to get the time in milliseconds from the ESP32 RTC? I need it because I'm interfacing a geophone and need the data with a correct timestamp and the sampling frequency is around 200 Hz.

Thanks in advance.

🌐
Reddit
reddit.com › r/esp32 › how to add microseconds dely inside the millis function
r/esp32 on Reddit: how to add microseconds dely inside the millis function
February 7, 2023 -

I want to make the pin high as soon as the code enters into the millis function and turn it off after some microseconds and again turn it on after some milliseconds. here I can create a microsecond delay using delayMcirosecond but how can create the delay in milliseconds as we can not use delay inside millis

Code: int Ad[] = {20, 7, 6, 9, 1, 7, 8, 1, 1, 1, 30, 8, 7}; float Af[] = {1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 23}; int Ap[] = {15, 25, 50, 50, 50, 90, 50, 50, 70, 50, 50, 50, 50};

int xa = sizeof(Ad) / sizeof(int); float ya = sizeof(Af) / sizeof(float); int za = sizeof(Ap) / sizeof(int);

void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(26,OUTPUT);

} void w_a(int Ad1[], int x , float Af1[] , int y, int Ap1[], int z) { unsigned long previousMillis = 0; int i; for (i = 0; i < x; i++) { int d = Ad1[i] * 1000; float f = round((1 / Af1[i]) * 1000); int p = Ap1[i];

unsigned long currentMillis = millis();
previousMillis = currentMillis;
while (currentMillis - previousMillis < d)
{
  digitalWrite(26, HIGH);
  delayMicroseconds(p);
  digitalWrite(26, LOW);
  delay(f);
  currentMillis = millis();
}
previousMillis = currentMillis;

} }

void channel1_1() { int j = 0; for ( j = 0; j < 2; j++) { w_a(Ad, xa, Af, xa, Ap, xa); // A } }

void loop() { channel1_1(); }

🌐
Reddit
reddit.com › r/esp32 › esp32 sparkfun thing and millis
r/esp32 on Reddit: Esp32 sparkfun thing and millis
August 12, 2019 -

Hey there! I am trying to implement non delay timer on Esp32 but every time I use millis() (tried micros() too) the Esp32 causes to panic. Is it a known issue? and how do you work around that?

Thanks

🌐
YouTube
youtube.com › watch
ESP32 & ESP8266 - Take control over time with millis and micros - YouTube
In this episode of ESP32 & ESP8266 programming, we are going to discuss time functions millis() and micros().
Published   November 28, 2023
🌐
ESP32 Forum
esp32.com › viewtopic.php
millis() and light-sleep - ESP32 Forum
August 9, 2023 - It is possible that this hasn't worked in the first arduino-esp32 release, v1.0.0, which came out in July 2018. arduino-esp32 uses esp_timer_get_time IDF function to implement millis, and esp_timer_get_time has maintained time in light sleep since IDF v3.1, released in September 2018.
🌐
Reddit
reddit.com › r/arduino › question about using millis() efficiently
r/arduino on Reddit: Question about using millis() efficiently
March 1, 2024 -

If your code includes many function on the main loop which call millis() for various timing needs, is it better to have a global variable which updates once per cycle with the value of millis() or is calling millis() seperatly many times perfectly fine?

We are talking 10-12 millis() calls per cycle at the moment.

The MCU is esp32

Top answer
1 of 2
5
As a general programming principle it's a good idea to spend a few bytes of memory to avoid reprocessing. What's more, loop() executes really fast. On a Uno I think an empty loop() will execute about 4x per millisecond. Less often of course depending on how much it does, but in simple sketches multiple calls to millis() will likely return the same value during an iteration of loop(). My usual practice is to start loop() with long msNow = millis(); and use msNow as the time throughout loop(). edit: oh wait, you said esp32, the figure I quoted was for a Uno. Yes, almost undoubtedly millis() will return the same value throughout your loop.
2 of 2
1
is it better to have a global variable which updates once per cycle with the value of millis() or is calling millis() seperatly many times perfectly fine? ... The MCU is esp32 For the function resolution of ESP32 specifically, the Arduino function internally calls esp_timer_get_time() which has microsecond resolution, which the library cuts off to milliseconds. For what is "better" will depend on what you're using it for. If you need consistency so everything in the same loop has the same number you'll want to call it once. If you're looking for the current time at that moment, you'll probably want to call it each time. The function call isn't free, it has the cost of potentially having instruction cache misses, the data load, and actually doing the math, but each call takes on the order of a few hundred nanoseconds worst case. If you're doing more advanced programming, another important detail for timings will be the CPU speed. The ESP32 family has power management so you don't have to be running the CPU at full speed and can do dynamic scaling, just like your home PC isn't running at 5 GHz all the time when browsing the web or sitting idle versus full power when playing advanced games. Sure you can run both cores at 240 MHz or even 400 MHz for the ESP32-P4 CPUs, but you can also slow it down to 80 MHz, or even 40 MHz or lower with custom settings. Even though operations take the same number of cycles you can get an order of magnitude difference in time if you're looking for efficiency of power. And if you're going really advanced, you can attach a JTAG debugger to use a profiler to see the actual performance numbers.
🌐
TechOverflow
techoverflow.net › 2025 › 07 › 05 › esp-idf-equivalent-of-arduino-millis
ESP-IDF equivalent of Arduino millis() | TechOverflow
July 5, 2025 - #include <esp_timer.h> uint32_t millis() { return esp_timer_get_time() / 1000; } // Usage example void myFunc() { uint32_t currentMillis = millis(); // Use currentMillis as needed } Check out similar posts by category: ESP32, C/C++ If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow ·
🌐
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
What Is millis() and Why Use It? The millis() function returns the number of milliseconds since your ESP32 started running. You can use this number like a stopwatch. Instead of pausing your code, you check how much time has passed and decide if it’s time to act.
🌐
YouTube
youtube.com › embedotronics technologies
millis alternative in esp-idf - YouTube
In this video tutorial we will learn how to use millis output in esp-idf as millis we will be undefined in esp-idf so for that we need to use timer which is ...
Published   October 2, 2022
Views   1K
🌐
YouTube
youtube.com › watch
ESP32 millis() instead of delay() - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2025 Google LLC
Published   January 26, 2022