|
1,先上关键代码,用于设置TIM1的六个通道的状态的句子,我觉得写得很不错。详细说明看2,高手就直接看3,启动问题好了
switch (MotorA.Step)
{
case 0 :
/* PhaseA configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCx_Disable); // 0
TIM_OC1NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_High);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCxN_Disable); // 0
/* PhaseB configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCx_Enable); // 1
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCxN_Enable); //同步整流
/* PhaseC configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCx_Disable); // 0
TIM_OC3NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_Low);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCxN_Disable); // 1
break;
case 1:
/* PhaseB configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCx_Disable); // 0
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCxN_Disable); // 0
/* PhaseA configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCx_Enable); // 1
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCxN_Enable); //同步整流
/* PhaseC configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCx_Disable); // 0
TIM_OC3NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_Low);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCxN_Disable); // 1
break;
case 2:
/* PhaseA configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCx_Enable); // 1
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCxN_Enable); //同步整流
/* PhaseC configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCx_Disable); // 0
TIM_OC3NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_High);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCxN_Disable); // 0
/* PhaseB configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCx_Disable); // 0
TIM_OC2NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_Low);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCxN_Disable); // 1
break;
case 3:
/* PhaseA configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCx_Disable); // 0
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCxN_Disable); // 0
/* PhaseB configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCx_Disable); // 0
TIM_OC2NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_Low);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCxN_Disable); // 1
/* PhaseC configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCx_Enable); // 1
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCxN_Enable); //同步整流
break;
case 4:
/* PhaseB configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCx_Disable); // 0
TIM_OC2NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_High);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCxN_Disable); // 0
/* PhaseA configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCx_Disable); // 0
TIM_OC1NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_Low);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCxN_Disable); // 1
/* PhaseC configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCx_Enable); // 1
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCxN_Enable); //同步整流
break;
case 5:
/* PhaseA configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCx_Disable); // 0
TIM_OC1NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_Low);
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_1, TIM_CCxN_Disable); // 1
/* PhaseC configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCx_Disable); // 0
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_3, TIM_CCxN_Disable); // 0
/* PhaseB configuration */
TIM_CCxCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCx_Enable); // 1
TIM_CCxNCmd(BLDC_TIMER_NUM, TIM_Channel_2, TIM_CCxN_Enable); //同步整流
break;
default:
MotorA.Step = 0;
}
2,关于以上代码的说明
在上传的图片1里,有ccer寄存控制位的说明,基本思路是,禁止输出后,对应的引脚会输出无效电平,该无效电平是有TIM_OC2NPolarityConfig(BLDC_TIMER_NUM, TIM_OCNPolarity_High);这个函数来设置的。
////////////////////////////////////////////////////////////////////////////////////////////////
我的问题:
3,我的问题,在图片中,示波器截图两个,第一个为tim1的channel1,pa8的输出,是为了显示pwm的输出情况,第二为电机某一相电压。现象是,没有啥动静,用手拧电机,能感觉到比不同电有阻力,
现在只想然电机转起来,所以在主函数中只有一个开环的换相程序,没有调整pwm和换相周期,是不是因为没有改变这两点,所以没有转吗?还是我自己tim1设置的还是哪点不正确,恳请各位指导。
START_TIME;
Step=2;
BLDC_SwitchStep();
delay(10000);
if ( time == 100 ) /* 0.5s 时间到 */
{
// change1();
Step=2;
BLDC_SwitchStep();
}
if ( time == 200 ) /* 1s 时间到 */
{
// change2();
Step=1;
BLDC_SwitchStep();
}
if ( time == 300 )
{
Step=0;
BLDC_SwitchStep();
}
if ( time == 400 )
{
Step=5;
BLDC_SwitchStep();
}
if ( time == 500 )
{
Step=4;
BLDC_SwitchStep();
}
if ( time == 600 )
{
time=0;
Step=3;
BLDC_SwitchStep();
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|