MsTimer2 and Atmega328P

Hi all, I’m hoping someone can help me w/ this one. I recently got a new Duemilanova, that came with the Atmega328 instead of the 168. I upgraded to Arduino-0014 as well.

Everything seems to be fine, except that I can’t get the MsTimer2 library to work. I attempted to change the following from:

#elif defined (__AVR_ATmega128__) 
      TIMSK &= ~(1<<TOIE2);
      TCCR2 &= ~((1<<WGM21) | (1<<WGM20));
      TIMSK &= ~(1<<OCIE2);
      
      if ((F_CPU >= 1000000UL) && (F_CPU <= 16000000UL)) {      // prescaler set to 64
            TCCR2 |= ((1<<CS21) | (1<<CS20));
            TCCR2 &= ~(1<<CS22);
            prescaler = 64.0;
      } else if (F_CPU < 1000000UL) {      // prescaler set to 8
            TCCR2 |= (1<<CS21);
            TCCR2 &= ~((1<<CS22) | (1<<CS20));
            prescaler = 8.0;
      } else { // F_CPU > 16Mhz, prescaler set to 256
            TCCR2 |= (1<<CS22);
            TCCR2 &= ~((1<<CS21) | (1<<CS20));
            prescaler = 256.0;

To:

  // addition here
#elif defined (__AVR_ATmega128__) || defined (__AVR_ATmega328P__) 
      TIMSK &= ~(1<<TOIE2);
      TCCR2 &= ~((1<<WGM21) | (1<<WGM20));
      TIMSK &= ~(1<<OCIE2);
      
      if ((F_CPU >= 1000000UL) && (F_CPU <= 16000000UL)) {      // prescaler set to 64
            TCCR2 |= ((1<<CS21) | (1<<CS20));
            TCCR2 &= ~(1<<CS22);
            prescaler = 64.0;
      } else if (F_CPU < 1000000UL) {      // prescaler set to 8
            TCCR2 |= (1<<CS21);
            TCCR2 &= ~((1<<CS22) | (1<<CS20));
            prescaler = 8.0;
      } else { // F_CPU > 16Mhz, prescaler set to 256
            TCCR2 |= (1<<CS22);
            TCCR2 &= ~((1<<CS21) | (1<<CS20));
            prescaler = 256.0;

However, that results in a compile error:

MsTimer2.cpp: In function 'void MsTimer2::set(long unsigned int, void (*)())':
MsTimer2.cpp:80: error: 'TIMSK' was not declared in this scope
MsTimer2.cpp:81: error: 'TCCR2' was not declared in this scope
MsTimer2.cpp:82: error: 'OCIE2' was not declared in this scope

Any ideas on what I need to do to upgrade this library to support the atmega368p?

Thanks!

!c

D'oh!

I saw my mistake right after posting this =)

The or was added to the incorrect line there (but on the correct line everywhere else!). It should've been on the one:

#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__)  || defined (__AVR_ATmega328P__)

!c

Hi

Lib has just been upgraded to work on 328P

Cheers