avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Timer0 interrupt on Mega128


From: Jan Menzel
Subject: Re: [avr-gcc-list] Timer0 interrupt on Mega128
Date: Tue, 21 Apr 2009 10:12:48 +0200
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

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?








reply via email to

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