Question

I am writing a C code for atmega168a. I got attempt to use poisoned "SIG_OUTPUT_COMPARE0A and attempt to use poisoned "SIG_OUTPUT_COMPARE0B error when I compile the code below. But I see similar usage of ISR function on http://www.protostack.com/blog/2010/09/timer-interrupts-on-an-atmega168/ I would appreciate if someone could tell me what I am doing wrong? I am using atmel studio 6.0 and its gcc to compile the code on a windows 7 pc.

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


volatile int new_msg;
volatile int new_msg_available = 0;
volatile int message = 0xFFFF;
int main(void)
{
    DDRB = 0xFF;
    TIMSK0 = _BV(OCIE0A) | _BV(OCIE0B);  // Enable Interrupt TimerCounter0 Compare Match A & B   // #define OCIE0A  1... (1<<1);
    TCCR0A = _BV(WGM01);  // Mode = CTC ... #define WGM01   1 ... mode 2
    TCCR0B = _BV(CS01);   // Clock/8, 0.000008 seconds per tick
    OCR0A = 104;          // 0.000008*104 = 0.000832 SIG_OUTPUT_COMPARE0A will be triggered.
    OCR0B = 52;           // 416 usec

    message = 0xFFFE;

    volatile int i; 
    sei(); //interrupts are globally switched on


    while(1)
    {   
         if (OCR0A >= 104){
                for (i=0; i<18; i++) {
                    if (i <2){
                        PORTB = 0xFF;
                    }
                    else if ((i<15) && (message & 0x1)) {
                        PORTB = 0x00;
                    }
                    else if (i>15){
                        PORTB = 0xFF;
                    }
                    else{
                        PORTB = 0x00;
                    }
                    message >>= 1;
                }    
         }
    }
    return 0;
}


ISR(SIG_OUTPUT_COMPARE0A)
{
    if(new_msg_available == 1){
        message = new_msg;
        new_msg_available = 0;
    }else{
        message = 0xFFFF;
    }   
}

ISR(SIG_OUTPUT_COMPARE0B)
{
    PORTB ^= 0xFF;
}
Was it helpful?

Solution

Yu are using an out of date interrupt name.

See: avr-libc documentation, "Interrupt vector names"

The new name to use is ISR( TIMER0_COMPA_vect )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top