You are calling "wait 3" inside your ISR (Interrupt Service Routine).
While processing an ISR the global interrupt is disabled. When the ISR takes longer as the timer overflow, the interrupt flag is set, but the ISR is not called (aka pending interrupt). After finishing the ISR the controller checks the interrupt flags and processes the pending interrupt, if nessesary.
If the interrupt would not be disabled the HW stack would overflow very easy.
It is a wise practice to keep the processing time of an ISR shorter than a new interrupt can occur.
↧