Hi Everyone,
I have trying to learn timer fundamentals of Arduino and I am currently working with the following code from
http://letsmakerobots.com/node/28278. My questions are:
-
what is the difference OCR1A and OCR1B? Why OCR1A is used here instead of OCR1B? And, why there are two of those registers which are apparently possess the same functionality? Is there an example where both of these are used?
-
Instead of asking this question here, some may advice that I change the code and use OCR1B and see myself what happens? But I am not sure how to analyze the result. Like is there a graphical tool where I can see time evolution plot of various register?
Thanks
Bu
/* Arduino 101: timer and interrupts
1: Timer1 compare match interrupt example
more infos: http://www.letmakerobots.com/node/28278
created by RobotFreak
*/
#define ledPin 13
void setup()
{
pinMode(ledPin, OUTPUT);
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 31250; // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
}
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
digitalWrite(ledPin, digitalRead(ledPin) ^ 1); // toggle LED pin
}
void loop()
{
// your program here...
}