實驗用的是28BYJ48型步進電機+ULN2003驅動,程序是正轉一圈、停、又反轉一圈。。。如此反復轉動,但發(fā)現(xiàn)步進電機丟步嚴重,比如12點方向開始轉動,一兩小時下來位置就變了,有30度左右位移,請問是怎樣造成的,謝謝!
51hei圖片_1.jpg (207.95 KB, 下載次數(shù): 21)
下載附件
2023-1-17 13:29 上傳
/*******************************************************
28BYJ48型步進電機+ULN2003驅動
接線方式:
IN1 ---- P10
IN2 ---- P11
IN3 ---- P12
IN4 ---- P13
+ ---- +5V
- ---- GND
*********************/
#include<reg52.h> //12mhz
#define uchar unsigned char
#define uint unsigned int
#define MotorData P1 //步進電機接口定義
uchar phasecw[8] ={0x08,0x04,0x02,0x01};//正轉,4拍 A-B-C-D
uchar phaseccw[8]={0x01,0x02,0x04,0x08};//反轉
//ms延時函數(shù)
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<112;j++);
}
//順時針轉動
void MotorCW(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phasecw;
Delay_xms(2);//轉速調節(jié)
}
}
//逆時針轉動
void MotorCCW(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phaseccw;
Delay_xms(2);//轉速調節(jié)
}
}
//停止轉動
void MotorStop(void)
{
MotorData=0x00;
}
//主函數(shù)
void main(void)
{
uint i;
Delay_xms(50);//等待系統(tǒng)穩(wěn)定
while(1)
{
for(i=0;i<512;i++)
{
MotorCW(); //順時針轉動
}
MotorStop(); //停止轉動
Delay_xms(1000);
for(i=0;i<512;i++)
{
MotorCCW(); //逆時針轉動
}
MotorStop(); //停止轉動
Delay_xms(1000);
}
}
|