2
我有一個家庭作業問題,需要製作一個mealy機器的狀態圖,每當連續輸入3個或更多個1時就會輸出一個狀態圖。 我想出了它,並且我看到它的方式在我的案例(狀態)中概述,並且我感覺它是正確的,因爲它編譯得很好。我認爲我的問題在於我的測試平臺。這一切都在一個文件中,但打散,使我的解釋更容易...Verilog測試臺狀態圖
// This is my module for the state diagram
module prob558(output reg y,input x, clk,reset);
parameter s0=2'b00,s1=2'b01,s2=2'b10,s3=2'b11;
reg [1:0] state;
always @(posedge clk, negedge reset)
if (reset==0) state<=s0;
else
case(state)
s0: if (x==0) state<=s0 && y==0; else if(x==1)state<=s1 && y==0;
s1: if (x==0) state<=s0 && y==0; else if(x==1)state<=s2 && y==0;
s2: if (x==0) state<=s0 && y==0; else if(x==1)state<=s3 && y==0;
s3: if (x==0) state<=s0 && y==1; else if(x==1)state<=s3 && y==1;
endcase
endmodule
這裏是我的測試臺開始的地方......我想在這裏做的是隻輸出x和y來看到他們來出什麼是
module prob558_tb();
reg clock;
reg reset;
reg x;
wire y;
prob558 p558(y,x,clk,reset);
// this is where I am starting to get lost, I am only trying to follow a
// poorly explained example my professor showed us for a synchronous
// circuit...
initial #200 $finish;
initial begin
clock = 0;
reset = 0;
#5 reset =1;
#5 clock=~clock;
end
// This I came up with my own, and although it is wrong, this is the way I am
// thinking of it. What I am trying to do below is to have the 'x' inputs be
// set by these numbers I am inputting, and then I was thinking it would go
// through my case statements and the 'y' output would be given
initial begin
#10 x=1;
#10 x=0;
#10 x=1;
#10 x=1;
#10 x=1;
#10 x=1;
#10 x=1;
#10 x=0;
#10 x=0;
end
// the following below I know is correct!
initial begin
$monitor("x= %d y=%d",x,y);
$dumpfile("prob558.vcd");
$dumpvars;
end
endmodule
我得到的0101010 X輸入和我的Y輸出全部出來爲「Y = X」 如果任何人有任何提示改進我將不勝感激!
提示:'&&'是一個邏輯運算符; tt不會分配任務。因此'state <= s0&& y==0;'與state <=(s0 &&(y == 0))相同;''y'被視爲輸入,並且是X,因爲它從未分配過。你需要像'begin state <= s0; ÿ<= 0;結束'更接近你應該使用的。有更多更乾淨的方式來獲得您想要的功能,你應該看看它。 – Greg