Hello Mayu,
Further to Kef's reply, leaving TPM1MOD register set to its default value, for free-running operation, will certainly simplify the coding. The only requirement is that the TPM overflow period be greater than the longest interrupt period. This would seem to be the case for a pre-scale division of 8. The following code might then apply for each ISR.
interrupt 7 void timer(void)
{
TPM1C2SC_CH2F = 0; // Clear flag
TPM1C2V += 2500; // Next output compare value 1ms
PTAD_PTAD0 = ~PTAD_PTAD0; //to verify
}
interrupt 8 void timer3(void)
{
TPM1C3SC_CH3F = 0; // Clear flag
TPM1C3V += 5000; // Next output compare value 2ms
PTAD_PTAD1 = ~PTAD_PTAD1;
}
You might also consider the initialisation of the TPM1C2V and TPM1C3V registers, so that the two interrupts never become concurrent, causing additional periodic latency. Perhaps the following initialisation code -
TPM1SC= 0x0B; // Preescaler 8
TPM1C2SC=0x50; // Interrupt only
TPM1C2V = TPM1CNT + 50;
TPM1C2SC=0x50; // Interrupt only
TPM1C3V = TPM1CNT + 1300;
Regards,
Mac