【问题标题】:Verilog multiplexerVerilog 多路复用器
【发布时间】:2021-05-20 15:23:59
【问题描述】:

帮我解决这个问题,下面的问题

创建一个 16 位宽、9 对 1 的多路复用器。 sel=0 选择 a,sel=1 选择 b,等等。对于未使用的情况(sel=9 到 15),将所有输出位设置为 '1'。

解决方案:

module top_module( 
input [15:0] a,b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );
always@(*) begin
    case(sel)
        0:
            out = a;
        1:
            out = b;
        2:
            out = c;
        3:
            out = d;
        4:
            out = e;
        5:
            out = f;
        6:
            out = g;
        7:
            out = h;
        8:
            out = i;
          
        default:
            out = 1;
       
    endcase
end

结束模块

我不知道这段代码有什么问题。可能是全部。

注意:https://hdlbits.01xz.net/wiki/Mux9to1v

【问题讨论】:

  • "All bits to 1" 与输出值(16 位宽)为整数 1 不同。有关指导,请参阅this

标签: verilog system-verilog


【解决方案1】:
module top_module( 
input [15:0] a,b, c, d, e, f, g, h, i,
input [3:0] sel,
output reg [15:0] out
);
always @(*) begin
    case(sel)
        0: out = a;
        1: out = b;
        2: out = c;
        3: out = d;
        4: out = e;
        5: out = f;
        6: out = g;
        7: out = h;
        8: out = i;
        default: out = {16{1'b1}}; //..'1 is not the same in every compiler
    endcase
end
endmodule

【讨论】:

    【解决方案2】:
    1. 您没有 endomdule 关键字(文件意外结束)。
    2. 始终阻止 require reg(程序分配给非注册输出)。不管是同步还是异步always块。
    module top_module( 
        input [15:0] a,b, c, d, e, f, g, h, i,
        input [3:0] sel,
        output reg [15:0] out
    );
    
        always @(*) begin
            case(sel)
                0: out = a;
                1: out = b;
                2: out = c;
                3: out = d;
                4: out = e;
                5: out = f;
                6: out = g;
                7: out = h;
                8: out = i;
                default: out = 1;
            endcase
        end
    
    endmodule
    

    【讨论】:

      【解决方案3】:

      还是谢谢。找到了答案。必须用 '1 将所有输出位填充为 1。

      module top_module( 
      input [15:0] a,b, c, d, e, f, g, h, i,
      input [3:0] sel,
      output reg [15:0] out
      );
      always @(*) begin
          case(sel)
              0: out = a;
              1: out = b;
              2: out = c;
              3: out = d;
              4: out = e;
              5: out = f;
              6: out = g;
              7: out = h;
              8: out = i;
              default: out = '1;
          endcase
      end
      

      结束模块

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-16
        • 1970-01-01
        • 1970-01-01
        • 2020-07-01
        • 1970-01-01
        • 2021-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多