[Icc-avr] Is there something wrong with this RTC interrupt?
Scott Kelley
scottk at skelleyco.com
Thu Jan 3 20:01:04 PST 2008
I'm well in over my head with this stuff...
I don't understand why cli does nothing...
I've forgotten more than I ever knew about machine
language... what would be occurring if "The second one
reenables ints BEFORE the regs are popped"? What would be
the way to deal with this?
_____
From: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] On Behalf Of
BobGardner at aol.com
Sent: Thursday, January 03, 2008 6:42 PM
To: icc-avr at imagecraft.com
Subject: Re: [Icc-avr] Is there something wrong with this
RTC interrupt?
My guess is the problem is the cli and sei in the interrupt
handler. The first one does nothing, because the ints are
off in the handler. The second one reenables ints BEFORE the
regs are popped, which could be the problem.
In a message dated 1/3/2008 8:53:39 P.M. Eastern Standard
Time, scottk at skelleyco.com writes:
My RTC is running slow. I have a number of devices that are
running this code, and all of them are losing somewhere
around 3 or 4 minutes per month.
Looking at my code, it seems that I must be missing ticks
while the isr is running. If I did my math right, it seems
like I must be missing 3 or 4 ticks per second.
If this is right, I think what I need to do is to init the
timer as a countdown, with a preset value equal to 32,768
minus the number of lost ticks. Am I right about this?
This is an ATMega64 running at 3.69 MHz. Does it make sense
that it would lose this many ticks? Seems like a lot when
there is more than 1,000:1 ratio between the main clock and
the RTC frequency...
void rtc_init(void) { // init timer for 1 second interrupt
CLI(); //disable all interrupts - prevent errant interrupts
until set up
TCCR0 &= ~(1<<WGM00); TCCR0 &= ~(1<<WGM01); // Set timer for
normal operation WGM00 = 0, WGM21 = 0
TCCR0 &= ~0x02; TCCR0 |= 0x05; // counter 0 prescaler = 128
CS02=1, CS01=0, CS00=1 (Timer Clock = 32,768 / TCCR2)
TIMSK &= ~((1<<TOIE0)|(1<<OCIE0)); // Disable Timer0
Interrupt TOIE0 = 0, OCIE0 = 0
ASSR |= (1<<AS0); //set Timer/Counter0 for asynchronous
operation - 32,768 Hz crystal AS0 = 1
TCNT0 = 0x00;
TIMSK |= (1<<TOIE0); // Enable Timer0 overflow Interrupt
SEI(); //set the Global Interrupt Enable Bit
} //void rtc_init(void)
void timer0_overflow_isr(void) { // Clock ISR - overflow
occured TCNT2=OCR2
CLI(); // turn Off interrupts
GeneralTimer++;
CommunicationsTimeout ++;
SecondFlag = 1;
WDTimerFlag = 1;
if (++second>=60) { //keep track of time, date, month, and
year
second=0;
MinuteFlag = 1; // Additional clock service is now
passed back to the main code
}
SEI();
}
_______________________________________________
Icc-avr mailing list
Icc-avr at imagecraft.com
http://dragonsgate.net/mailman/listinfo/icc-avr
_____
Start the year off right. Easy ways to stay in shape
<http://body.aol.com/fitness/winter-exercise?NCID=aolcmp0030
0000002489> in the new year.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080103/31c63680/attachment.html
More information about the Icc-avr
mailing list