Arduino YUN interrupt

I tried using the function below on my Arduino YUN, Arduino IDE 1.5.8 and have compilation errors due to undeclared variables like TCCR2A etc. However, I have tried the same code on an Arduino UNO and it compiled successfully. May I know how to resolve this issue? Thanks :)

The code

void interruptSetup(){ // Initializes Timer2 to throw an interrupt every 2mS. TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED }

Error

Interrupt.ino:16:3: error: 'TCCR2A' was not declared in this scope Interrupt.ino:17:3: error: 'TCCR2B' was not declared in this scope Interrupt.ino:18:3: error: 'OCR2A' was not declared in this scope

Add:

#include <avr/interrupt.h>   

void setup() { 
...

“interrupt.h” at “C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr”

interrupt.h->io.h->iom32u4.h

“iom32u4.h” has them all.

sonnyyu:
Add:

#include <avr/interrupt.h>   

void setup() {




"interrupt.h" at "C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr"


interrupt.h->io.h->iom32u4.h

"iom32u4.h" has them all.

I have tried that but those variables are still undeclared. Apparently it managed to compile when my board setting in Arduino IDE is set to Arduino UNO, but when i switched it to Arduino Yun, the errors popped out. Any Idea?

OK, It might need ot switch to a different timer?

Change TCCR2A to TCCR4A
Change WGM21 to WGM41
Change WGM20 to WGM40
Change TCCR2B to TCCR4B
Change CS22 to CS42
Change CS21 to CS41
Change CS20 to CS40
Change TIMSK2 to TIMSK4
...

http://sourceforge.net/p/qpc/discussion/668726/thread/2378ff48/

Thanks alot i got it working! changed to Timer1 instead :)