實(shí)驗(yàn)19:步進(jìn)電機(jī)1
實(shí)驗(yàn)?zāi)康?/h2>實(shí)驗(yàn)任務(wù)
本實(shí)驗(yàn)的任務(wù)是設(shè)計(jì)控制四相繞組的步進(jìn)電機(jī)電機(jī)正轉(zhuǎn)、反轉(zhuǎn)、停止的控制電路。要求如下:
電機(jī)運(yùn)轉(zhuǎn)規(guī)律為:正轉(zhuǎn)30s→停10s→反轉(zhuǎn)30s→停10s→正轉(zhuǎn)30s……
本文引用地址:http://cafeforensic.com/article/202310/451502.htm實(shí)驗(yàn)原理
步進(jìn)電機(jī)是將電脈沖信號轉(zhuǎn)變?yōu)榻俏灰苹蚓€位移的開環(huán)控制元步進(jìn)電機(jī)件。當(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í)驗(yàn)要求,我們可以將電機(jī)四相的時(shí)序圖畫出,用1代表高電平,用0代表低電平。則四相步進(jìn)電機(jī)的工作狀態(tài)可以分成四個(gè):狀態(tài)1:1001 ;狀態(tài)2:1100;狀態(tài)3:0110;狀態(tài)4:0011 。正轉(zhuǎn):狀態(tài)1~4,反轉(zhuǎn)狀態(tài)4~1。根據(jù)要求中的正轉(zhuǎn)30s→停10s→反轉(zhuǎn)30s→停10s→正轉(zhuǎn)30s,我們可以將周期設(shè)為40s(其中高電平30s,低電平10s),占空比為3/4。
Verilog HDL建模描述
設(shè)計(jì)文件 stepmotor1.v
module stepmotor1(input wire clk,rst,output wire [5:0] led); wire clk1h; //1秒時(shí)鐘reg [5:0] dir; //電機(jī)轉(zhuǎn)動方向控制。正轉(zhuǎn)000111,反轉(zhuǎn)111000,停止000000reg [5:0] timecont; //計(jì)時(shí) parameter S1 = 2'b00, //電機(jī)工作狀態(tài) 正轉(zhuǎn)
S2 = 2'b01, //停止
S3 = 2'b10, //反轉(zhuǎn)
S4 = 2'b11; //停止
parameter TIME_S1 = 6'd30, //正轉(zhuǎn)計(jì)時(shí)30秒
TIME_S2 = 6'd10, //停止計(jì)時(shí)10秒
TIME_S3 = 6'd30; //反轉(zhuǎn)計(jì)時(shí)30秒 reg [1:0] cur_state,next_state;
divide #( //產(chǎn)生1秒時(shí)鐘信號.WIDTH(24),.N(12000000)) u1(.clk(clk),.rst_n(rst),.clkout(clk1h)); always@(posedge clk1h or negedge rst) //第一段
if(!rst)
cur_state <= S1;
else
cur_state <= next_state; always@(cur_state or rst or timecont) //第二段,狀態(tài)轉(zhuǎn)移
if(!rst)
begin
next_state = S1;
end
else
begin
case(cur_state) //判斷當(dāng)前狀態(tài)
S1:begin
if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S2,否則保持S1
next_state = S2;
else
next_state = S1;
end
S2:begin
if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S3,否則保持S2
next_state = S3;
else
next_state = S2;
end
S3:begin
if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S4,否則保持S3
next_state = S4;
else
next_state = S3;
end
S4:begin
if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S1,否則保持S4
next_state = S1;
else
next_state = S4;
end
default:next_state = next_state;
endcase
end always@(posedge clk1h or negedge rst) //第三段,當(dāng)前狀態(tài)輸出
if(!rst)
begin
timecont <= TIME_S1;
dir <= 6'b000111;
end
else
begin
case(next_state)
S1:begin
dir <= 6'b000111; //正轉(zhuǎn)狀態(tài)輸出
if(timecont == 1) //計(jì)時(shí)控制
timecont <= TIME_S1; //計(jì)時(shí)結(jié)束賦新的值
else
timecont <= timecont - 1;//計(jì)時(shí)減1
end
S2:begin
dir <= 6'b000000;
if(timecont == 1)
timecont <= TIME_S2;
else
timecont <= timecont - 1;
end
S3:begin
dir <= 6'b111000;
if(timecont == 1)
timecont <= TIME_S3;
else
timecont <= timecont - 1;
end
S4:begin
dir <= 6'b111000;
if(timecont == 1)
timecont <= TIME_S2;
else
timecont <= timecont - 1;
end
default:begin
dir <= 6'b000111;
timecont <= TIME_S1;
end
endcase
endassign led = dir; //狀態(tài)輸出動作對應(yīng)的led endmodule
實(shí)驗(yàn)步驟
開發(fā)板上的四個(gè)led會按照10011100011000111001的順序正向循環(huán)30s后暫停10s,然后繼續(xù)從暫停處開始按照10010011011011001001的順序反向循環(huán)30s后暫停10s,再繼續(xù)從暫停處開始正向循環(huán),以此往復(fù)。在任一時(shí)刻,按下rst所連接的按鍵開關(guān),將rst置0,則循環(huán)會回到初始1001狀態(tài)開始正向循環(huán)。
本實(shí)驗(yàn)的任務(wù)是設(shè)計(jì)控制四相繞組的步進(jìn)電機(jī)電機(jī)正轉(zhuǎn)、反轉(zhuǎn)、停止的控制電路。要求如下:
電機(jī)運(yùn)轉(zhuǎn)規(guī)律為:正轉(zhuǎn)30s→停10s→反轉(zhuǎn)30s→停10s→正轉(zhuǎn)30s……
步進(jìn)電機(jī)是將電脈沖信號轉(zhuǎn)變?yōu)榻俏灰苹蚓€位移的開環(huán)控制元步進(jìn)電機(jī)件。當(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í)驗(yàn)要求,我們可以將電機(jī)四相的時(shí)序圖畫出,用1代表高電平,用0代表低電平。則四相步進(jìn)電機(jī)的工作狀態(tài)可以分成四個(gè):狀態(tài)1:1001 ;狀態(tài)2:1100;狀態(tài)3:0110;狀態(tài)4:0011 。正轉(zhuǎn):狀態(tài)1~4,反轉(zhuǎn)狀態(tài)4~1。根據(jù)要求中的正轉(zhuǎn)30s→停10s→反轉(zhuǎn)30s→停10s→正轉(zhuǎn)30s,我們可以將周期設(shè)為40s(其中高電平30s,低電平10s),占空比為3/4。
設(shè)計(jì)文件 stepmotor1.v
module stepmotor1(input wire clk,rst,output wire [5:0] led); wire clk1h; //1秒時(shí)鐘reg [5:0] dir; //電機(jī)轉(zhuǎn)動方向控制。正轉(zhuǎn)000111,反轉(zhuǎn)111000,停止000000reg [5:0] timecont; //計(jì)時(shí) parameter S1 = 2'b00, //電機(jī)工作狀態(tài) 正轉(zhuǎn) S2 = 2'b01, //停止 S3 = 2'b10, //反轉(zhuǎn) S4 = 2'b11; //停止 parameter TIME_S1 = 6'd30, //正轉(zhuǎn)計(jì)時(shí)30秒 TIME_S2 = 6'd10, //停止計(jì)時(shí)10秒 TIME_S3 = 6'd30; //反轉(zhuǎn)計(jì)時(shí)30秒 reg [1:0] cur_state,next_state; divide #( //產(chǎn)生1秒時(shí)鐘信號.WIDTH(24),.N(12000000)) u1(.clk(clk),.rst_n(rst),.clkout(clk1h)); always@(posedge clk1h or negedge rst) //第一段 if(!rst) cur_state <= S1; else cur_state <= next_state; always@(cur_state or rst or timecont) //第二段,狀態(tài)轉(zhuǎn)移 if(!rst) begin next_state = S1; end else begin case(cur_state) //判斷當(dāng)前狀態(tài) S1:begin if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S2,否則保持S1 next_state = S2; else next_state = S1; end S2:begin if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S3,否則保持S2 next_state = S3; else next_state = S2; end S3:begin if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S4,否則保持S3 next_state = S4; else next_state = S3; end S4:begin if(timecont == 1) //計(jì)時(shí)結(jié)束跳轉(zhuǎn)到S1,否則保持S4 next_state = S1; else next_state = S4; end default:next_state = next_state; endcase end always@(posedge clk1h or negedge rst) //第三段,當(dāng)前狀態(tài)輸出 if(!rst) begin timecont <= TIME_S1; dir <= 6'b000111; end else begin case(next_state) S1:begin dir <= 6'b000111; //正轉(zhuǎn)狀態(tài)輸出 if(timecont == 1) //計(jì)時(shí)控制 timecont <= TIME_S1; //計(jì)時(shí)結(jié)束賦新的值 else timecont <= timecont - 1;//計(jì)時(shí)減1 end S2:begin dir <= 6'b000000; if(timecont == 1) timecont <= TIME_S2; else timecont <= timecont - 1; end S3:begin dir <= 6'b111000; if(timecont == 1) timecont <= TIME_S3; else timecont <= timecont - 1; end S4:begin dir <= 6'b111000; if(timecont == 1) timecont <= TIME_S2; else timecont <= timecont - 1; end default:begin dir <= 6'b000111; timecont <= TIME_S1; end endcase endassign led = dir; //狀態(tài)輸出動作對應(yīng)的led endmodule
開發(fā)板上的四個(gè)led會按照10011100011000111001的順序正向循環(huán)30s后暫停10s,然后繼續(xù)從暫停處開始按照10010011011011001001的順序反向循環(huán)30s后暫停10s,再繼續(xù)從暫停處開始正向循環(huán),以此往復(fù)。在任一時(shí)刻,按下rst所連接的按鍵開關(guān),將rst置0,則循環(huán)會回到初始1001狀態(tài)開始正向循環(huán)。
評論