51單片機驅(qū)動步進電機(雙四拍和八拍)
通常電機的轉(zhuǎn)子為永磁體,當電流流過定子繞組時,定子繞組產(chǎn)生一矢量磁場。該磁場會帶動轉(zhuǎn)子旋轉(zhuǎn)一角度,使得轉(zhuǎn)子的一對磁場方向與定子的磁場方向一致。當定子的矢量磁場旋轉(zhuǎn)一個角度。轉(zhuǎn)子也隨著該磁場轉(zhuǎn)一個角度。每輸入一個電脈沖,電動機轉(zhuǎn)動一個角度前進一步。它輸出的角位移與輸入的脈沖數(shù)成正比、轉(zhuǎn)速與脈沖頻率成正比。改變繞組通電的順序,電機就會反轉(zhuǎn)。所以可用控制脈沖數(shù)量、頻率及電動機各相繞組的通電順序來控制步進電機的轉(zhuǎn)動。每一個脈沖信號對應(yīng)步進電機的某一相或兩相繞組的通電狀態(tài)改變一次,也就對應(yīng)轉(zhuǎn)子轉(zhuǎn)過一定的角度(一個步距角)。當通電狀態(tài)的改變完成一個循環(huán)時,轉(zhuǎn)子轉(zhuǎ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è)置成推挽模式-將引腳強制拉高--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);}
評論