ESP32 Timer Interrupt Calculator
Type the interval you want an interrupt to fire at. Get the prescaler, the
alarm value, and a working timerBegin() / timerAlarm() sketch.
Calculator
Enter your target interval. Results and code update as you type.
hw_timer_t *timer = NULL;
void IRAM_ATTR onTimer() {
// Your interrupt code here (keep it short!)
}
void setup() {
timer = timerBegin(1000000); // 1000000 Hz tick rate (80 MHz / prescaler 80)
timerAttachInterrupt(timer, &onTimer);
timerAlarm(timer, 500000, true, 0); // 500000 ticks = 500 ms, auto-reload, repeat forever
}
void loop() {
}
Examples
Pick a preset to populate the calculator above.
About this tool
What is an ESP32 timer interrupt?
The ESP32 has hardware timers that count independently of your program's
loop(). Each timer is fed by the 80 MHz APB clock through a
16-bit prescaler, which divides that clock down to a slower "tick" rate.
You then set an alarm value — the number of ticks to count before the timer
fires an interrupt — so it triggers at exactly the interval you want,
regardless of what the rest of your code is doing.
What this calculator does
You type a plain interval like "500 ms", and it works backward through the
hardware math: it divides the 80 MHz clock by your prescaler to get the tick
frequency, converts your interval into the matching number of ticks for the
alarm value, and flags any rounding so you know exactly how close the
achieved interval is to what you asked for. It then generates a complete
timerBegin() / timerAttachInterrupt() /
timerAlarm() sketch using those values.
Why it's useful
Prescaler-and-alarm math is one of the most commonly searched, commonly botched parts of ESP32 timer setup — a wrong prescaler silently gives you an interrupt that fires at the wrong rate instead of an obvious error. This tool removes that guesswork and hands you a value pair that's already been checked against the hardware limits.
Who should use it
Anyone who needs something to happen at a precise, repeating interval on an
ESP32 without blocking loop() with delay() —
sensor polling, PID control loops, non-blocking blinking, or timestamping.