初级会员
- 积分
- 70
- 金钱
- 70
- 注册时间
- 2015-3-25
- 在线时间
- 11 小时
|
1金钱
本帖最后由 wuping8229 于 2016-11-10 20:31 编辑
用tim1 比较通道3,4产生舵机信号。直接硬件pwm,通道3的信号是正常的。软件模拟时,在比较中断的时候写低电平,tim2更新的时候写高电平,同样的配置,通道3高电平信号是随机的,通道4是正常的。不知道什么回事,下图是软件模拟的信号,上面的是通道4信号,下面是通道3信号
通道3-4
tim1的初始设置
TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,2099, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_SET);
TIM1_OC3PreloadConfig(ENABLE);
TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, 499, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_RESET);//50%占空比
TIM1_OC4PreloadConfig(ENABLE);
TIM1_CCxCmd(TIM1_CHANNEL_1|TIM1_CHANNEL_2|TIM1_CHANNEL_3|TIM1_CHANNEL_4, ENABLE);
TIM1_ITConfig(TIM1_IT_CC3|TIM1_IT_CC4, ENABLE);
tim1 比较中断
INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
{
ITStatus its;
its = TIM1_GetITStatus(TIM1_IT_CC3);
if(its)
{
GPIO_WriteLow(SERVOPORTP, SERVOPINP);
TIM1_ClearITPendingBit(TIM1_IT_CC3);
return;
}
GPIO_WriteLow(SERVOPORTY, SERVOPINY);
TIM1_ClearITPendingBit(TIM1_IT_CC4);
}
}
tim2更新中断
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
GPIO_WriteHigh(SERVOPORTY, SERVOPINY);
GPIO_WriteHigh(SERVOPORTP, SERVOPINP);
TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
}
|
|