module motor(clk,reset,dir,a,b,c);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
input clk,reset,dir;
output a,b,c;
reg a,b,c;
parameter st0=3'b001,st1=3'b011,st2=3'b010,st3=3'b110,st4=3'b100,st5=3'b101;
reg[2:0] pst,nst;
always @(posedge clk)
begin
if(reset)
pst<=st0;
else
pst<=nst;
end
always @(pst or dir)
begin
if(!dir)
begin
case(pst)
st0:nst<=st1;
st1:nst<=st2;
st2:nst<=st3;
st3:nst<=st4;
st4:nst<=st5;
st5:nst<=st0;
endcase
end
else
begin
case(pst)
st0:nst<=st5;
st1:nst<=st0;
st2:nst<=st1;
st3:nst<=st2;
st4:nst<=st3;
st5:nst<=st4;
endcase
end
end
always @(pst)
begin
case(pst)
st0:<?xml:namespace prefix = st1 ns = "isiresearchsoft-com/cwyw" />{c,b,a}<=st0;
st1:{c,b,a}<=st1;
st2:{c,b,a}<=st2;
st3:{c,b,a}<=st3;
st4:{c,b,a}<=st4;
st5:{c,b,a}<=st5;
endcase
end
endmodule
我是用状态机设计的,这里我转载了别人的一个程序,他是用VHDL语言写的,详见附件。
用户377235 2012-5-24 13:14