Using timer 0 on Olimexino85 (AtTiny85)

Started by BobMcNobby, June 12, 2014, 09:15:29 am

Previous topic - Next topic

BobMcNobby

Hi I have been trying to get a timer to fire a compare ISR on the Olimexino85
Similar code works on the UNO etc, but I cant seem to get it to run, I dont think the ISR is being accessed

Here is the code

/*
* OLIMEXINO tiny85_blink_by_timer_interrupt.ino
*/

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

void setup()
{
  // Disable global interrupts before initialization
  cli();
  //initialize the PortB Pin1 to output;
  DDRB |= (1<<PINB1);
  //initialize the timer0
  TCCR0A  = (1<<WGM01);      // Put timer0 in CTC mode and clear other bits
  TCCR0B  = (1<<CS02) ;      // Timer0 prescaling 256 and clearing other bits
  TIMSK  |= (1<<OCIE0A);     // enable timer1 compare interrupt
  //set the timer0 count
  OCR0A = 255; // Count 255 cycles before calling ISR interrupt
  PORTB |= (1<<PINB1); // Set PortB Pin1 high to turn on LED
  //initialize global interrupts before beginning loop
  sei();
}

void loop()
{
}

ISR(TIM0_COMPA_vect) {
  //toggle the PortB pin1 to HIGH or LOW
  PORTB ^= (1<<PINB1);

}

BobMcNobby

My bad, just realised the ISR was being triggered so fast I couldnt see it !!

I this line into the ISR

if (!count++) { PORTB ^= (1<<PINB1); }


works perfectly now

jrigbi234

Hi,

I'm trying same thing as you but the code doesnt work for me. How can I know that interrupt is generated correctly.

Here is my code.

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

void setup()
{
  DDRB |= 0x00; // Direction Register
  OCR0A = 0xFF;     // Match value for the counter to be compared against
  TCCR0A = 0x02;  // CTC Mode
  TCCR0B = 0x05;  // clock source / 1024, start timer
  //TIFR |= 0x01;   // Clear interrupt flag
  TIMSK |= (1<<OCIE0A);   // enable interrupt for compare A

  sei();
}
void loop()
{
 
}

ISR(TIM0_COMPA_vect)
{
  PORTB ^= 0x00;
}

Please help.

7eggert

Quote from: jrigbi234 on July 22, 2016, 08:40:43 pm

ISR(TIM0_COMPA_vect)
{
  PORTB ^= 0x00;
}


"PORTB ^= ..." will toggle every bit you set in "...". In 0x00, there is no bit set, therefore that instruction does nothing.