I want to use one timer (FTM2 in my case) of a MKE02Z32VLC2 to set a flag after a specified time. In this case, just for testing, it's fixed at 10000 timer steps but in practice it will be variable.
The standard procedure, used thousand of times in other projects with many other processors, is replicated in this processor as follows:
FTM2_C0SC = FTM_CnSC_MSA_MASK; // MS = 0:1 (compare), ELS = 0:0, interrupt disabled
FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // System clock, prescaler 64
while (1)
{
// Output pin Toggle
FTM2_C0V = FTM2_CNT + 10000; // Set the compare value
FTM2_C0SC &= ~FTM_CnSC_CHF_MASK; // Reset of the event flag
do {} while ((FTM2_C0SC & FTM_CnSC_CHF_MASK) == 0); // Wait for the compare event
}
But in this case it doesn't work. I see the output toggling every timer rollover. It seems that FTM2_C0V is not set.
I know that FTM2_C0V is really updated only after the timer has advanced one step, but here it seems it's simply ignored.
By the way: the timer clock is much slower than the CPU clock.
I was unable to find any example on the 'net.
Any idea?