大家好! 我用32 tim1 6路pwm 互补 控制blcd 现在遇到一个问题 就是 重复调用
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); //pwm1
TIM_SetCompare2(TIM1, 0); //占空比0
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable); //chN通道 0
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); // ch通道 1
这个语句波形输出就不正常 ,会有异常下降沿
代码是
TIM_TimeBaseStructure.TIM_Prescaler = 0; //预分频
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_CenterAligned1 ; // 模式 增 ;//中央对齐模式 1 计数模式
TIM_TimeBaseStructure.TIM_Period = 5999; // 从装比较最大 12k = 72000/ 6000= 12k
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 分频
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0; // 控制占空比
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High ; // 上桥臂
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High ; // 下桥臂
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
TIM_OC1Init(TIM1, &TIM_OCInitStructure); // 比较单元 1 2 3
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); //
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
// The DeadTime=8(32+DTG[4:0])Tdts DTG= C4
TIM_BDTRInitStructure.TIM_DeadTime = 0x6A; // 带死区 1.8us左右
// TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_Break =TIM_Break_Disable ; // 关闭刹车
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;//低电平输入有效
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_ClearITPendingBit(TIM1, TIM_IT_Break); //清中断标志位
TIM_ITConfig(TIM1,TIM_IT_Break ,ENABLE); //使能中断
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ClearITPendingBit(TIM1, TIM_IT_Update); //清中断标志位
TIM_ITConfig(TIM1,TIM_IT_Update ,ENABLE); //打开中断
TIM_Cmd(TIM1, DISABLE);//使能或者失能TIMx外设
TIM_CtrlPWMOutputs(TIM1, DISABLE); //使能或者失能主输出
如果去掉其中一个,问题就解决了,相波形也非常完美,但是如果电机启动的时候可以会卡住,因为这个区只开了4路pwm。
搞了好几天没有解决,无奈请教网友
|