Dear All,
This is the code which makes use of serial line and timer. I am using Arduino UNO board. In this, the setup routine gets called again and again. How to solve this?
Regards
S Srinivasan
THE CODE:
volatile boolean triggered;
ISR(Timer1_COMPA_vect) {
// Your commands here
triggered = true;
}
void setup() {
Serial.begin (9600);
Serial.println ("Started.");
cli(); // disable interrupt
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0; // initialize the counter from 0
OCR1A = 7811; // sets the counter compare value
TCCR1B |= (1<<WGM12); // enable the CTC mode
TCCR1B |= (1<<CS12)|(1<<CS10); //sets the control scale bits for the timer
TIMSK1 |= (1<<OCIE1A); //enable the interrupt
sei(); //allows interrupts
}
void loop ()
{
static int i=0;
static int j=0;
i=i+1;
if (triggered)
{
Serial.println ("Triggered!");
triggered = false;
}
if(i>1000)
{
i=0;
j=j+1;
if(j>100)
{
Serial.println("Clock");
Serial.print(i);
Serial.print(triggered);
j=0;
}
}
} // end of loop