Most AVR microcontrollers got three dedicated pins for each timer (for example, OC1A, OC1B, and OC1C) that can be toggled automatically when the counter reaches the so called top value in the corresponding three registers (OCR1A, OCR1B, and OCR1C).
I'm not sure how can those three dedicated pins/registers operate in CTC mode for different independent top values, and this is what I want to accomplish. I want to toggle OC1A, OC1B and OC1C (though "output compare", not through interrupt or something like that) at different intervals (to see the having three dedicated registers and pins).
Let's say I want to program the AVR timer to toggle the pins OC1A, OC1B and OC1C at different intervals (for example 1 second, half second, quarter a second), but it does not work as I expect. I set compare match register A and B and C with the three different value, having the greatest value on A (I also tried having it on C).
Only OC1A is toggled at the needed frequency.
To me it seems that if they made only OC1A top clears the counter then it would be possible to have the three pins work at different three independent values. Is this right?
// Initialize timer1 noInterrupts(); // Disable all interrupts TCCR1A = 0; TCCR1B = 0; TCCR1C = 0; TCNT1 = 0; OCR1A = 62500; // Compare match register 16 MHz/256/1 Hz OCR1B = 31250; // Compare match register 16 MHz/256/2 Hz OCR1C = 15625; // compare match register 16 MHz/256/4 Hz // Toggle OC1A, OC1B and OC1C => (on Lenoardo) PB5, PB6 and PB7 => digital 9, 10, 11 // TCCR1A = 0b01010100; TCCR1A |= (1 << COM1C0) | (1 << COM1B0) | (1 << COM1A0); // TCCR1B = 0b1100 TCCR1B |= (1 << WGM12); // CTC mode TCCR1B |= (1 << CS12); // 256 prescaler interrupts(); // Enable all interrupts