Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Issue with interrupt handler on Atmel Mega 8 [RSS Feed]

#1 Nov. 1, 2005 16:53:56

Jerome K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Issue with interrupt handler on Atmel Mega 8


I'm trying to use the timer 0 on a mega 8. Everything works fine,
(I mean, i can see the timer TCNT0 incrementing) but when I want
to route the interrupt to an handler, I get a infinite reset.


Here a snipset of the code (full code, is attached)

SIGNAL(SIG_OVERFLOW0)
{
uptime ++;
return 0;
}

void inittimer()
{
// 1024 prescaler
sbi(TCCR0,CS02);
cbi(TCCR0,CS01);
sbi(TCCR0,CS00);

// set the interrupt handle
sbi(TIMSK,TOIE0);
uptime = 0;
}



If I comment the sbi(TIMSK..) all works fine. What can I do to fix
that .?


Thanks for any help./*
* Author: Jerome Kerdreux, Copyright: GPL
*
*
* Chip type : ATMEGA8
* Clock frequency : Internal clock 1 Mhz (factory default)
*/

#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include "test_avr.h"
#include "avr_compat.h"
#include "lcd.h"



#define TIMERINI 256-72
#define TIMERCON 0x05


volatile int uptime;



void delay_ms(unsigned short ms)
/* delay for a minimum of <ms> */
/* with a 1Mhz clock, the resolution is 1 ms */
{
uint8_t inner,inner1;
while (ms) {
inner = 100;
while (inner) {
inner--;
inner1 = 70;
while (inner1) {
inner1--;
}
}
ms--;
}
}



void flashled()
{
if bit_is_set(PORTD,PD5) { cbi(PORTD,PD5); }
else { sbi(PORTD,PD5); }
}



SIGNAL(SIG_OVERFLOW0)
{
uptime ++;
return 0;
}


void debug(char *msg)
{
lcd_gotoxy(0,0);
lcd_puts(msg);
delay_ms(1000);
}


void inittimer()
{
// 1024 prescaler
sbi(TCCR0,CS02);
cbi(TCCR0,CS01);
sbi(TCCR0,CS00);

// set the interrupt handle
//sbi(TIMSK,TOIE0);

uptime = 0;
}



int main(void)
{
char line;

sbi(DDRD,PD5);

lcd_init(LCD_DISP_ON);
lcd_clrscr();

debug("LCD Ok");

// init the the timer
sprintf(line,"TCCR0 %x" , TCCR0);
debug(line);
inittimer();

sprintf(line,"TCCR0 after %x" , TCCR0);
debug(line);
//

flashled();
sei();
debug("Sei Ok");
while (1)
{
delay_ms(500);
lcd_gotoxy(0,0);
sprintf(line,"Timer: %d " , uptime);
lcd_puts(line);

lcd_gotoxy(0,1);
sprintf(line,"TCNT0: %x " , TCNT0);
lcd_puts(line);

flashled();
}

return 0;
}_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Nov. 1, 2005 23:03:54

Jerome K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Issue with interrupt handler on Atmel Mega 8


On Tue, 1 Nov 2005 17:52:57 +0100
Jerome Kerdreux <> wrote:

> I'm trying to use the timer 0 on a mega 8. Everything works fine,
> (I mean, i can see the timer TCNT0 incrementing) but when I want
> to route the interrupt to an handler, I get a infinite reset.
>
>
> Here a snipset of the code (full code, is attached)
>
> SIGNAL(SIG_OVERFLOW0)
> {
> uptime ++;
> return 0;
> }
>
> void inittimer()
> {
> // 1024 prescaler
> sbi(TCCR0,CS02);
> cbi(TCCR0,CS01);
> sbi(TCCR0,CS00);
>
> // set the interrupt handle
> sbi(TIMSK,TOIE0);
> uptime = 0;
> }

I check out the vector table with avr-objdump -S, and I get something
like this:

