Verilog仲裁器电路未产生预期的输出

问题描述 投票:-1回答:1

我的仲裁模块设置如下:

// Code your design here
module arbiter#(parameter WIDTH=3)(
    input clk,rst,
    input [WIDTH-1:0] in,
    output reg [WIDTH-1:0] out
    ); 
    parameter IDLE=3'b0,G1=3'b001,G2=3'b010,G3=3'b100;
    reg [WIDTH-1:0] state;    
    wire [WIDTH-1:0] nextState;    

  always@(posedge clk)
     if (rst==1'b1)begin
       state<=3'b000;
       out=3'b000;
     end else begin
      case (state)
    IDLE:if (in==3'b000) begin
            state=IDLE;
            out=IDLE;
        end else if (in == 3'b001)begin
             state=G1;
             out=G1;
        end else if (in == 3'b010 | in==3'b011) begin
            state=G2;
            out=G2;
        end else if (in == 3'b100 | in==3'b101| in==3'b110| in==3'b111) begin
            state=G3;
            out=G3;
        end

   G1:if (in==3'bxx1) begin
            state=G1;
            out=G1;
        end else if (in==3'bxx0)begin
            state=IDLE;
            out=IDLE;
        end

    G2:if (in==3'bx0x) begin
             state=IDLE;
             out=IDLE;
        end else if (in==3'bx1x)begin
              state=G2;
              out=G2;
        end

     G3:if (in==3'b1xx) begin
               state=G3;
               out=G3;
        end else if (in==3'b0xx)begin
                state=IDLE;
                out=IDLE;
         end

endcase

end

endmodule

我的测试台如下:

module basic_and_tb();

  reg [2:0] a;
  wire [2:0] out;
  reg clk,rst;

  arbiter uut(.clk(clk),.rst(rst),.in(a),.out(out));

  initial clk=1'b0;

  always #5 begin
    clk=~clk;
  end

  initial begin
    rst=1'b1;
    #10rst=1'b0;
    a=3'b000; $display("%b",out);
    #10 a=3'b010; $display("%b",out);
    #30 a=3'b011; $display("%b",out);
    #10 a=3'b000; $display("%b",out);
    #10 a=3'b100;$display("%b",out);
    #10 a=3'b101;$display("%b",out);
    #20 a=3'b011;$display("%b",out);
    #20 a=3'b010;$display("%b",out);
    #20 a=3'b000;$display("%b",out);
    #10 a=3'b100;$display("%b",out);
    #20 a=3'b000;$display("%b",out);
    #1 $display("%b",out);
    #10 $finish;
  end

endmodule

但是,我得到的输出是

000
000
010
010
010
010
010
010
010
010
010
010

在任何时间点,只有输出的一位高。当一个当请求输入在空闲状态下被断言时,电路应通过断言输出的相应位来批准该请求。它应保持高电平,直到相应的输入位被置为无效为止,此时电路应进入空闲状态。如果有多个输入位断言,将授予最高优先级的请求,最左边的位具有最高优先级。但是,我的输出始终保持在010。出了什么问题?

verilog hdl test-bench
1个回答
0
投票

您的状态机陷入状态G2('b010),因为要移出该状态的条件要求in具有x。但是,您始终使用已知值驱动in。也许您的意思是:

G2:if (~in[1]) begin
         state=IDLE;
         out=IDLE;
    end else begin
          state=G2;
          out=G2;
    end

状态G1和G3需要类似的更改。

© www.soinside.com 2019 - 2024. All rights reserved.