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