AnsweredAssumed Answered

How to synchronize two FTM modules?

Question asked by Andy Berger on Jul 19, 2018
Latest reply on Sep 17, 2018 by Andy Berger

I would like to synchronize two FTM modules (e.g. FTM0 and FTM1) on a K64, such that a CNT = CNTIN event on FTM1 also forces CNT = CNTIN on FTM0. Specifically, I have setup FTM1 as a free-running counter (MOD = 0xFFFF) and FTM0 with MOD = 0xFFF (i.e. FTM0 should rollover 16 times for every rollover of FTM1).


FTM1 is set to generate an external trigger whenever its counter is updated with CNTIN (which is set to 0), and FTM0 is set to receive this trigger, causing a PWM sync (pwmSyncMode = kFTM_HardwareTrigger_0). [see attached peripherals.c code, generated by MCUXpresso Config Tools]. I have also set up FTM0 hardware trigger source to be driven by the FTM1 hardware trigger [see attached pin_mux.c].


However, it does not appear that the rollover events are in-fact synchronized. In the attached FTM_Synchro.c code, I am generating a GPIO output toggle on each rollover (GPIOB_Pin9 toggles on FTM0 rollovers, and GPIOB_Pin10 toggles on FTM1 rollovers). By putting a variable delay between the FTM0 and FTM1 timer start events (i.e. adding or removing a printf statement between the FTM_StartTimer calls for the two timers), I can see that the synchronization is not working (specifically, I measure a 1 µs delay when the FTM_StartTimer events are back-to-back, and a 13 µs delay when the printf statement is inserted between the two calls).


Is there a more effective way to implement FTM synchronization?