|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
此程序是简单的状态机,在仿真的时候K2和K1的值是未知数X,请高手赐教
module fsm(Clock,Reset,A,K2,K1,state);
input Clock,Reset,A;
output K2,K1;
output [1:0]state;
reg K2,K1;
reg [1:0]state;
parameter Idle=2'b00,
Start=2'b01,
Stop=2'b10,
Clear=2'b11;
always @(posedge Clock)
if(!Reset)
begin
state<=Idle;
K2<=0;
K1<=0;
end
else
casex(state)
Idle:if(A) begin
state<=Start;
K1<=0;
end
else begin
state<=Idle;
K2<=0;
K1<=0;
end
Start:if(!A) state<=Stop;
else state<=Start;
Stop:if(A) begin
state<=Clear;
K2<=1;
end
else begin
state<=Stop;
K2<=0;
K1<=1;
end
Clear:if(!A) begin
state<=Idle;
K2<=0;
K1<=1;
end
else begin
state<=Clear;
K2<=0;
K1<=0;
end
default:state<=Idle;
endcase
endmodule
测试代码
`timescale 1ns/1ns
module test;
reg a;
reg clock,rst;
wire k2,k1;
initial
begin
a=0;
rst=1;
clock=0;
#22 rst=0;
#133 rst=1;
end
always #50 clock=~clock;
always @(posedge clock)
begin
#30 a={$random}%2;
#(3*50+12);
end
initial
begin
#10000 $stop;
end
fsm m(.Clock(clcok),.Reset(rst),.A(a),.K2(k2),.K1(k1));
endmodule |
|