For an application, I need regular timer interrupts. I thought I'd set the timer in "CTC" mode, (WGMx[3:0] = 0x04 or 0x0c), and catch the overflow interrupts.
Or don't overflows happen if the timer is in CTC mode?
To get things to work I enabled the OCR1B comparator and made it compare to the constant "20" so everytime the timer crosses the value 20, I now get a TIMER1_COMPB interrupt.
Here is my initialization code:
OCR1A = 1000-1; // reload counter/interrupt at 16000 Hz. TCCR1A = 0; TCCR1B = (1 << CS10) | (1 << WGM12); // Mode 4 CTC. //TCCR1B = (1 << CS10); // Mode 4 CTC. TCCR1C = 0; OCR1B = 20; //TIMSK1 = _BV (TOIE1); TIMSK1 = _BV (OCIE1B); EICRA = 0; EIMSK = 0; pwm_on = 0; sei ();
So with the TIMSK1 = TOIE1 I would've expected to receive TIMER1_OVF_vect interrupts, but those don't happen, and with the now uncommented TIMSK1 = .. OCIE1B I do get the compare B interrupts. It currently works this way, with an interrrupt every 1000 cycles, but I'd like to know why the original thought won't work.
(I've programmed microprocessors a lot 10 and 20 years ago, and I always had trouble with interrupts. Back then (8051, PIC and Intel '960) I always forgot to set some bit before interrupts would work. But with AVR I usually manage to correctly get interrupts on the first try. Great architecture AVR!).