iqbal0001 / arduino-tiny

Automatically exported from code.google.com/p/arduino-tiny
Other
0 stars 0 forks source link

Interrupts on timer overflows don't work on TIny84 #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am not able to use an interrupt based on a timer overflow on Attiny 84.

This code doesn't work:

int counterT=0;
int starterT=0;
byte state=1;
#define LED 0

void setupTimer() {
    float prescaler;

    //during setup, disable all the interrupts based on timer 0
    TIMSK0 &= ~(1<<TOIE0);
    TIMSK0 &= ~((1<<OCIE0A) | (1<<OCIE0B));
    //normal mode: increment counter until overflow
    TCCR0B &= ~(1<<WGM02);
    TCCR0A &= ~((1<<WGM01) | (1<<WGM00));
    //normal mode: no pwm generation
    TCCR0A &= ~((1<<COM0A0) | (1<<COM0A1));
    TCCR0A &= ~((1<<COM0B0) | (1<<COM0B1));
    //sets the prescaler depending on the system clock
    if ((F_CPU == 16000000UL) || (F_CPU == 8000000UL)) {   
        TCCR0B &= ~(1<<CS02);
        TCCR0B |= ((1<<CS01) | (1<<CS00));
        prescaler = 64.0;
    } else if (F_CPU == 1000000UL) { 
    TCCR0B &= ~((1<<CS02) | (1<<CS00));
    TCCR0B |= (1<<CS01);
    prescaler = 8.0;
    }
    starterT = 256 - (int)((float)F_CPU * 0.001 / prescaler);
    TCNT0 = starterT;
    TIMSK0 |= (1<<TOIE0);
}

ISR(TIMER0_OVF_vect) {
    TCNT0 = starterT;
    counterT++;
    if (counterT>999) { 
        state ^=1; 
        counterT=0;
        digitalWrite(LED, state);
    }
}

void setup() {
    pinMode(LED, OUTPUT);
    digitalWrite(LED, state);
    setupTimer();
}

void loop() {
}

Led lights up forever.

Original issue reported on code.google.com by leomi...@gmail.com on 29 Sep 2011 at 11:12

GoogleCodeExporter commented 8 years ago

Change this...

ISR(TIMER0_OVF_vect) {

...to this...

ISR(TIM0_OVF_vect) {

Original comment by arduino....@gmail.com on 30 Sep 2011 at 5:19