0
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ Seems correct to me. \$\endgroup\$ – Eugene Sh. Jul 27 '16 at 17:15
  • \$\begingroup\$ It is 0.000128 seconds not microseconds. But all the same, you have calculated TC as if it were 0.000128 seconds. \$\endgroup\$ – Bence Kaulics Jul 27 '16 at 18:19
0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I was trying to implement delay without CTC mode \$\endgroup\$ – ganeshredcobra Jul 27 '16 at 18:07
  • \$\begingroup\$ Oh, then TCNT0 = F_CPU/N/F = 8000000/1024/100 = 78.125 = 78 so it is right. \$\endgroup\$ – Flanker Jul 27 '16 at 18:35
  • \$\begingroup\$ F_CPU/N/F what is that F which is substituted as 100? \$\endgroup\$ – ganeshredcobra Jul 28 '16 at 4:30
  • \$\begingroup\$ F is the timer frequency, if period is 10ms (0.01s) then 1/0.01=100Hz \$\endgroup\$ – Flanker Jul 28 '16 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.