Atmega644 and Timer0 CTC, overflow interrupt not working?

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

It's getting late and I have probably done something wrong but I can't seem to figure out exactly what at the moment... :(

I have this code that should start the Timer0 in CTC mode and I guess it should run and go to interrupt?

ISR(TIMER0_OVF_vect)
{
	TLC59116_SetSingle(ARRAY0,14,0xFF);
}

and

OCR0A = 63;	//Clear timer when it reaches this value
TCCR0A &= (1<<WGM01);//Timer 0 Clear-Timer on Compare (CTC)
TCCR0B &= (1<<CS02);//Timer 0 prescaler = 256
TIMSK0 &= (1<<TOIE0);//Enable overflow interrupt for Timer0
						//Timer should clear ~10 times per second
		
sei();							//Enable global interrupts

I have tested the TLC function elsewhere so i KNOW it works, the mega never goes in to the interrupt it seems! Any help is appreciated!

I'm using atmel studio 6 btw

- Brian

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

Geronimo wrote:
I have this code that should start the Timer0 in CTC mode and I guess it should run and go to interrupt?
No, not unless you change &= into |= and you use the correct interrupt.

Stefan Ernst

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

Your timer will never be overflowed because it's cleared at CTC event. So you have to use appropriate interrupt (on compare, if I remember correctly).

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

Thank you both! Of course it should have been | not &! I also changed the interrupt so now it works, thank you very much!

Here is the fixed code just for good measure:

ISR(TIMER0_COMPA_vect)
{
	TLC59116_SetSingle(ARRAY0,14,0xFF);
}

and

OCR0A = 63;	//Clear timer when it reaches this value
TCCR0A |= (1<<WGM01);//Timer 0 Clear-Timer on Compare (CTC)
TCCR0B |= (1<<CS02);//Timer 0 prescaler = 256
TIMSK0 |= (1<<OCIE0A);//Enable overflow interrupt for Timer0
						//Timer should clear ~10 times per second
		
sei();							//Enable global interrupts

- Brian