[SOLVED] Why Timer1 Interrupt is not firing ?

Status
Not open for further replies.

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,524
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Visit site
Activity points
0
Why Timer1 Interrupt is not firing ? It has to fire every 160 ms.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define F_CPU 8000000UL
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
 
unsigned char mask[] = {0xFE, 0xFD, 0XFB, 0XF7, 0XEF, 0XDF, 0XBF};  //segments a , b, c, d, e, f, g
unsigned char step = 0;
 
//Timer1 Prescaler = 64; Preload = 20000; Actual Interrupt Time = 160 ms
//Place/Copy this part in declaration section
void InitTimer1() {
    SREG |= 0x80;
    OCR1AH = 0x4E;
    OCR1AL = 0x20;
    TCCR1A = 0x80;
    TCCR1B |= 0x0B;
    TIMSK |= 0xC0;
}
 
// TIMER1 overflow interrupt service routine
// called whenever TCNT1 overflows
ISR(TIMER1_OVF_vect)
{
    PORTD = 0x60;
    PORTB = mask[step++];       //Assign mask values to turn on each segment of 1st SSD one by one
    PORTD = 0x20;
    
    if(step == 7)step = 0;      //If last segment displayed was g then reset lookup table index to 0 so that segment a is displayed on next interrupt   
}
 
int main(void)
{
    DDRA = 0x00;
    PORTA = 0x00;
    DDRB = 0xFF;
    PORTB = 0xFF;
    DDRD = 0xFF;
    PORTD = 0x20;               //Turn ON SSD1 connected to PD6 and turn OFF SSD2 connected to PD5
    
    InitTimer1();
    
    sei();                      // enable global interrupts
    
    while(1)
    {
        
    }
}




Worked. ISR vector was wrong.


Code C - [expand]
1
ISR(TIMER1_COMPA_vect)

 
Last edited:

Looks like you are enabling OCIE1B interrupt without a related interrupt routine. First step would be to check that the main loop is actually continuously executing.
 
I don't have much experience with AVR. I mainly use PIC. I generated the InitTimer1() code using mikroe Timer Calculator. This is the code it generated. It was using Timer1_COMPA_vect. If I use COMPB_vect then ISR doesn't fire.

This is for ATtiny2313A. I need to interrupt every 160 ms. I need to turn ON segments a, b, c, d, e, f, g of Units Digit SSD on every interrupt. I am attaching Proteus 8.1 file and Atmel Studio files. The segment d will be always ON. I don't know why.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Timer1 Prescaler = 64; Preload = 20000; Actual Interrupt Time = 160 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  SREG_I_bit = 1; 
  OCR1AH = 0x4E; 
  OCR1AL = 0x20;
  TCCR1A = 0x80;
  TCCR1B |= 0x0B; 
  OCIE1A_bit = 1; 
}
 
void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {
  //Enter your code here 
}

 

Attachments

  • ATTiny2313A SSD.rar
    71.3 KB · Views: 45

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…