[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L
From: |
'Andrew McNabb' |
Subject: |
Re: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L |
Date: |
Thu, 27 May 2004 15:55:08 -0600 |
User-agent: |
Mutt/1.5.6i |
I've been playing around with everything I can think of or have been
recommended on the list. I've finally noticed that under certain
circumstances I can get _something_ to happen when I enable interrupts.
I just don't know what it means. Let me try to explain:
When my main loop just outputs TCNT0, it doesn't make any difference
whether interrupts are on or off. Either way the lights are counting
from 0 to 0xff over and over.
However when I add something to my while loop that polls TCNT0 to check
"manually" whether there's been an overflow, the behavior depends on
whether or not I've set TOIE0 in TIMSK. If TOIE0 is not set, everything
works properly and the lights flip on and off every second. However if
TOIE0 is set, the lights on PORTB all turn on and stay on. But if the
while loop is empty, the lights stay off.
I can't quite put a finger on what's going on. Does anyone have any
ideas?
Here's my code in its current form. Thanks.
--------------------------------------
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
SIGNAL (SIG_OVERFLOW0)
{
}
int main()
{
int wasjustzero = 0;
// Enable outputting to Port B;
DDRB = 0xff;
// Turn off all of the lights;
PORTB = 0xff;
// Set clock to Asynchronous Mode (use 32,768 Hz crystal)
ASSR = _BV(AS0);
// Scale to PCK0/128 (256 Hz)
TCCR0 = _BV(CS02) | _BV(CS00);
//TCCR0 = _BV(CS02) | _BV(CS01) | _BV(CS00);
TCNT0 = 0;
// Make sure the interrupt is cleared.
TIFR = _BV(TOV0);
// Enable Interrupts (set TIMSK and then global interrupts)
TIMSK |= _BV(TOIE0); // THIS IS THE LINE THAT I POINTED OUT
sei();
while (1) {
//PORTB = ~TCNT0;
// Poll timer counter 0 to flip the LED every second:
if (TCNT0 == 0) {
if (!wasjustzero) {
PORTB = ~PORTB;
wasjustzero=1;
}
} else {
wasjustzero=0;
}
}
return 1;
}
- [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Andrew McNabb, 2004/05/26
- RE: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Rune Christensen, 2004/05/26
- AW: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Peter Hierholzer, 2004/05/27
- RE: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Rune Christensen, 2004/05/27
- AW: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Peter Hierholzer, 2004/05/28
- Re: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, 'Andrew McNabb', 2004/05/28
- AW: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Peter Hierholzer, 2004/05/28
- Re: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, 'Andrew McNabb', 2004/05/28
Re: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, 'Andrew McNabb', 2004/05/27
Re: [avr-gcc-list] Timer Interrupt Problem on ATmega 103L, Andrew McNabb, 2004/05/28