I'm trying to setup an interrupt to produce 125uS ticks.
I had the following code which doesn't work,
But, if I move the line OCR2A=249; down to just before the sei() line then it works perfectly.
It also works if I add the line OCR2A=249; to the ISR.
There must be a logical explanation for this but I can't work it out.
Any ideas anyone?
Mike.
I had the following code which doesn't work,
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t count;
ISR(TIMER2_COMPA_vect){
count++;
}
void setup(){
Serial.begin(115200);
cli(); //disable interrupts
OCR2A=249; //set period
TCCR2A = (1<<WGM21); //CTC mode
TCCR2B = (1<<CS21); //prescaler = 8
TIMSK2 = (1<<OCIE2A); //enable timer interrupts
sei(); //enable all interrupts
while(1){
Serial.println(count);
}
}
void loop(){
}
It also works if I add the line OCR2A=249; to the ISR.
There must be a logical explanation for this but I can't work it out.
Any ideas anyone?
Mike.