51單片機(jī)驅(qū)動步進(jìn)電機(jī)(雙四拍和八拍)
通常電機(jī)的轉(zhuǎn)子為永磁體,當(dāng)電流流過定子繞組時(shí),定子繞組產(chǎn)生一矢量磁場。該磁場會帶動轉(zhuǎn)子旋轉(zhuǎn)一角度,使得轉(zhuǎn)子的一對磁場方向與定子的磁場方向一致。當(dāng)定子的矢量磁場旋轉(zhuǎn)一個(gè)角度。轉(zhuǎn)子也隨著該磁場轉(zhuǎn)一個(gè)角度。每輸入一個(gè)電脈沖,電動機(jī)轉(zhuǎn)動一個(gè)角度前進(jìn)一步。它輸出的角位移與輸入的脈沖數(shù)成正比、轉(zhuǎn)速與脈沖頻率成正比。改變繞組通電的順序,電機(jī)就會反轉(zhuǎn)。所以可用控制脈沖數(shù)量、頻率及電動機(jī)各相繞組的通電順序來控制步進(jìn)電機(jī)的轉(zhuǎn)動。每一個(gè)脈沖信號對應(yīng)步進(jìn)電機(jī)的某一相或兩相繞組的通電狀態(tài)改變一次,也就對應(yīng)轉(zhuǎn)子轉(zhuǎn)過一定的角度(一個(gè)步距角)。當(dāng)通電狀態(tài)的改變完成一個(gè)循環(huán)時(shí),轉(zhuǎn)子轉(zhuǎn)過一個(gè)齒距。四相步進(jìn)電機(jī)可以在不同的通電方式下運(yùn)行,常見的通電方式有單(單相繞組通電)四拍(A-B-C-D-A),雙(雙相繞組通電)四拍(AB-BC-CD-DA-AB),八拍(A-AB-B-BC-C-CD-D-DA-A)。
本文引用地址:http://m.butianyuan.cn/article/201611/318365.htm以下代碼為8拍:
sbit P00 = P0^0;sbit P01 = P0^1;sbit P02 = P0^2;sbit P03 = P0^3;//設(shè)置成推挽模式-將引腳強(qiáng)制拉高--void init_gpio(void){P0M1 = P0M1 & 0X0;P0M2 = P0M2 0XFF;P0 = 0X0; }//--horizontal motor#define A P00#define B P01#define C P02#define D P03#define h_Coil_A {A = 1;B = 0;C = 0;D = 0;}#define h_Coil_AB {A = 1;B = 1;C = 0;D = 0;}#define h_Coil_B {A = 0;B = 1;C = 0;D = 0;}#define h_Coil_BC {A = 0;B = 1;C = 1;D = 0;}#define h_Coil_C {A = 0;B = 0;C = 1;D = 0;}#define h_Coil_CD {A = 0;B = 1;C = 1;D = 0;}#define h_Coil_D {A = 0;B = 0;C = 0;D = 1;}#define h_Coil_DA {A = 0;B = 0;C = 1;D = 1;}#define h_Coil_OFF {A = 0;B = 0;C = 0;D = 0;}void h_Right_Motor(){h_Coil_Adelay_ms(speed);h_Coil_ABdelay_ms(speed);h_Coil_Bdelay_ms(speed);h_Coil_BCdelay_ms(speed);h_Coil_Cdelay_ms(speed);h_Coil_CDdelay_ms(speed);h_Coil_Ddelay_ms(speed);h_Coil_DAdelay_ms(speed);}void h_Left_Motor(){h_Coil_DAdelay_ms(speed);h_Coil_Ddelay_ms(speed);h_Coil_CDdelay_ms(speed);h_Coil_Cdelay_ms(speed);h_Coil_BCdelay_ms(speed);h_Coil_Bdelay_ms(speed);h_Coil_ABdelay_ms(speed);h_Coil_Adelay_ms(speed);}
評論