Electrical – AVR 10ms timer with 8MHz clock

atmegaavravr-gcctimer

I want to generate a 10ms timer using ATMEGA32. The crystal used is 8MHz.
Is this calculation correct TCNT0 value is correct.The prescaler value i used is 1024.

enter image description here

enter image description here

enter image description here

is the calculation and the value 78 for TCNT0 is correct?

Best Answer

If you want to get periodic timer, you shall use CTC mode.

Check the datasheet page 99:

http://www.atmel.com/Images/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf

The formula is: F = F_CPU / (2 * N * (1 + OCR0))

OCR0 = (F_CPU / (F * 2 * N)) - 1 = (8000000 /(100 * 2 * 1024)) - 1 = 38.06 = 38

Timer 0 CTC mode (page 106): WGM02=0 WGM01=1 WGM00=0

To use TIMER0_COMP_vect interrupt, OCF0 & OCIE0 flags must be set.