Timer Overflow Interrupt

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code below works perfectly for at90S2313 but the program counter doesn't go in ISR when compiled for atmega16.
This code changes the status of led upon encountering TIMER1 Overflow.
Any ideas??

/*
// I/O register definitions

#include 
#include 
#define fmove 2
#define xtal 4000000
unsigned char led_status=0xfe;
void initialize(void);
int main(void)
{
initialize();
while (1)PORTB=led_status;

return (0);
}

ISR(TIMER1_OVF_vect)
{
TCNT1=0x10000-(xtal/1024/fmove);

led_status=0x00;
}
void initialize(void)
{
DDRB=0xff;
PORTB=led_status;
DDRD=0xff;
PORTD=0;
TCCR1A=0;
TCCR1B=5;
TCNT1=0x10000-(xtal/1024/fmove);
TIFR=0;
TIMSK=0x80;
GIMSK=0;

sei();

}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just copied that code and built for the mega16. The error I got was:

../eric.c:36: error: 'GIMSK' undeclared (first use in this function)

Surely you must have also got this error when you built for the mega16 ? The mega16's equivalent of the 90S2313's GIMSK register is GICR in fact

My guess is that you are still building for the AT90S2313 and downloading the code into a mega16. If you do this then TIMER1_OVF1_vect is going to be an RJMP at word location 0x0005 while TIMER1_OVF_vect on a mega16 is going to be a JMP at location 0x0010. So 90s2313 code will not have the vector in the right place for a mega16

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot cliff....
v got the error...
v had to set TIMSK register to 0x40 to enable the overflow interrupt n change interrupts name to TIMER1_OVF_vect...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello anubhavk,
can you send the corrected code , because I am trying to learn timer interrupts and this is a good example for me.
thank you..