Hi,
I'm plannig to use timer2 interrupt to increase a counter, but it seems I am doing something wrong because if the marked code
/* next line is the important one */
Serial.print(".""\n"); /* <--- <--- <--- <--- <--- <--- <--- */
/* past line is the important one */
is deleted the interrupt is not working, also if the "." is removed or replaced for " " the interruption does not work.
Hope you can help me :]
unsigned long Position;
byte Clkout;
void setup() {
Clkout = 9;
pinMode (Clkout, OUTPUT);
Serial.begin(19200);
noInterrupts();
///------------------------------------
/*Timer2 Configuration for interrupt at 400Hz in order to generate pulse for correct*/
TCCR2A = 0; //Clear TCCR2A
TCCR2B = 0; //clear TCCR2B
TCNT2 = 0; //initialize counter value to 0
OCR2A = 249; // = (16*10^6) / (400*255) - 1 (must be <256)
TCCR2A |= (1 << WGM21); // Set CTC mode in timer2TCCR2B |= (1 << CS21);
TCCR2B |= (1 << CS22);
TIMSK2 = 0; //Timer2 interrupts disabled
}
///------------------------------------
/*Timer 2 interrupt*/
ISR(TIMER2_COMPA_vect){
TIMSK2 = 0; //stop timer /timer2 interrupt disabled
TCNT2 = 0; //initialize counter value to 0
Position += 1;
Serial.print(Position);
Serial.print("\n");
digitalWrite(Clkout, !digitalRead(Clkout));
}
///------------------------------------
void loop() {
/* next line is the important one */
Serial.print(".""\n"); /* <--- <--- <--- <--- <--- <--- <--- */
/* past line is the important one */
interrupts();
//Serial.print("\n");
TCNT2 = 0; //initialize counter value to 0
TIMSK2 |= (1 << OCIE2A); // enable timer compare interrupt
}
Thanks!