How to synchronize two FTM modules?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to synchronize two FTM modules?

1,107 Views
aberger
Contributor V

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?

Labels (1)
2 Replies

797 Views
aberger
Contributor V

I found the most effective way to synchronize two FTM modules whose moduli are related by an integer multiple is to use the Global Time Base.

For example to synchronize FTM0 (MOD = 4095) and FTM3 (MOD = 65535, free-running):

1. Initialize the FTM counters you wish to synchronize

FTM_Init(FTM_0_PERIPHERAL, &FTM_0_config);

FTM_Init(FTM_3_PERIPHERAL, &FTM_3_config);

where the config struct for both FTM0 and FTM3 includes the following:

const ftm_config_t FTM_0_config = {
// make sure to set the config option:
.useGlobalTimeBase = true
}; 

2. enable the clock source for both modules

FTM_StartTimer(FTM_0_PERIPHERAL, kFTM_SystemClock);

FTM_StartTimer(FTM_0_PERIPHERAL, kFTM_SystemClock);

(note: this doesn't actually start the FTM counters, it just sets them in a "ready" state to await the Global Time Base start trigger).

3. set the Global Time Base output

FTM_SetGlobalTimeBaseOutputEnable(FTM_0_PERIPHERAL, true);

I found that only FTM0 can serve as the master GTB out source (I am using a K64).

797 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

I think your path is ok. I found there is another similar question in community. It could give you some help.

https://community.nxp.com/message/854291?commentID=854291#comment-854291 

And there is an application note AN4560 which should also helpful.

https://www.nxp.com/docs/en/application-note/AN4560.pdf

Regards,

Jing

0 Kudos