|
本帖最后由 FSL_TICS_ZJJ 于 2014-1-26 13:57 编辑
在看定时器FTM2的时候,完全搞不懂FTM2在COMBINE模式下是如何输出互补PWM的,下面的这个初始化函数也有搞不明白的地方:
void FTM_PWMInit(FTM_Type *pFTM, uint8_t u8PWMModeSelect, uint8_t u8PWMEdgeSelect)
{
uint8_t channels, i;
ASSERT((FTM0== pFTM) || (FTM1== pFTM) || (FTM2== pFTM));
/* open the clock gate */
if (FTM0 == pFTM)
{
channels = 2;
SIM->SCGC |= SIM_SCGC_FTM0_MASK;
}
else if(FTM1 == pFTM)
{
channels = 2;
SIM->SCGC |= SIM_SCGC_FTM1_MASK;
}
else
{
channels = 6;
SIM->SCGC |= SIM_SCGC_FTM2_MASK;
}
pFTM->SC = 0x0; /* disable counter */
pFTM->MOD = FTM_MOD_INIT;
if(FTM_PWMMODE_CENTERALLIGNED == u8PWMModeSelect) /* enable CPWM */
{
pFTM->SC |= FTM_SC_CPWMS_MASK;
}
else if(FTM_PWMMODE_COMBINE == u8PWMModeSelect) /* enable combine pwm mode */
{
ASSERT(FTM2 == pFTM);
pFTM->MODE |= FTM_MODE_WPDIS_MASK | FTM_MODE_FTMEN_MASK;
pFTM->COMBINE = FTM_COMBINE_FAULTEN0_MASK |
FTM_COMBINE_COMBINE0_MASK | FTM_COMBINE_COMP0_MASK | FTM_COMBINE_SYNCEN0_MASK | FTM_COMBINE_DTEN0_MASK |
FTM_COMBINE_FAULTEN1_MASK |
FTM_COMBINE_COMBINE1_MASK | FTM_COMBINE_COMP1_MASK | FTM_COMBINE_SYNCEN1_MASK | FTM_COMBINE_DTEN1_MASK |
FTM_COMBINE_FAULTEN2_MASK |
FTM_COMBINE_COMBINE2_MASK | FTM_COMBINE_COMP2_MASK | FTM_COMBINE_SYNCEN2_MASK | FTM_COMBINE_DTEN2_MASK
;
pFTM->SC &= ~FTM_SC_CPWMS_MASK;
}
if(FTM_PWM_HIGHTRUEPULSE == u8PWMEdgeSelect)
{
/* Configure timers PWM High True Pulses */
for(i=0; i<channels; i++)
{
pFTM->CONTROLS.CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;
pFTM->CONTROLS.CnV = FTM_C0V_INIT + i*100;
}
}
else if(FTM_PWM_LOWTRUEPULSE == u8PWMEdgeSelect)
{
/* Configure timers for PWM Low True Pulses */
for(i=0; i<channels; i++)
{
pFTM->CONTROLS.CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK;
pFTM->CONTROLS.CnV = FTM_C0V_INIT + i*100;
}
}
}
问题一:如红色字体部分,不明白为什么要+i*100
还有就是:
初始化函数如下:
/* set FTM2 as combine mode */
FTM_PWMInit(FTM2, FTM_PWMMODE_COMBINE, FTM_PWM_LOWTRUEPULSE);
/* set MOD value */
FTM_SetModValue(FTM2, 1000);
/* set clock source and start the counter */
FTM_ClockSet(FTM2, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV1);
//FTM_PWMDeadtimeSet(FTM2,DEAD_PS_DIV1,DEAD_TIME);
//FTM2_PolaritySet(FTM2, FTM2POL_INT);
FTM_SetCallback(FTM2, FTM2_Task);
NVIC_EnableIRQ(FTM2_IRQn);
FTM_EnableOverflowInt(FTM2);
经过测试,FTM2CH3,FTM2CH5输出完全为低电平,FTM2CH2,FTM2CH4输出完全为高电平,但是FTM2CH0和FTM2CH1输出的却是一组互补的PWM
问题是:为什么三组输出会有不同,为什么FTM2CH0和FTM2CH1的PWM |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|