0
每當我爲我的systemverilog代碼編寫測試臺時,即使實現正確,輸出似乎總是X.我的錯誤在哪裏?輸出始終爲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
[email protected] (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
[email protected] (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
我不知道這是否是我的有限狀態機,是錯誤的,或者如果它的測試平臺。希望得到一些幫助,提前致謝。
你的阻塞/非阻塞混淆了。組合('always_comb' /'always @ *')應該是阻塞的('=')。順序('@(posedge clk)')應該是非阻塞的('<=')。 – Greg
謝謝我從來不知道這個 – John