Shop by category
Shop all componentsSensors & MCUs
Timer2 on the ATmega328P also offers prescalers 32 and 128. The smallest prescaler that fits gives the finest timing steps.
OCR = f cpu ÷ (prescaler × f target) − 1f actual = f cpu ÷ (prescaler × (OCR + 1))16 MHz clock and a 1 Hz interrupt on the 16-bit Timer1: prescaler 256 gives OCR = 16,000,000 ÷ 256 − 1 = 62,499 with no error. Prescaler 1024 with OCR 15,624 also works.
Hardware timers let a microcontroller do things at exact intervals without a delay loop. In CTC (clear timer on compare match) mode, the timer counts up to OCR and fires an interrupt, then restarts.
Each prescaler divides the clock before it reaches the counter. A larger prescaler reaches lower frequencies but with coarser steps, so the best choice is the smallest prescaler that keeps OCR within the timer’s range.
Timer1 with prescaler 256: OCR1A = 16,000,000 ÷ (256 × 1) − 1 = 62,499.
Timer0 and Timer2 are 8-bit; Timer1 is 16-bit. Timer0 runs millis(), so use Timer1 or Timer2 for your own interrupts.
OCR must be a whole number, so some frequencies round. The calculator shows the actual frequency you get.
OCR = f cpu ÷ (prescaler × f target) − 1; f actual = f cpu ÷ (prescaler × (OCR + 1)).
16 MHz clock and a 1 Hz interrupt on the 16-bit Timer1: prescaler 256 gives OCR = 16,000,000 ÷ 256 − 1 = 62,499 with no error. Prescaler 1024 with OCR 15,624 also works.
Geekobot builds that use it include Program a bare AVR microcontroller on a breadboard with Arduino as ISP. Each has the full parts list, wiring and code.
Results are estimates for design and learning. Check critical designs against the component datasheet. Made by the Geekobot Learning Team. How we write our calculators