[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-chat] Interrupts from assync timer in sleepmode
From: |
Bjarne Laursen |
Subject: |
Re: [avr-chat] Interrupts from assync timer in sleepmode |
Date: |
Fri, 23 Sep 2005 11:07:39 +0200 |
User-agent: |
Mozilla Thunderbird 0.7.3 (Windows/20040803) |
Nils Springob wrote:
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)
#include <iom64.h> // same behavior on mega64 and mega128
#include <ina90.h>
unsigned int b;
#define DEBUG_PORT PORTB //interrupt uses BIT0
//main loop uses BIT1
#pragma vector=TIMER0_COMP_vect
__interrupt void ISR_Timer0_Compare(void)
{
OCR0 += 32;
DEBUG_PORT |= 0x01;
while (ASSR&0x02);
DEBUG_PORT &= ~0x01;
}
void AsyncTimer_Init(void)
{
ASSR=0x08; // Set AS0 (use async 32kHz clk
source)
OCR0=0; // Set output compare register to 0
TCCR0=0x04; // TCN0 standart mode,
clk=32768/64=512Hz
while (ASSR&0x01); //wait for update
TIFR=0x03; // Clear intr. flags
TIMSK = 0x00; //clear all interrupts
TIMSK |= 0x02; // Enable compare interrupt OCR0
}
void main( void)
{
MCUCR=0x00;
SFIOR=0x00;
DDRB = 0xFF; //PORTB set to output
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
PORTF = 0x00;
PORTG = 0x00;
AsyncTimer_Init(); // Initialize timer0
asm("sei"); // enable interrupt
for( ;;)
{
// MCUCR = 0x20; //idle mode
MCUCR = 0x38; //power save mode
asm("sei"); //enable intr.
asm("sleep");
asm("cli"); //diable intr.
MCUCR = 0x00;
DEBUG_PORT |= 0x02;
if (!(b%6)) // every 6th time we will wait until the
interupt is already there before sleep
{
for(;!(TIFR&0x02);); //wait for interrupt flag to be set
}
DEBUG_PORT &= ~0x02;
b++;
}
}
- [avr-chat] Interrupts from assync timer in sleepmode, Bjarne Laursen, 2005/09/22
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Erik Christiansen, 2005/09/22
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Bjarne Laursen, 2005/09/22
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Nils Springob, 2005/09/22
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Bjarne Laursen, 2005/09/22
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Nils Springob, 2005/09/22
- RE: [avr-chat] Interrupts from assync timer in sleepmode, Larry Barello, 2005/09/22
- Re: [avr-chat] Interrupts from assync timer in sleepmode,
Bjarne Laursen <=
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Nils Springob, 2005/09/27
- Re: [avr-chat] Interrupts from assync timer in sleepmode, Bjarne Laursen, 2005/09/27
Re: [avr-chat] Interrupts from assync timer in sleepmode, Joerg Wunsch, 2005/09/22
Re: [avr-chat] Interrupts from assync timer in sleepmode, Dmitry K., 2005/09/22