[mw_shl_code=c,true]/******************************************************************************
*????????:static void Motor1PointerControl(void)
*???????÷:???ú1????????
*????????:??
*????????:??
*******************************************************************************/
static void Motor1PointerControl(void) //100us*32 == 3.2ms LOOP in Time0
{
static u16 iStop = 0; //????
//----------------------------------------------------------------------DmxFinedataUser
if ((Motor1_postion_Current == Motor1_postion_user)&&(!MotorXSpeedPos)) //?????±?°?????????è???????°??????????0
{ //?????±?°???????????§?????????????ú??????
Motor1_user_postion_gap = 0; //???§?¨????????0
Motor1_dynamic_postion_gap = 0; //?????¨????????0
LineFlag = 2; //1 ???? 0 ???? 2 ???? (????)
//-----------?????±?????????¨???????????ú??????±?----------------------------
if (iStop > 30) //655us/2*500 ?????±???÷????????1/4
{//????????2?????????÷????
Current_Attenuation(2); //???????ú???÷????????????
DECAY = 0; //???????ú???????÷??????????
TIM3->CCR2 = SinDataA[MotorPositionPointer]>>0; //Sin?¨??????A
TIM3->CCR1 = SinDataB[MotorPositionPointer]>>0; //Sin?¨??????B
TIM3->CCR4 = CosDataC[MotorPositionPointer]>>0; //Sin?¨??????C
TIM3->CCR3 = CosDataD[MotorPositionPointer]>>0; //Sin?¨??????D
}
else
{
iStop++; //?????ó???÷????????
Current_Attenuation(1); //???????ú???÷????????????
DECAY = 0; //???????ú???????÷??????????
}
}
else
{
iStop = 0; //????????????
if (DecayXCurrentFlag) //?????±?°???÷????±ê??=1
{ //??°???????2
Current_Attenuation(2); //???????ú???÷????????????
DECAY = 0; //???????ú???????÷??????????
TIM3->CCR2 = SinDataA[MotorPositionPointer]>>0; //Sin?¨??????A
TIM3->CCR1 = SinDataB[MotorPositionPointer]>>0; //Sin?¨??????B
TIM3->CCR4 = CosDataC[MotorPositionPointer]>>0; //Sin?¨??????C
TIM3->CCR3 = CosDataD[MotorPositionPointer]>>0; //Sin?¨??????D
}
else
{ //·??ò????????????
Current_Attenuation(1); //???????ú???÷????????????
DECAY = 1; //???????ú???????÷??????????
TIM3->CCR2 = SinDataA[MotorPositionPointer]>>0; //Sin?¨??????A
TIM3->CCR1 = SinDataB[MotorPositionPointer]>>0; //Sin?¨??????B
TIM3->CCR4 = CosDataC[MotorPositionPointer]>>0; //Sin?¨??????C
TIM3->CCR3 = CosDataD[MotorPositionPointer]>>0; //Sin?¨??????D
}
//---------??·?×?????-----------------------------------------
if (Motor1_dir == 1) //???§??????·??ò ?????ò?±
{
Motor1_dir_Current = 1; //???ú?±?°·??ò??1???ò
}
else //???§??????·??ò ??·??ò?±
{
Motor1_dir_Current = 0; //???ú?±?°·??ò??0·??ò
}
//------------------------------------------------------------
if (Motor1_dir_Current == YES) //???????????ú ???ò×???
{
//?????ò????×??? ???¨×???
MotorPositionPointer += MaxStep; //16*2; //???????ú??????????16
CounterMotorXStepPostionCurrent += 1; //???????ú?¨????????1
//-------------×??ê?????????ú????1024??????------------------------
if (MotorPositionPointer >= 1024) //?????????ó??1024??????
{
MotorPositionPointer = 0; //??????????×??????ú??
}
}
else //·??ò???????????ú ·??ò×???
{
MotorPositionPointer -= MaxStep; //16*2; //???????ú??????????16
CounterMotorXStepPostionCurrent -= 1; //???????ú?¨????????1
//--------------------------------------------------
if (MotorPositionPointer <= 0) //????????????????0????×??ó1024
{
MotorPositionPointer = 1024; //???????????ú????×??ó??????
}
}
}
//---------------------------------------------------------------------------------------------------------------
Motor1_postion_Current = CounterMotorXStepPostionCurrent; //°????????????±?°?????????÷
//?±?°×????ì?? ??????×????????÷ ?????±?°×???
//---------------------------------------------------------------------------------------------------------------
}[/mw_shl_code]
在淘宝上买的快300大洋的步进电机驱动,我把它精简成只有一路步进电机的驱动程序,还自己写了一个上位机软件通过串口来控制电机的粗调和细调功能,现在来原子贵坛分享下!
不过还有一个问题就是速度还不能满足我的项目需求,想调节步进电机的速度指数曲线的数组但是不懂怎么生成?
还望有做过的大神不吝赐教,谢谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>