Calculate one overflow interval
Use the timer clock settings from your exact MCU datasheet. The default is a classic 12-clock timer at 12 MHz.
- TH register
- TL register
- Timer counts
- One timer tick
- Calculated interval
- Rounding error (actual − target)
- Maximum single interval
Worked examples you can check
These examples use 12 oscillator periods per timer tick. TH and TL are the high and low bytes of the same preload.
| Oscillator | Target | Counts | TH | TL | Actual interval |
|---|---|---|---|---|---|
| 12 MHz | 1 ms | 1,000 | FC | 18 | 1 ms |
| 12 MHz | 50 ms | 50,000 | 3C | B0 | 50 ms |
| 11.0592 MHz | 50 ms | 46,080 | 4C | 00 | 50 ms |
| 11.0592 MHz | 1 ms | 922 | FC | 66 | 1.000434028 ms |
At 11.0592 MHz, 1 ms needs 921.6 ticks. Rounding to 922 produces about +0.434 µs of arithmetic error.
How the preload is calculated
timer frequency = oscillator frequency / divisor
ideal counts = target seconds × timer frequency
counts = nearest integer to ideal counts
preload = 65536 − counts
TH = floor(preload / 256)
TL = preload modulo 256At 12 MHz with a divisor of 12, the timer frequency is 1 MHz. A 50 ms interval needs 50,000 ticks, leaving a preload of 15,536 decimal, or 0x3CB0.
The requested interval must fit between one tick and 65,536 ticks. A full 65,536-tick interval starts at 0x0000; it is not a zero-length interval. Half-tick values round upward.
From a number to a working timer
- Identify the exact chip, timer source and prescaler. Do not infer timer timing from “8051-compatible” branding.
- Choose internal timer operation and Mode 1. Preserve Timer 1's TMOD bits when configuring Timer 0.
- Stop the timer before loading TH/TL, and clear a stale overflow flag before starting a fresh measurement.
- Account for gating, interrupt enables, interrupt priority and other owners of the timer registers.
- Measure the output on your board. Oscillator tolerance, start/load instructions, polling and interrupt latency affect real results.
Scope: this tool calculates count arithmetic. Mode 1 does not automatically reload. Repeating a 50 ms software routine twenty times does not by itself establish an exact one-second period. This is not a baud-rate calculator, external pulse counter, firmware simulation or hardware timing certification.
Common questions
Does this work with every 8051 derivative?
Only when its selected timer behaves as the modeled 16-bit up-counter and you enter the correct clock divisor. Check the device's timer chapter, not just its CPU clock rating. Fractional dividers, cascaded timers and external clocks need a different model.
Why is a requested interval rejected?
One overflow in this mode can represent 1–65,536 ticks. Change the clock configuration or design a multi-overflow schedule for longer intervals. The calculator rejects out-of-range values rather than silently wrapping the preload.
Does auto-reload remove interrupt latency?
No. Hardware reload can keep overflow spacing regular, but the processor still needs time to enter and execute an interrupt handler. This calculator models Mode 1, which requires a software reload for repeated shortened intervals.
Verification and source
The arithmetic was checked with Node.js against eight reference cases, all 65,536 valid integer counts at a 1 MHz timer clock, 18 rounding cases, a half-tick case and 12 invalid inputs. This does not validate a physical MCU or compiled firmware.
Download the calculation source · Download the arithmetic tests
To run locally, save both files in one folder and run node test_timer.mjs.
Register and timer behavior reference: Microchip / Atmel 8051 Microcontrollers Hardware Manual, Timer/Counter chapters. For a concrete derivative, compare the AT89S52 datasheet.