interrupt not working on at90can

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

i'm trying to setup a timer of 10 msec using timer1.

i've tried everything, but the led will not go on or toggle.

what am i missing.

int void (main)

{

TCCR1A = 0x80;
TCCR1B = 0x0C;
OCR1AH = 0x9C;
OCR1AL = 0x3F;
TIMSK1 = (1<<OCIE1A);
// enable interrupts
sei();

while(1){

//main code which works!
}
}

interrupt routine

ISR (TIMER1_OVF_vect)
{
stap++;
uart_mini_printf ("-0- Interrupt reached ");
if(stap >50)
{
write_led_number (0,1); // statusled on 0,5 sec
}
if (stap >100){
write_led_number (0,0); // statusled off 0,5 sec
}
if (stap>150)stap=0;
}

i'm using avrstudio 6 and winavr.

and led works when used in main programm.

what am i doing wrong !

thanx in advance

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

You can start with this https://www.avrfreaks.net/index.p...

TCCR1A = 0x80;
TCCR1B = 0x0C;
OCR1AH = 0x9C;
OCR1AL = 0x3F;

using magic numbers makes following things confusing, use bit name as in

TIMSK1 = (1<<OCIE1A); 

This CLEARLY tells people that you have enable the output compare 1A interrupt, the other stuff tells us nothing.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I don't see your declaration for stap. I'm guessing it's defined globally and not defined as volatile. If it's a local variable to the ISR, it needs to be defined as static.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
TIMSK1 = (1<<OCIE1A);
             ^^^^
ISR (TIMER1_OVF_vect) 
            ^^^

Stefan Ernst

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

Stefan got it I think, you are enabling the output compare interrupt but using the wrong vector (the overflow vector)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

stupid of me, misread the datasheet!

thanks for your replays, i solved it.

this topic can be closed...

thanx again.