My application receives a 1ms trigger pulse every 33ms. The time between each trigger pulse is called a frame. When I receive a trigger I put out a certain number of PWM pulses before waiting for the trigger to indicate the next frame.
I use a mega325. The external interrupt (PORTD1) catches the rising edge of the trigger and Timer1 puts out the PWM pulses on OC1B (PORTB6).
The external interrupt starts Timer1 and counts number of frames, and disables itself when the desired number of frames is reached.
The Timer1 interrupt counts the pulses and stops the timer when done.
And now, the problem:
On the first run, after power up or a reset, when I send a start-command no pulses appear until the last frame. The only thing I can see that changes before the last frame is that the external interrupt is turned off (CLEARBIT(EIMSK,INT0)). After this first run everything behaves as expected.
I use gcc (WinAVR-20070525), and I have tried to run the application in AVR Studio. I have put breakpoints at different places, and it looks like the timer interrupt isn't flagged before the external interrupt is disabled. Since Timer1 is configured as Fast PWM with OCR1A as TOP I've tried both overflow and compare interrupt, but it makes no difference. Still same problem.