SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By Clusto
#53092
Hi guys,
I'm having an interrupt problem with the Olimex AVR-USB-162 Dev board. When I try to use a compare A match interrupt it never fires the interrupt.

It will never go into: ISR(TIMER1_COMPA_vect)

But it does when I simulate it. When I plug it into the circuit it just sits there and shows the time. It won't update the time in any way. Any ideas? What would you try to solve this problem? thanks.

Here's my code:


#include <avr/io.h>
//#include <stdio.h>
#include <avr/interrupt.h>


//void update_display();

volatile int first_sec = 0x03;
volatile int second_sec= 0x02;

volatile int first_hr = 0x08;
volatile int second_hr= 0x01;

volatile int first_min= 0x04;
volatile int second_min= 0x01;

volatile int alarm_first_min = 0x03;
volatile int alarm_second_min = 0x01;

volatile int alarm_first_hr = 0x09;
volatile int alarm_second_hr = 0x01;

volatile int ampm = 0;
volatile int in = 0;
volatile int time_type = 0;
//volatile int round_two = 0;
volatile int input = 0;
volatile int alarm_on = 0;


int main (void)
{
DDRB = 0xFF; // Set LED as output
DDRC = 0xFF;
DDRD = 0xFF;

SREG= 0x82;
TCCR1B=0x0B;
OCR1A=0x7A11;
TIMSK1 = (1<<OCIE1A);//(1<<OCIE1C) | (1<< OCIE1B) | (1<<OCIE1A);
//sei();

while(1)
{
PORTB = ((second_sec*16) + first_sec);
PORTD = ((second_min*16) + first_min);
PORTC = (second_hr + (first_hr*16));
}
}

ISR(TIMER1_COMPA_vect)
{
first_sec = first_sec + 0x01;
if (first_sec > 9)
{
first_sec = 0x00;
second_sec = second_sec + 0x01;
};

if (second_sec > 5)
{
second_sec = 0x00;
first_min = first_min + 0x01;
};
if(first_min >9)
{
first_min = 0x00;
second_min = second_min + 0x01;
};
if(second_min >5)
{
second_min = 0x00;
first_hr = first_hr + 0x01;
};

if(first_hr > 9)
{
first_hr = 0x00;
second_hr = second_hr + 0x01;
};

if ((second_hr == 2) && (first_hr > 3))
{
second_hr = 0x00;
first_hr = 0x00;
first_min = 0x00;
second_hr = 0x00;
first_sec = 0x00;
second_sec = 0x00;
};
}