Porting from Zumo Arduino Uno to 32U4

I have some code that is working well on my Zumo Arduino Shield using an Uno. I want to port it to my Zumo 32U4. Basically, I need to have a timer that I can control that can be set to trigger an interrupt in the 100-200Hz range. On the Zumo Arduino shield, I have decided not to use the buzzer so that I can use Timer2 for this purpose. This code is in my setup function and causes the timer interrupt to trigger at a 100Hz rate:

void setup() { //======================================================= // set up the Timer2 interrupt to trigger at 100Hz //======================================================= cli(); // disable global interrupts //OCR0A = 124; TCCR2A = 0;// set entire TCCR2A register to 0 TCCR2B = 0;// same for TCCR2B TCNT2 = 0;//initialize counter value to 0 // set compare match register for 8khz increments OCR2A = 250;// = (16*10^6) / (8000*8) - 1 (must be <256) // turn on CTC mode TCCR2A |= (1 << WGM21); // Set CS21 bit for 8 prescaler // TCCR2B |= (1 << CS21); bitSet(TCCR2B, CS22); bitSet(TCCR2B, CS21); bitSet(TCCR2B, CS20); //!//bitClear(TCCR2B, CS20); // enable timer compare interrupt TIMSK2 |= (1 << OCIE2A); sei();// re-enable global interrupts //=======================================================

The 32U4 is balking at TCCR2A. Does the 32U4 have multiple timers? Does the Zumo 32U4 have an unused timer or can I easily free one up by not using the buzzer or something? And if so, how can I set up a timer interrupt at around 100 Hz?

Googling for 32u4 timers didn’t produce anything immediately helpful.

Thanks,

Ryan

Hello, Ryan.

You should look at the Zumo 32U4 Robot User’s Guide “AVR Timers” section. That section specifies the number of timers the ATmega 32U4 has and lists what each timer is used for. Once you decided what timer you are going to use, you probably will need to modify your code to use the appropriate names for the registers associated with that timer, which you can find in the ATmega32U4 datasheet.

By the way, we added code tags ([ code ] [ /code ] without spaces) to your post to make it easier to read; please use this method to post code in the future.

- Amanda