Hi - I need to update ICR1 on the fly in my code. I have seen the warnings in the ATMEGA168 datasheet regarding this. That doesn't change the fact that I still need to do it, however!
I am using fast PWM mode, WGM1[3:0] = 1110. Thus ICR1 is my top. I cannot use OCR1A as my top as it is being used to generate a PWM signal (if I ever rev this board, I will move the PWM signal to OCR1B, but for now I'm stuck with OCR1A).
My timer is running with no divider and with a fixed value in OCR1A. I will never try to put a value less than or equal to OCR1A in ICR1.
My question is this - what's the best (and fastest) way to update ICR1?
I'm thinking something like this:
TIFR1 &= ~(1<<TOV1); //clear TOV1 while (~(TIFR1 & (1<<TOV1))) ; //wait for TCNT1 to hit ICR1 ICR1a = foo; //update ICR1
Anybody see any problems with this?