【问题标题】:Verilog test bench state diagramVerilog 测试台状态图
【发布时间】: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' 如果有人有任何改进建议,我将不胜感激!

【问题讨论】:

  • 提示:&amp;&amp; 是一个逻辑运算符; tt 不分开作业。因此state&lt;=s0 &amp;&amp; y==0;state &lt;= (s0 &amp;&amp; (y==0)); 相同y 被视为输入,并且是X,因为它从未分配过。你想要像begin state&lt;=s0; y&lt;=0; end 这样的东西更接近你应该使用的东西。有更多更简洁的方法可以获得您想要的功能,您应该研究一下。

标签: verilog


【解决方案1】:

我想在您的测试平台中指出一些更正,并帮助您找出 RTL 代码中的问题:

  1. clk 必须是 clock

    //  prob558 p558(y,x,clk,reset); <-- clk must be clock
        prob558 p558(y,x,clock,reset);
    
  2. clock 生成必须处于无限循环中

    //#5 clock=~clock; <-- should be inside an infinite loop
    
    initial begin
      forever begin
        #5 clock = ~clock;
      end
    end
    
  3. 在断言一些输入信号之前等待复位

    @(posedge reset); // wait for reset
    
  4. 使用@(posedge clock) 而不是#10 将您的输入同步到clock,并使用非阻塞赋值。

    // #10 x=1; <-- use @(posedge clock) instead and a non-blocking assignment
    // #10 x=0;
    // #10 x=1;
    // #10 x=1;
    // #10 x=1;
    // #10 x=1;
    // #10 x=1;
    // #10 x=0;
    // #10 x=0;
      @(posedge clock) x <= 1;
      @(posedge clock) x <= 0;
      @(posedge clock) x <= 1;
      @(posedge clock) x <= 1;
      @(posedge clock) x <= 1;
      @(posedge clock) x <= 1;
      @(posedge clock) x <= 1;
      @(posedge clock) x <= 0;
      @(posedge clock) x <= 0;
    

您可能想尝试运行上述更正here 并查看波形。

现在您可以尝试修复 RTL 代码的逻辑(输出 y 输出不正确,请参阅 Greg 的评论),因为这是您的作业。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    相关资源
    最近更新 更多