avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] Interrupts from assync timer in sleepmode


From: Nils Springob
Subject: Re: [avr-chat] Interrupts from assync timer in sleepmode
Date: Tue, 27 Sep 2005 10:17:02 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

AS0 is 1, that is what make it an ansyncrone timer. The timer runs from the 32768 Hz crystal as it should.

do you write to the OCR0 or TCNT0 just before entering sleep mode?

Yes I do.
As you can see belove, I update the OCR0 to a new value every time.

The code belove will show the problem. Every 6th time the mainloop will wait until the interrupt flag have been set before entering sleep. When this result in that the output compare match is not serviced until the next time there is an ocr match. Since the OCR0 haven't been updated, it will count another 256, insteed of 32.

If the sleepmode is idle, every thing works as expected. The interrupt is serviced right after the sleep instruction.


The following code is for IAR compiler, but it should be clear enough. (We are helping a customer that use that compiler, sorry)

Did you checked the generated assembler code, that there is no other OP code inserted between the "cli" and the "sleep" instruction?

The cli instruction will be executed with a delay of one cycle, so interrupts will be enabled when sleep mode is activated. It is important that the sleep instruction is the next executed opcode.




reply via email to

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