Hi!
Many thanks for this hint. Yes, the code was not ideal in that point.
I now setup a completely new project with just the lines below and - as
expected - the flags are set correctly. Then I started putting back the
other code I previously had and found, the the sequence of changing the
clock divider to 1:2 causes the problem: after XDIV = 0xff the timer0
flags are not raised anymore. Ok, I carefully studied the datasheet
again and found: "When the system clock is divided, Timer/Counter0 can
be used with Asynchronous clock only." (page 37) Is there any workaround
for this? (the datasheet does not say anything...)
Best regards
Jan
On 20.04.2009 18:06, Jan Waclawek wrote:
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?
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list