I am using an Attiny13A and I can not get the timer overflow interrupt to work properly.
This is a small version of the full version of the code (quite large) but reproduces the problem.
#define F_CPU 128000
#include <avr/io.h>
#include <util/delay.h>
volatile unsigned long x=0;
SIGNAL(TIMER0_OVF_vect){x=1;} //Set x to 1
int main(){
TCCR0B |= _BV(CS01); //Prescaler to F_CPU/8
TCCR0A |= _BV(WGM00)| _BV(WGM01);
TIMSK0 = _BV(TOIE0); //Enable timer overflow interrupt
DDRB = 0x18; //PB3 and PB4
asm("sei"); //Enable interrupts
while(1){
PORTB ^= 0x8; //Invert vale on PB3
if(x){PORTB |= 0x10;} //Turn on PB4 after the interrupt
_delay_ms(500); //Blink delay
}
}
Expected behavior is that PB3 would blink and PB4 would light. Actual behavior is PB3 would flicker at about 20 times per second and PB4 does not light.
But if I change it to:
#define F_CPU 128000
#include <avr/io.h>
#include <util/delay.h>
volatile unsigned long x=0;
SIGNAL(TIMER0_OVF_vect){x=1;} //Set x to 1
int main(){
TCCR0B |= _BV(CS01); //Prescaler to F_CPU/8
TCCR0A |= _BV(WGM00)| _BV(WGM01);
TIMSK0 = _BV(TOIE0); //Enable timer overflow interrupt
DDRB = 0x18; //PB3 and PB4
while(1){
PORTB ^= 0x8; //Invert vale on PB3
if(x){PORTB |= 0x10;} //Turn on PB4 after the interrupt
_delay_ms(500); //Blink delay
asm("sei"); //Enable interrupts *moved*
}
}
Again I expect the same behavior as before but now PB3 actually blinks at the correct rate but PB4 still does not light.
I have been Googling for hours and can not find a solution.
It seems to match the examples as well.