Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: timer 1 question

2008-02-25 by bobby cossum

--- In AVR-Chat@yahoogroups.com, "bobby cossum" <nbronski@...> wrote:
> 
> 
> if (TIFR1 & (1 << TOV1)) {             // timer1 overflow ?
>   TIFR1 &= ~(1 << TOV1);               // clear timer1 overflow
>   if (++t1Count == 15) {
>     PORTD ^= 0x80;
>     t1Count = 0;
>   }
> }


ok, so i have learned that to reset TOV1 i must set it.  very zen. 
(exactly how far north were the guys who designed this chip?  bet it
was summer.  couldn't sleep on account of 24 hour daylight.)

it finally sunk in on the hundredth reading of the datasheet.  now i
can sleep.  or could if my timer was working as desired.

i want TOV1 set every 0.0333333 seconds.  my mega168 is running at
16MHz.  i put timer1 in fast pwm mode 15, WGM13:0 = 15.  i select a
prescaler of 64, CS12:0 = 5.  i set OCR1A = 8333.

so i figure 16000000 / 64 = 250000.

and 250000 / 8333 is as close to 30 as i'm going to get.

it's close enough.  delays getting to the bit of code where i check
the flag and a fairly busy timer2 ISR might just nudge it towards
greater accuracy.

it would be close enough, that is, but my timer math still appears to
be off.  the flicker on my led has slowed, but is still too fast.

any advise greatly appreciated.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.