00000000 <__vectors>:
0: 12 c0 rjmp .+36 ; 0x26
2: 2b c0 rjmp .+86 ; 0x5a
4: 2a c0 rjmp .+84 ; 0x5a
6: 29 c0 rjmp .+82 ; 0x5a
8: 28 c0 rjmp .+80 ; 0x5a
a: 27 c0 rjmp .+78 ; 0x5a
c: 26 c0 rjmp .+76 ; 0x5a
e: 25 c0 rjmp .+74 ; 0x5a
10: 24 c0 rjmp .+72 ; 0x5a
12: 23 c0 rjmp .+70 ; 0x5a
14: 22 c0 rjmp .+68 ; 0x5a
16: 21 c0 rjmp .+66 ; 0x5a
18: 20 c0 rjmp .+64 ; 0x5a
1a: 1f c0 rjmp .+62 ; 0x5a
1c: 1e c0 rjmp .+60 ; 0x5a
1e: 1d c0 rjmp .+58 ; 0x5a
20: 1c c0 rjmp .+56 ; 0x5a
22: 1b c0 rjmp .+54 ; 0x5a
24: 1a c0 rjmp .+52 ; 0x5a


As you can see, vector 10 (timer0 overflow) go to the bad_interrupt.

Somebody with an idea ?

Bye Bye..


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Nov. 1, 2005 23:55:20

Jerome K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Issue with interrupt handler on Atmel Mega 8


On Tue, 1 Nov 2005 15:24:38 -0800
Dave Hylands <> wrote:

> Hi Jerome,
>
> > As you can see, vector 10 (timer0 overflow) go to the bad_interrupt.
> >
> > Somebody with an idea ?
>
> You're missing a
>
> #include <avr/signal.h>


Oh, god I spent a lot of time on this only because I'm missing the
include signal.h :(





> and SIG_OVERFLOW0 is vector9 (the first one is vector0 which is the
> reset vector)

You're right, perhaps I need a little sleep :) .


Thanks a lot. I CC to the list as I receive several answer, but you
get the right one.




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Nov. 1, 2005 23:56:39

Vincent T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Issue with interrupt handler on Atmel Mega 8


On Wed, 2005-11-02 at 00:03 +0100, Jerome Kerdreux wrote:

> > I'm trying to use the timer 0 on a mega 8. Everything works fine,
> > (I mean, i can see the timer TCNT0 incrementing) but when I want
> > to route the interrupt to an handler, I get a infinite reset.

I think that's normal. You forgot to include <avr/signals.h>, so the
"SIG_OVERFLOW0" name was unknown at compile time, and as stated in the
avr-libc documentation, this does not generate a warning and simply
defaults the ISR to the bad interrupt vector, which by default generates
a reset. In the code of your ISR, you put a "return 0" (why?), so the
"reti" instruction that the compiler generated, never gets executed,
hence the interrupt flag doesn't get cleared, therefore it instantly
executes the ISR egain, hence a reset, and so on, forever.

Why did you put a "return" in your ISR ? Am I missing something very
subtle ???


HTH,


--
Vince



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#5 Nov. 2, 2005 00:08:08

Jerome K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Issue with interrupt handler on Atmel Mega 8


On Wed, 02 Nov 2005 00:55:26 +0100
Vincent Trouilliez <> wrote:

> On Wed, 2005-11-02 at 00:03 +0100, Jerome Kerdreux wrote:
>
> > > I'm trying to use the timer 0 on a mega 8. Everything works fine,
> > > (I mean, i can see the timer TCNT0 incrementing) but when I want
> > > to route the interrupt to an handler, I get a infinite reset.
>
> I think that's normal. You forgot to include <avr/signals.h>, so the
> "SIG_OVERFLOW0" name was unknown at compile time, and as stated in the
> avr-libc documentation, this does not generate a warning and simply
> defaults the ISR to the bad interrupt vector, which by default generates
> a reset. In the code of your ISR, you put a "return 0" (why?), so the
> "reti" instruction that the compiler generated, never gets executed,
> hence the interrupt flag doesn't get cleared, therefore it instantly
> executes the ISR egain, hence a reset, and so on, forever.
>
> Why did you put a "return" in your ISR ? Am I missing something very
> subtle ???

Hum, not really funny. I added a return to the ISR because the compilo
give a warning "missing return value for a function". (due to the lack
of SIGNAL macro)

I read the documentation about the missing-warning if signame is wrong,
so I double-checked the typo, but forget to check that I included signal.h
( Perhaps, somebody can add this to the doc, beside this error is really
stupid, but can happen if you are a newbie like me)


Thanks a lot for all answer I get.


(Apologize for my awfull english)
--


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Issue with interrupt handler on Atmel Mega 8 [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support