本帖最后由 邵大书生 于 2010-1-14 16:10 编辑
L6219的I01,I11,I12,I02,PH1,PH2分别接到单片机,还有参考电压(VREF1,VREF2)也接到单片机PWM输出端口。
I01,I11,I12,I02给接低电平,两相输出电流都为VREF/10*RS,
(1)当PH1=1,PH2=1时(AB)
VREF1由5V慢慢下降到0V,VREF2由0V慢慢上升到5V
(2)当PH1=0,PH2=1时(-AB)
VREF1由0V慢慢上升到5V,VREF2由5V慢慢下降到0V
(3)当PH1=0,PH2=0时(-A-B)
VREF1由5V慢慢下降到0V,VREF2由0V慢慢上升到5V
(4)当PH1=1,PH2=0时(A-B)
VREF1由0V慢慢上升到5V,VREF2由5V慢慢下降到0V
循环(1)——(4)
原来走一步现在细分成N步来完成,应该没有什么振动才对,可是还是有振动,是在那里出了问题呢,我一名学生能力有限,请各位帮帮忙,在此谢过!!
//---------------------------------马达的运转-------------------------------
void MotorRun(unsigned char Direct,unsigned int Steps)//方向与步数
{
unsigned int StepCount;
unsigned char Subdivide=1;
switch(MotorWorking.WorkState)
{
case MotorIdel:
MotorWorking.MotorDirect=Direct;
MotorWorking.MotorSteps=Steps;
MotorWorking.SubdivideNumber=1; //马达128倍细分
MotorWorking.WorkState=MotorPowerOn;
case MotorPowerOn: //马达旋转步距角比较小时,在上电过程中完成,速度不上到正常旋转中
while(Subdivide<MotorWorking.MaxStep)
{
StepCount=65; //马达走64个小步,速度上一个台阶
while(--StepCount)
{ MotorRunOneStep(MotorWorking.MotorDirect);
MotorGetEnergy(MotorWorking.SubdivideTableID);
}
Subdivide<<=1;
MotorWorking.SubdivideNumber=Subdivide;
} //当马达速度达到最大速度时进入正常运转状态
MotorWorking.WorkState=MotorNormalState;
case MotorNormalState:
StepCount=MotorWorking.MotorSteps; //这里的StepCount保存的是马达还有多少个步距角
while(StepCount>4) //马达最后一圈进入减速状态
{ MotorRunOneStep(MotorWorking.MotorDirect); //查找PWM占空比数据
MotorGetEnergy(MotorWorking.SubdivideTableID); //由数据输PWM(电流变化)
StepCount=MotorWorking.MotorSteps;
}
MotorWorking.WorkState=MotorPowerOff;
case MotorPowerOff:
StepCount=MotorWorking.MotorSteps;
if(MotorWorking.MotorSteps==4)
{
Subdivide=MotorWorking.MaxStep>>1;
while(Subdivide)
{
StepCount=65; //马达走64个小步,速度上一个台阶
while(--StepCount)
{
MotorRunOneStep(MotorWorking.MotorDirect);
MotorGetEnergy(MotorWorking.SubdivideTableID);
}
Subdivide>>=1;
MotorWorking.SubdivideNumber=Subdivide;
}
}
MotorWorking.WorkState=MotorIdel;
break;
default:
break;
}
} |