How to sync FTM modules on K60.

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

How to sync FTM modules on K60.

1,226 Views
boci
Contributor II

Hello,

Does anyone know how to sync FTM modules on K60??

I am trying to synchronize FTM0 and FTM1 modules on K60, but so far no success.

I have global time base enabled, but they are still not in sync.

I want to run FTM1 CH0 and CH1 in complementary mode and FTM0 CH0 in Edge-aligned PWM mode.

FTM0 CH0 can also run complimentary mode with CH1, I just would not use CH1.

The FTM1 CH0 and CH1 will run at half the frequency that FTM0 CH0 would run.

My current registry setup is below. First I setup FTM0 and than FTM1 modules.

I  attached video showing the FTM outputs with my current registry setup.

Yellow trace is FTM0 CH0 and blue and purple traces are FTM1 CH0 and CH1.

Can anyone help? Thank you.  Boci Nik

/*********************************

Enable FTM0

**********************************/

// Enable clocking

  SIM_SCGC6 |= SIM_SCGC6_FTM0_MASK;

  //disable write protect

  FTM0_MODE = FTM_MODE_WPDIS_MASK;

 

  //Enable FTM registers

  FTM0_MODE = FTM_MODE_FTMEN_MASK;

 

  //enable FTM in BDM mode

  FTM0_CONF = FTM_CONF_BDMMODE(3);

 

  FTM0_COMBINE = FTM_COMBINE_COMBINE0_MASK | FTM_COMBINE_SYNCEN0_MASK  |

                 FTM_COMBINE_DTEN0_MASK | FTM_COMBINE_COMP0_MASK;

 

  //Configure combine PWM

  FTM0_C0SC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

  FTM0_C1SC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

 

  //set sync to software

  FTM0_SYNCONF = FTM_SYNCONF_SYNCMODE_MASK |

                 FTM_SYNCONF_SWRSTCNT_MASK |

                 FTM_SYNCONF_SWWRBUF_MASK |

                 FTM_SYNCONF_SWOM_MASK |

                 FTM_SYNCONF_SWINVC_MASK |

                 FTM_SYNCONF_SWSOC_MASK |

                 FTM_SYNCONF_CNTINC_MASK;

 

  FTM0_CNTIN = FTM_CNTIN_INIT(1);

  FTM0_C0V = FTM_CnV_VAL(4001);

  FTM0_MOD = FTM_MOD_MOD(8001);

  // Enable global time base

  FTM0_CONF = FTM_CONF_GTBEOUT_MASK | FTM_CONF_GTBEEN_MASK;

  //set deadtime to 240nS

  //assume 50Mhz

  FTM0_DEADTIME =  FTM_DEADTIME_DTVAL(2) | FTM_DEADTIME_DTPS(3);

  //sync

  FTM0_SYNC = FTM_SYNC_REINIT_MASK | FTM_SYNC_SYNCHOM_MASK;

   // clock source - system clock, divide by 1

  FTM0_SC = FTM_SC_CLKS(1);

/*********************************

Enable FTM1

**********************************/

// Enable clocking

  SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;

  //disable write protect

  FTM1_MODE = FTM_MODE_WPDIS_MASK;

 

  //Enable FTM registers

  FTM1_MODE = FTM_MODE_FTMEN_MASK;

 

  //enable FTM in BDM mode

  FTM1_CONF = FTM_CONF_BDMMODE(3);

 

  //configure combine

  //enable sync

  //configure complimentary

  //enable dead time

  FTM1_COMBINE = FTM_COMBINE_COMBINE0_MASK | FTM_COMBINE_SYNCEN0_MASK  |

                 FTM_COMBINE_DTEN0_MASK | FTM_COMBINE_COMP0_MASK;

 

  //Configure combine PWM

  FTM1_C0SC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

  FTM1_C1SC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

 

  //set sync to software

  FTM1_SYNCONF = FTM_SYNCONF_CNTINC_MASK |

                 FTM_SYNCONF_INVC_MASK |

                 FTM_SYNCONF_SWOC_MASK |                 

                 FTM_SYNCONF_SYNCMODE_MASK |

                 FTM_SYNCONF_SWRSTCNT_MASK |

                 FTM_SYNCONF_SWWRBUF_MASK |

                 FTM_SYNCONF_SWOM_MASK |

                 FTM_SYNCONF_SWINVC_MASK |

                 FTM_SYNCONF_SWSOC_MASK |

                 FTM_SYNCONF_CNTINC_MASK;

 

  FTM1_CNTIN = FTM_CNTIN_INIT(1);

  FTM1_C0V = FTM_CnV_VAL(8001);

  FTM1_MOD = FTM_MOD_MOD(16001);

  //Enable global time base

  FTM1_CONF = FTM_CONF_GTBEEN_MASK;

 

  //set deadtime to 240nS

  //assume 50Mhz

  FTM1_DEADTIME =  FTM_DEADTIME_DTVAL(2) | FTM_DEADTIME_DTPS(3);

 

  //sync

  FTM1_SYNC = FTM_SYNC_REINIT_MASK | FTM_SYNC_SYNCHOM_MASK;

 

  // clock source - system clock, divide by 1

  FTM1_SC = FTM_SC_CLKS(1);

 

/*********************************

Initiate sync

**********************************/

  // reset timer

  FTM0_CNT = 1;

  // start sync

  FTM0_SYNC |= FTM_SYNC_SWSYNC_MASK;

  FTM1_SYNC |= FTM_SYNC_SWSYNC_MASK;

Labels (1)
Tags (1)
0 Kudos
3 Replies

663 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Boci,

If you want to synchronize two FTM modules for example FTM0 and FTM1, the two modules have to use the same clock source for example the BUS CLOCK, secondly, both FTM0 and FTM1 should have the same mode for example, both of them use either the edge-alignment mode or center-alignment mode, thirdly, both of them have to use the same Modulo value, in other words, the FTMx_MOD should have the same value.

"Synchronize" means that both FTM0 and FTM1 counters have the same value at any instant, the GBT signal can start both the FTM0/FTM1 counters so that they have the same value at any instant with the same tick source.

I attach an example based on K40 tower board, hope it can help you.

BR

XiangJun Rong

0 Kudos

663 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Pls use the new example based on K40, which can synchronize both FTM0 and FTM1 modules.

BR

XiangJun Rong

0 Kudos

663 Views
boci
Contributor II

Hello XiangJun,

I do not see anything attached.  Did you forget to attach the document?

Boci

0 Kudos