本帖最后由 你好我好大家好! 于 2015-1-28 19:44 编辑 有高手调试过st库函数中自带的TIM_6Steps历程吗?stm32f051xx的。我调试了一下,出来的波形是下图这样的file:///C:\Users\Administrator\Documents\Tencent Files\1835116269\Image\4~}7E)9FBC$1E]F6CKEYB(H.jpg,感觉有些问题就是1和1n通道有同时为高电平的时候,这样在电机控制板中上下桥臂的两只管子就会直通,就把电源烧坏了。我希望是在1和1n通道没有输出pwm的期间,对应管脚输出都为低电平。可能是哪里没有设置好,希望高手们可以只指点一下, |
您好啊:
我采用的是nnmos的驱动模式。现在希望的是:在各通道上同时为Disable期间,对应通道的引脚为低电平,比如上图中1和1n通道中划红线的部分,是两个通道同时为Disable,希望这里同时为低电平。
定时器的配置是这样的, /* Channel 1, 2,3 and 4 Configuration in PWM mode */
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 = 2047;
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);
TIM_OCInitStructure.TIM_Pulse = 1023;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 511;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 1;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
在中断中六步pwm是这样的,void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
{
/* Clear TIM1 COM pending bit */
TIM_ClearITPendingBit(TIM1, TIM_IT_COM);
if (step == 1)
{
/* Next step: Step 2 Configuration -------------------------------------- */
/* Channel3 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
step++;
}
else if (step == 2)
{
/* Next step: Step 3 Configuration -------------------------------------- */
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
step++;
}
else if (step == 3)
{
/* Next step: Step 4 Configuration -------------------------------------- */
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel2 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
step++;
}
else if (step == 4)
{
/* Next step: Step 5 Configuration -------------------------------------- */
/* Channel3 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
step++;
}
else if (step == 5)
{
/* Next step: Step 6 Configuration -------------------------------------- */
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
/* Channel1 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
step++;
}
else
{
/* Next step: Step 1 Configuration -------------------------------------- */
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
/* Channel2 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
step = 1;
}
}
按道理说在两个通道同时Disable期间,对应引脚输出的电平就是为低电平啊,因为定时器的配置为TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High ;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High ;
可是用逻辑分析仪测试的结果不是这样的,希望能指点一下,先谢谢了
你是说1楼的那个波形吗?那个波形就是用逻辑分析仪测量出来的。就是将stm32f0xx的外设库中的TIM_6Steps例程(历程的位置:STM32F0xx_StdPeriph_Lib_V1.4.0->Projects->STM32F0xx_StdPeriph_Examples->TIM->TIM_6Steps)下载到我的学习开发板:stm32f0discovery中测量出来的,打算把这个例程用到无刷直流电机驱动上面上呢,结果测量后发现在上下两个互补通道都关闭后,对应引脚输出的为高电平(按照无刷直流电机驱动理论和例程中的配置:TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High ; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High ;对应引脚应该输出低电平。就是1楼图片中划红线部分为两个互补通道都关闭的时候,应该输出低电平才对的),不知道是开发板坏了,还是我没理解好手册,阳光大哥配置的代码是使用在f0xx上面吗?能把你的代码贴出来共享一下吗?谢谢了
逻辑分析仪测量出来的波形贴在1楼了,就是将stm32f0xx的外设库中的TIM_6Steps例程(历程的位置:STM32F0xx_StdPeriph_Lib_V1.4.0->Projects->STM32F0xx_StdPeriph_Examples->TIM->TIM_6Steps)下载到我的学习开发板:stm32f0discovery中测量出来的,打算把这个例程用到无刷直流电机驱动上面上呢,结果测量后发现在上下两个互补通道都关闭后,对应引脚输出的为高电平(按照无刷直流电机驱动理论和例程中的配置:TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High ; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High ;对应引脚应该输出低电平。就是1楼图片中划红线部分为两个互补通道都关闭的时候,应该输出低电平才对的),不知道是开发板坏了,还是我没理解好手册,找了好几天原因了,还是没解决,哎哎,另外你这波形是103的吧
你那个波形是怎么来的呀,我用的没问题,不过我是用在Full bright上,没一点问题呀。应该是你文档研究的不够深入,我没用库文件,自己写的。ST的这个PWM真心不好用,文档看起来要吐血,写的不明不白的。
能把你用逻辑分析仪检测的波形贴出来吗?不然不好分析。另,关于官网自带的程序的库还有讨论的空间:官网的程序基于051,内核是cotex—m0的好像,103系列的是基于cotex_m3,对于库的版本对于pwm输出极性的影响,参照下图,希望对你有帮助。
现在使用103的还比较普遍,而且库版本问题一直都很困扰,051的程序不能直接移植,其时钟和io口设置和103有较大的差别,要不你换一个库试试,而且用于bldc的pwm驱动程序网上也有很多,不见得非得要用它的,它的程序自然接近最优的,但是很大替换程序写得也不差,换相部分的程序也有不少,我最近也在做bldc控制,只不过做的是无感的,算法要复杂一些,不过还没有做出来。
哎!关键051的板子已经做出来了。刚才我试了一下103官方外设库中自带的六步电压的历程,测量出来的波形是正确的,波形图如下,其中的配置和051的差不多,可是051的就是不对,看着051的手册和历程中软件的配置是一致的,但是测量的波形就是不对,哎,,,愁死我了C:\Users\Administrator\Desktop
哦,好吧,这个我也不清楚了,我用的pwm波都是我自己调出来的,感觉还行。