Skip to content

ESP32 Timer Calibration Off Due to RC Oscillator

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 Timer Calibration Off Due to RC Oscillator. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 timer timing is inaccurate because the RTC uses the internal RC oscillator instead of the external crystal.

Quick Fix

Wrong

// Using default timer config - may drift 1-3%
Timer drifts significantly. 1-second timing becomes 0.97-1.03 seconds.
// Calibrate timer against RTC
uint64_t cal = timer_calibrate(TIMER_GROUP_0, TIMER_0, 100000);
if (cal != 0) {
  float error = (cal - 100000.0) / 100000.0 * 100;
  Serial.printf("Calibration: %llu ticks (%+.2f%% error)\n", cal, error);
} else {
  Serial.println("Calibration not supported");
}
Calibration: 99872 ticks (-0.13% error)
(Error within acceptable range)

Prevention

Use timer_calibrate() to measure timer accuracy. Apply software correction for drift. Use external 32kHz crystal for accurate RTC timing. For precision timing, use the FRC (Free Running Counter) timer. Recalibrate when temperature changes.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### Why does ESP32 timer drift?

The RTC uses an internal RC oscillator with 1-3% accuracy. Temperature changes cause additional drift. External 32kHz crystal improves to 20ppm.

How do I use the external crystal?

Enable CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS in menuconfig. The external crystal provides much better accuracy.

What is the most accurate timer?

The FRC2 usec timer (micros()) uses the PLL which is locked to the external 40MHz crystal. It drifts less than 0.1%.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro