[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Troubles with timer

From: Artur Lipowski
Subject: RE: [avr-gcc-list] Troubles with timer
Date: Thu, 15 May 2003 09:04:25 +0200

-----Original Message-----
From: address@hidden [mailto:address@hidden
Behalf Of Olav Torheim
Sent: 14 maja 2003 18:57
To: address@hidden
Subject: [avr-gcc-list] Troubles with timer
> When entering 2 og 3 (clock/8 and clock/64) as parameters to my
self-defined function scaleTimer
> (char scale) I can watch my program going through the startup sequence.
Entering 4 or 5 makes the
> sequence run so fast that I am unable to watch it. What I am wondering is,
wasn't the opposite
> supposed to happen? And why not?

Using values like 2, 5 for timer prescaler is very confusing. IMO a much
better approach is to use:
_BV(CS01) | _BV(CS00)
it translates directly to/from prescaler table in the datasheet.

The line:
outp(0,TCNT0); /* reload timer with initial value */
in the timer overflow interrupt makes no sense, this interrupt will happen
anly and after TCNT0 wrap to 0.

Forget about outp - it is deprecated.

And at the and 8-) answer for your qestion, look at your loop:
1.      while (teljar2 != 1000)
2.              while(mTimerHighbyte != 0);
3.              asm("nop\n\t");
4.              teljar2 ++;
You wait in the inner while loop until mTimerHighbyte is 0.
Steps 3 and 4 are executeded very quickly and you are again in the inner
mTimerHighbyte is still 0 - and it stays 0 longer if you program longer
timer period <=> higher pescaler, so inner while do not wait.
You increase teljar2 assuming that full timer (mTimerHighbyte) cycle
Longer timer period means that your inner while will "skipped" more times,
so teljar2 will raise to value of 1000 faster.

I hope will able to understand my explanation in spite of my poor english

For pourpose like that it is better to use delay functions from the

Artur Lipowski

Do not use HTML whebn posting to the list, please.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]