本帖最后由 wazhzlp 于 2013-4-17 09:04 编辑
大神帮我看看,主要是主函数,这是模拟的一个6路PWM的换向,是不是可以实现其功能。
我不太明白他的COM事件的意思,谢谢指点。
void main(void)
{
Tim1_Init();
while (1)
{
for(step=1;step<7;step++)
{
Commutate(step);
TIM1_GenerateEvent(TIM1_EVENTSOURCE_COM);
}
}
}
void Commutate(u8 step)
{
switch(step)
{
case 1: //3H、2L// WH OFF WL OFF
TIM1_CCxCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_2, TIM1_FORCEDACTION_ACTIVE);
TIM1_CCxCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_2, ENABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_3, TIM1_OCMODE_PWM2);
TIM1_CCxCmd(TIM1_CHANNEL_3, ENABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_3, DISABLE);
break;
case 2:
TIM1_SelectOCxM(TIM1_CHANNEL_1, TIM1_FORCEDACTION_ACTIVE);
TIM1_CCxCmd(TIM1_CHANNEL_1,DISABLE );
TIM1_CCxNCmd(TIM1_CHANNEL_1, ENABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_2, TIM1_OCMODE_PWM2);
TIM1_CCxCmd(TIM1_CHANNEL_2, ENABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_CCxCmd(TIM1_CHANNEL_3, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_3, DISABLE);
break;
case 3:
TIM1_SelectOCxM(TIM1_CHANNEL_1, TIM1_FORCEDACTION_ACTIVE);
TIM1_CCxCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_1, ENABLE);
TIM1_CCxCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_3, TIM1_OCMODE_PWM2);
TIM1_CCxCmd(TIM1_CHANNEL_3, ENABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_3, DISABLE);
break;
case 4:
TIM1_CCxCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_2, TIM1_FORCEDACTION_ACTIVE);
TIM1_CCxCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_2, ENABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_3, TIM1_OCMODE_PWM2);
TIM1_CCxCmd(TIM1_CHANNEL_3, ENABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_3, DISABLE);
break;
case 5:
TIM1_SelectOCxM(TIM1_CHANNEL_1, TIM1_OCMODE_PWM2);
TIM1_CCxCmd(TIM1_CHANNEL_1, ENABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_2, TIM1_FORCEDACTION_ACTIVE);
TIM1_CCxCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_2, ENABLE);
TIM1_CCxCmd(TIM1_CHANNEL_3, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_3, DISABLE);
break;
case 6:
TIM1_SelectOCxM(TIM1_CHANNEL_1, TIM1_FORCEDACTION_ACTIVE);
TIM1_CCxCmd(TIM1_CHANNEL_1, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_1, ENABLE);
TIM1_CCxCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_2, DISABLE);
TIM1_SelectOCxM(TIM1_CHANNEL_3, TIM1_OCMODE_PWM2);
TIM1_CCxCmd(TIM1_CHANNEL_3, ENABLE);
TIM1_CCxNCmd(TIM1_CHANNEL_3, DISABLE);
break;
default:
break;
} |