Interrupt does not work when i set up PWM on the same timer

Hello guys . my application requires me to use TIMER1 on the arduino UNO for both waveform generation and interrupt handling . but weirdly enough , the interrupt does not work when i set the PWM with ICR1 as top .

so the following code does not work :

					  TCCR1A |= (1<<WGM11)|(COM1A1);             //
					  TCCR1B |= (1<<CS12)|(1<<WGM12)|(1<<WGM13); //256 prescaler , Fast PWM with ICR1 as top
					  TIMSK1 |= (1<<OCIE1B);
					  ICR1    = 200;                             //calibration might be required here
					  OCR1A   = 20;
					  OCR1B   = 50;

					  TCNT1L = 0;
					  TCNT1H = 0;

but when i replace the parameters to the following , where the top is 0x00FF , everything seems to work well . both the interrupt and PWM work . but i need ICR1 as top ! and i can't imagine why the interrupt doesn't work in the first bit of code .

					  TCCR1A |= (1<<WGM10)|(COM1A1);             //
					  TCCR1B |= (1<<CS12)|(1<<WGM12); //256 prescaler , Fast PWM with ICR1 as top
					  TIMSK1 |= (1<<OCIE1B);
					  ICR1    = 200;                             //calibration might be required here
					  OCR1A   = 20;
					  OCR1B   = 50;

					  TCNT1L = 0;
					  TCNT1H = 0;

The Arduino ide sets up the timers with default values for the standard pwm/analogWrite() and you need to clear out the default settings from TCCR1A and TCCR1B before setting up your conditions.

TCCR1A = 0;
TCCR1B = 0

In your first case, I think you are actually in fast pwm to OCR1A (because WGM10 is set by default)and not fast pwm to ICR1.

cattledog:
The Arduino ide sets up the timers with default values for the standard pwm/analogWrite() and you need to clear out the default settings from TCCR1A and TCCR1B before setting up your conditions.

TCCR1A = 0;

TCCR1B = 0




In your first case, I think you are actually in fast pwm to OCR1A (because WGM10 is set by default)and not fast pwm to ICR1.

thank you cattledog for your attention and response , even after setting the values to 0 i still have the same problem . you see , in both cases the PWM works well , my problem is that the Interrupts don't work when i set ICR1 as top .

TCCR1A |= (1<<WGM11)|(COM1A1);

I'm not certain what/why this syntax is doing(it appears to be setting WGM11 and WGM10 for some reason) but its not correct. Use this

TCCR1A |= (1<<WGM11)|(1<<COM1A1);

I'm seeing the OCR1B interrupt working with this change.

cattledog:

TCCR1A |= (1<<WGM11)|(COM1A1);

I'm not certain what/why this syntax is doing(it appears to be setting WGM11 and WGM10 for some reason) but its not correct. Use this

TCCR1A |= (1<<WGM11)|(1<<COM1A1);

I'm seeing the OCR1B interrupt working with this change.

oh my god i am so sorry i am such a goof . i just didn't notice that error .
thank you very much sir for paying attention to that .
thank you very much for your help , i have been pulling my hair out this entire day and for some reason that just escaped my eye

thank you sir , thank you .