Skip to content

ESP32 Timer Counter Value Not Incrementing

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 Timer Counter Value Not Incrementing. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 timer counter remains at 0 or does not increment at expected rate.

Quick Fix

Wrong

uint64_t val;
timer_get_counter_value(TIMER_GROUP_0, TIMER_0, &val);
// Timer not started
Counter value: 0 (timer never started)
timer_config_t config = { /* ... */ };
timer_init(TIMER_GROUP_0, TIMER_0, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
timer_start(TIMER_GROUP_0, TIMER_0);
uint64_t val;
timer_get_counter_value(TIMER_GROUP_0, TIMER_0, &val);
float seconds = val / 10000.0 / 8000.0;  // Adjust for divider
Serial.printf("Counter: %llu (%.2f seconds)\n", val, seconds);
Counter: 100000 (1.25 seconds since start)

Prevention

Call timer_start() after init. Set initial counter value with timer_set_counter_value(). Use timer_get_counter_value() for 64-bit read. Calculate elapsed time: counter_value / (80 MHz / divider).

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

FAQ

### How do I read the timer counter safely?

Use timer_get_counter_value() which handles the 64-bit atomic read. Direct register reads may get inconsistent high/low values.

Can I use the timer counter as a microsecond clock?

Yes. Set divider to 80 and read counter value directly as microseconds. Max 64-bit count at 1us resolution: ~584,942 years.

Does the counter reset on alarm?

Yes, if auto_reload is enabled. The counter resets to the reload value (default 0) after each alarm.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro