Although I don't understand the mechanism why it does not work - is this the
only code you have? - you don't want to do this:
TIFR |= _BV(OCF0);
Instead, you want to do this:
TIFR = _BV(OCF0);
The reason is explained in Note 2 under Register Smmary table in the datasheet
(and elsewhere):
2. Some of the status flags are cleared by writing a logical one to them. Note
that the CBI and SBI instructions will operate on
all bits in the I/O register, writing a one back into any flag read as set,
thus clearing the flag. The CBI and SBI instructions
work with registers $00 to $1F only.
JW
----- Original Message ---------------
Hi all!
I'm trying to generate interrupts using timer0 on a Mega128 but
unfortunately can't see any change in overflow and capture/compare
flags. This is the code I tried (compiled using WinAVR 20081205):
TCCR0 = _BV(CS02);
cli();
while (1)
{
if (TIFR & _BV(OCF0))
{
DEBUG_PORT ^= _BV(DEBUG_PIN);
TIFR |= _BV(OCF0);
}
}
I tried the same with TOV0 flag without success. If I read the counter
register TCNT0 I can see the counter counting from 0x00 to 0xff. I
verified in the list file that all registers and bits are correct.
Surprisingly the code works well if changed to timer2.
Can anyone give me a hit why timer0 is not raising this flags in my
code?