在线时间28 小时
UID113945
注册时间2008-3-21
NXP金币0
TA的每日心情 | 无聊 2019-8-29 13:37 |
---|
签到天数: 6 天 连续签到: 1 天 [LV.2]偶尔看看I
中级会员
 
- 积分
- 251
- 最后登录
- 2022-1-14
|

楼主 |
发表于 2015-10-10 09:27:29
|
显示全部楼层
昨天下午问题解决了,但是具体原因就不去深究了,直接上解决办法:
把之前步进电机微步驱动中对MCDC寄存器的操作使用指针(当然从语法上是没问题的,应该还是编译器差异造成的,之前老项目XHZ用的是CW4.6),改为不使用指针就OK了.时间的问题就先不求甚解了,待日后再说吧
使用指针做法:
{
volatile unsigned char ctemp,*motor_channel;
int temp,itemp;
//LLWW __RESET_WATCHDOG();
itemp=wdM4AimSteps-wdM4CurSteps;
if (itemp!=0)
{
if (itemp<0) wdM4CurSteps--;
else if (itemp>0) wdM4CurSteps++;
motor_channel=(byte *)(&MCDC4);
temp = wdM4CurSteps;
ctemp = temp - (temp / STEP4) * STEP4; //计算得到 temp/24的余数
if(bMotorSWITEC == 0){
if((ctemp<STEP1))
{
*motor_channel&=~S0_DTC; //;Duty cycle channel 0 (A low /A PWM)
*(motor_channel+2)&=~S0_DTC; //;Duty cycle channel 1 (B low /B PWM)
}
else if((ctemp>=STEP1)&&(ctemp<STEP2))
{
*motor_channel&=~S0_DTC; //;Duty cycle channel 0 (A low /A PWM)
*(motor_channel+2)|=S1_DTC; //;Duty cycle channel 1 (B PWM /B low)
}
else if((ctemp>=STEP2)&&(ctemp<STEP3))
{
*motor_channel|=S1_DTC; //;Duty cycle channel 0 (A PWM /A low)
*(motor_channel+2)|=S1_DTC; //;Duty cycle channel 1 (B PWM /B low)
}
else if((ctemp>=STEP3)&&(ctemp<STEP4))
{
*motor_channel|=S1_DTC; //;Duty cycle channel 0 (A PWM /A low)
*(motor_channel+2)&=~S0_DTC; //;Duty cycle channel 1 (B low /B PWM)
}
}
修改后,解决问题的做法:
{
volatile unsigned char ctemp;//, *motor_channel;
int temp, itemp;
itemp = wdM3AimSteps - wdM3CurSteps;
if (itemp!=0)
{
if (itemp < 0)
wdM3CurSteps --;
else if (itemp > 0)
wdM3CurSteps ++;
temp = wdM3CurSteps;
ctemp = temp - (temp / STEP4) * STEP4;
if((ctemp<STEP1))
{
MCDC4_S = 0;
MCDC5_S = 0;
}
else if((ctemp >= STEP1) && (ctemp < STEP2))
{
MCDC4_S = 0;
MCDC5_S = 1;
}
else if((ctemp >= STEP2) && (ctemp < STEP3))
{
MCDC4_S = 1; //;Duty cycle channel 0 (A PWM /A low)
MCDC5_S = 1;
}
else if((ctemp >= STEP3) && (ctemp < STEP4))
{
MCDC4_S = 1; //;Duty cycle channel 0 (A PWM /A low)
MCDC5_S = 0;
}
}
} |
|