Help? CTC compare interrupt won't be visited by execution even if compare flag is set

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

#include <avr/io.h>

int main(void)
{
    
    TCCR1A=0b00000000;
    TCCR1B=0b00001010; //clock /8 and CTC with OCR1A as TOP     
    TIMSK =0b01000000; //compare interrupt enable
    
    OCR1A=62500; //62500*8 gives 500000 which translates to 0.5s when an 1MHz clock is used
    
    DDRB    = 0b00000001;
    PORTB    = 0b11111111; //blinking pin 0 at port B
    
    
    
    TCNT1=0; //timer initialazation
    
    while (1) 
    {

    }
}

 

ISR (TIMER1_COMPA_vect)
{
    PORTB    ^= 0x01; //ISR should be called every 0.5s

}

 

The compare match happens. The flag OCF1A is set but the interrupt is never executed. These are things I saw in the emulator.

I also tried a led at the PB0 but it won't blink. The chip is an ATtiny2313a. Help me I am lost :S

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

Last Edited: Fri. Dec 6, 2019 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

try adding "sei();" to enable cpu interrupts

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

Ok I guess I should hav used sei(); ... Now it works. I thought sei(); meant external interrupts so I didn't use it.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Yeah exactly -_- thank you so much.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Can I set the "I" bit in the  SREG register in stead of using sei(); ?? Is it the same?

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

it's the same

Last Edited: Fri. Dec 6, 2019 - 03:43 PM