Problems in MsTimer2

Hello!

I’m a beginner in Arduino platform.
I would like make timer interrupt. So I found this lib: MsTimer2 http://www.arduino.cc/playground/Main/MsTimer2

But it doesn’t work. The led connected on pin 13 doesn’t blink.

Can you help me??

My processor is a ATmega8-16pu (28 pins) in a Arduino board.

Follow my code:

#include <MsTimer2.h>

void setup() {
pinMode(13, OUTPUT);
MsTimer2::set(200, flash); // 500ms period
MsTimer2::start();
Serial.begin(9600);
}

void loop() {
delay(1000);
Serial.print(“12345”);
}

void flash() {
static boolean output = HIGH;
digitalWrite(13, output);
output = !output;
}

Thanks

Best regards!

The mega8 only has timers 0 and 1. It does not have a timer 2, so MsTimer2 won't work.

  • Ben

So why there’s mega8 reference code? :-?

#elif defined (AVR_ATmega8)
TIMSK &= ~(1<<TOIE2);
TCCR2 &= ~((1<<WGM21) | (1<<WGM20));
TIMSK &= ~(1<<OCIE2);
ASSR &= ~(1<<AS2);

Ben, check mega8 datasheet. It has timer2. Take a look at page 104.

Lib now working. I've told Javier (who wrote the lib) what was missing. I think he will post corrected files soon.

Best regards

Oops, sorry, my mistake. I knew that the mega8 was missing timer2 PWM outputs and I assumed that was because it lacked a third hardware timer. Apparently there is a timer 2 and it has a single PWM output (unlike timers 0 and 1, which each have two PWM outputs).

  • Ben

Ppppfff... MsTimer2 with ATmega8 resolved by me, but no credits...