|
步進(jìn)電機(jī)加快電機(jī)轉(zhuǎn)速就會發(fā)生只抖動現(xiàn)象,有什么解決辦法嗎- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define MotorData P1 //步進(jìn)電機(jī)控制接口定義
- //uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正轉(zhuǎn) 電機(jī)導(dǎo)通相序 D-C-B-A
- //uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反轉(zhuǎn) 電機(jī)導(dǎo)通相序 A-B-C-D
- uchar phasecw[8] ={0x06,0x07,0x03,0x0b,0x09,0x0d,0x0c,0x0e};//正轉(zhuǎn) 電機(jī)導(dǎo)通相序 D-C-B-A
- uchar phaseccw[8]={0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06};//反轉(zhuǎn) 電機(jī)導(dǎo)通相序 A-B-C-D
- //ms延時(shí)函數(shù)
- void Delay_xms(uint x)
- {
- uint i,j;
- for(i=0;i<x;i++)
- for(j=0;j<112;j++);
- }
- //順時(shí)針轉(zhuǎn)動
- void MotorCW(void)
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- MotorData=phasecw[i];
- Delay_xms(1);//轉(zhuǎn)速調(diào)節(jié)
- }
- }
- //逆時(shí)針轉(zhuǎn)動
- void MotorCCW(void)
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- MotorData=phaseccw[i];
- Delay_xms(1);//轉(zhuǎn)速調(diào)節(jié)
- }
- }
- //停止轉(zhuǎn)動
- void MotorStop(void)
- {
- MotorData=0x00;
- }
- //主函數(shù)
- void main(void)
- {
- uint i;
- Delay_xms(50);//等待系統(tǒng)穩(wěn)定
- while(1)
- {
- for(i=0;i<500;i++)
- {
- MotorCW(); //順時(shí)針轉(zhuǎn)動
- }
- MotorStop(); //停止轉(zhuǎn)動
- Delay_xms(500);
- for(i=0;i<500;i++)
- {
- MotorCCW(); //逆時(shí)針轉(zhuǎn)動
- }
- MotorStop(); //停止轉(zhuǎn)動
- Delay_xms(500);
- }
- }
復(fù)制代碼
|
|