你好!
我需要将FTM0和FTM2同步,使用软件触发始终不成功,不知啥原因?代码如下:
// FTM2 配置
SIM->PINSEL &= ~SIM_PINSEL_FTM2PS2_MASK; // 0 T22--PTC2 PWT_IN0
//SIM->PINSEL |= SIM_PINSEL_FTM2PS2_MASK; // 1 T22--PTC4 PWT_IN0
//SIM->PINSEL |= SIM_PINSEL_FTM2PS3_MASK; //T23--PTC5
SIM->PINSEL &= ~SIM_PINSEL_FTM2PS3_MASK; //T23--PTC3
SIM->SCGC |= SIM_SCGC_FTM2_MASK;
FTM2->SC = 0x0; // CLKS为0,关计数器
//FTM2->CONF |=0xC0; //DBM 11
FTM2->MOD = 959; //50KHz 20*48-1
FTM2->CNTIN=0;
//FTM2->DEADTIME |= 0xF;
FTM2->SC &= ~FTM_SC_CPWMS_MASK; //向上或中心对齐模式选择 ,选向上模式
FTM2->MODE |= 0x5; // FTM使能
FTM2->COMBINE |= 0x232323; // 全部通道组合互补
FTM2->CONTROLS[0].CnSC |= 0x8; // H真脉冲
FTM2->CONTROLS[1].CnSC |= 0x8;
FTM2->CONTROLS[2].CnSC |= 0x8;
FTM2->CONTROLS[3].CnSC |= 0x8;
FTM2->CONTROLS[4].CnSC |= 0x8;
FTM2->CONTROLS[5].CnSC |= 0x8;
FTM2->CONTROLS[0].CnV = 300;
FTM2->CONTROLS[1].CnV = 600;
FTM2->CONTROLS[2].CnV = 300;
FTM2->CONTROLS[3].CnV = 600;
FTM2->CONTROLS[4].CnV = 0;
FTM2->CONTROLS[5].CnV = 500;
FTM2->CNT=0;
FTM2->SC |= 0x8; //系统时钟,直通
FTM2->SYNCONF |= 0x380; //软件触发
FTM2->SYNC |= 0x4;
void FTM0_Isr(void)
{
FTM2->CONTROLS[4].CnV = 0;
FTM2->CONTROLS[5].CnV = 300;
FTM2->PWMLOAD |=0x200; //使能更新值加载
FTM2->SYNC |= 0x80; //软件触发同步
}
FTM0是计数器为0时发生中断,在中断程序中软件触发FTM2计数器回0,但无法实现.
同样的问题,在帖子PWM Synchronization Using Kinetis Flextimers讨论吧