It is clear now.
Timer is always ticking. I guess System Input Conditions gets true not every timer overflow period? But timer output compare match occurs every timer period. Now, since you update compare registers in main after clearing flag and enabling interrupt, chances are older output compare match setting will match CNT anytime between marked lines:
Main:
if((System Input Conditions) && (InterruptStatus == DISABLED))
{
Switch ON the Port Pin;
TPM2CH1IF = 0;
/* Enable the Compare Interrupt */
TPM2CH1IE = 1;
/* Flag holding the status of Timer Interrupt */
InterruptStatus = ENABLED;
TPM1C1V = TPM1CNT + One Ms Equivalent Count;
}
You get desired results in case older compare match doesn't occur before or during red line, before C1V gets updated. To fix it, update C1V before clearing timer flag
Main:
if((System Input Conditions) && (InterruptStatus == DISABLED))
{
Switch ON the Port Pin;
TPM1C1V = TPM1CNT + One Ms Equivalent Count;
TPM2CH1IF = 0;
/* Enable the Compare Interrupt */
TPM2CH1IE = 1;
/* Flag holding the status of Timer Interrupt */
InterruptStatus = ENABLED;
}
Also I'd move InterruptStatus = ENABLED; above CH1IE=1. It won't change anything while +1ms is enough to execute code from C1V update to Interrupts = ENABLED. But if you decide later to shorten that drastically, you will be guaranteed ISR always sees InterruptStatus == ENABLED.
Message Edited by kef on 2009-11-21 01:17 PM