SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;
PORTB_PCR0 = PORT_PCR_MUX(0x3)| PORT_PCR_DSE_MASK;; // FTM is alt3 function for this pin
SIM_SCGC6|=SIM_SCGC6_FTM1_MASK; //使能FTM1时钟
FTM1_C0SC |= FTM_CnSC_ELSB_MASK;
FTM1_C0SC &= ~FTM_CnSC_ELSA_MASK;
FTM1_C0SC |= FTM_CnSC_MSB_MASK;
FTM1_SC = FTM_SC_PS(6) | FTM_SC_CLKS(1);
FTM1_MODE &= ~3; //BIT0 FTM Enable
FTM1_OUTMASK &= ~3; //0 Channel output is not masked. It continues to operate normally.
FTM1_COMBINE=0; //Function for Linked Channels (FTMx_COMBINE)
FTM1_OUTINIT=0;
FTM1_EXTTRIG=0;
FTM1_POL=0;
FTM1_QDCTRL &=~FTM_QDCTRL_QUADEN_MASK;
FTM1_INVCTRL=0; //反转控制
FTM1_SWOCTRL=0; //软件输出控制F TM Software Output Control (FTMx_SWOCTRL)
FTM1_PWMLOAD=0; //FTM PWM Load
FTM1_CNTIN=0; //Counter Initial Value
FTM1_MOD=19531; //Modulo value,The EPWM period is determined by (MOD - CNTIN + 0x0001)
//采用龙丘时钟初始化函数,可以得到2分频的频率,系统60M频率时,PWM频率是30M,以此类推
//PMW频率=X系统频率/2/(2^FTM1_SC_PS)/FTM1_MOD=125000000/2/(2^6)/19531=50HZ
FTM1_C0V=1484; //设置 the pulse width(duty cycle) is determined by (CnV - CNTIN).
FTM1_C1V=1484;
FTM1_CNT=0; //只有低16位可用