【发布时间】:2015-12-09 23:35:24
【问题描述】:
我有一个家庭作业问题,需要为一个 Mealy 机器制作状态图,只要连续输入 3 个或更多 1,它就会输出一个。 我想出了它,并且在我的案例(状态)中概述了我看到它的方式,我觉得它是正确的,因为它编译得很好。我认为我的问题是我的测试台。这一切都在一个文件中,但为了让我的解释更容易而分解...
// 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; y<=0; end这样的东西更接近你应该使用的东西。有更多更简洁的方法可以获得您想要的功能,您应该研究一下。
标签: verilog