AnsweredAssumed Answered

How to sync FTM modules on K60.

Question asked by Boci Nik on Nov 21, 2014
Latest reply on Dec 5, 2014 by xiangjun.rong

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;

Attachments

Outcomes