0

我正在尝试构建一个由数据路径单元和控制单元组成的有限状态机自动售货机。附加的链接是控制单元,它由 EQ(Equal)、GT(Greater) 和产品的输入组成。当 product 为“1”且 EQ 或 GT 为“1”时,输出将为 out=product。但是,在我的问题中,verilog 代码显示正确的 GT 但不是 EQ。似乎输出在高电平时无法响应 EQ。

我设计的状态图。 状态图

我的 Verilog 代码。Verilog 代码

结果。结果波形

module dispense(
  input [1:0] product,
  input GT, EQ, rst, clk,
  output [1:0] out,
  output reg done,
  output R
  );
  reg [1:0] ps,ns; //Present State and Next State
  assign R=EQ||GT;
  //State encoding
  parameter [1:0] S0=2'b00, S1=2'b01, S2=2'b10;
  //Verilog segment Next State logic and Output logic
  always @*
    begin
     //out=0;
     done=0;
     case(ps)
       S0: if(product>0) ns=S1; else ns=S0; 
        S1: if(R) ns=S2; else ns=S1;
        S2: begin  done=1; ns=S0; end
        endcase
      end
        //out=product;
    
    assign out = (done==1)?product:0;

    //State Register
    always@(posedge clk)
        if (!rst) ps=S0;
        else ps=ns;
endmodule
4

1 回答 1

0

答案很简单。ps将和添加ns到您的模拟图表中,您就会明白为什么。

在模拟开始时,您处于状态S0。当product大于0(第一个黄色标记)时,您进入 state S1。然后您正在等待EQor GT,但EQ在一个时钟周期前下降,所以下一个GT到达。

设置EQGT一个时钟周期后。

于 2021-05-19T16:00:45.670 回答