每当我为我的systemverilog代码编写一个测试平台时,即使实现是正确的,输出似乎总是为X.我的错误在哪里?
`timescale 1ns / 1ps
module fsm( input logic clk, input logic reset,
input logic start, clockwise,
output logic [3:0] pattern);
parameter A=4'b1100,
B=4'b0110,
Ab=4'b0011,
Bb=4'b1001;
typedef enum logic [1:0] {S0,S1,S2,S3} statetype;
statetype state, nextstate;
//state register
always@ (posedge clk)
begin
if (reset)
state= S0;
else
state = nextstate;
end
//nextstate logic
always_comb
case(state)
S0: if(start==1 && clockwise==0)
nextstate<= S3;
else if(start==1&&clockwise==1)
nextstate<=S1;
else
nextstate<=S0;
S1: if(start==1 && clockwise==0)
nextstate<= S0;
else if(start==1&&clockwise==1)
nextstate<=S2;
else
nextstate<=S1;
S2: if(start==1 && clockwise==0)
nextstate<= S1;
else if(start==1&&clockwise==1)
nextstate<=S3;
else
nextstate<=S2;
S3: if(start==1 && clockwise==0)
nextstate<= S2;
else if(start==1&&clockwise==1)
nextstate<=S0;
else
nextstate<=S3;
endcase
//output logic
always@ (posedge clk)
case(state)
S0: pattern= A;
S1: pattern= B;
S2: pattern= Ab;
S3: pattern= Bb;
endcase
endmodule
这是我的测试平台
module fsmtest();
logic clk, reset, clockwise, start;
logic [3:0] pattern;
fsm dut(clk, reset, start, clockwise, pattern);
//generate clock
always
begin
clk=0; #5; clk=1; #5;
end
initial
begin
reset=0;
start=1;
clockwise=1;
#10;
start=0;
#10;
end
endmodule
我不确定这是我的有限状态机是错误还是它是测试平台。希望得到一些帮助,提前谢谢。
答案 0 :(得分:3)
您从未断言重置,因此您的状态机仍然未初始化。您应该通过在case语句中添加default
分支来解决此问题。然后,如果您的DUT处于未编码状态,则可以保证进入已知状态。