Verilog 中的二对一多路复用器因无法绑定 case 语句而出错?
Two to one mux in Verilog giving errors for unable to bind for a case statement?
编译器错误:
lastname_dp.v:17: error: Unable to bind parameter sel' in
testbench.dpTWOTOONEMUX'
lastname_dp.v:17: error: Cannot evaluate genvar case expression: sel
代码:
module twotoonemux(input wire [31:0] input1, input wire [31:0] input2, input wire sel,
output wire [31:0] outputval);
case(sel)
0: assign outputval = input1; //if sel is 0, first input is taken
1: assign outputval = input2; //if sel is 1, second input is taken
endcase
endmodule
测试平台
//mux
reg [31:0] input1;
reg [31:0] input2;
reg sel;
wire [31:0] outputval;
twotoonemux dpTWOTOONEMUX(input1,input2,sel,outputval);
//2 to 1 MUX
input1 = $urandom % 100;
input2 = $urandom % 100;
sel = 0;
#10
$display("inputs %2d & %2d, sel %1d, output %2d", input1, input2, sel, outputval);
sel = 1;
#10
$display("inputs %2d & %2d, sel %1d, output %2d", input1, input2, sel, outputval);
这些只是一个更大项目的块,如果需要整个项目请告诉我
您的示例中的 case
语句本来可以是 generate 块,只是生成块不能将变量作为 select。在您的情况下 sel
是一个变量(输入线选择)。所以,这是你错误的根源。它既不是生成块,也不是任何其他合法的 verilog 构造。
如果我对你的代码的理解正确,你试图表达如下内容:
assign outputval = sel ? input1 : input2;
上面应该可以正确编译。
编译器错误:
lastname_dp.v:17: error: Unable to bind parameter
sel' in
testbench.dpTWOTOONEMUX'
lastname_dp.v:17: error: Cannot evaluate genvar case expression: sel
代码:
module twotoonemux(input wire [31:0] input1, input wire [31:0] input2, input wire sel,
output wire [31:0] outputval);
case(sel)
0: assign outputval = input1; //if sel is 0, first input is taken
1: assign outputval = input2; //if sel is 1, second input is taken
endcase
endmodule
测试平台
//mux
reg [31:0] input1;
reg [31:0] input2;
reg sel;
wire [31:0] outputval;
twotoonemux dpTWOTOONEMUX(input1,input2,sel,outputval);
//2 to 1 MUX
input1 = $urandom % 100;
input2 = $urandom % 100;
sel = 0;
#10
$display("inputs %2d & %2d, sel %1d, output %2d", input1, input2, sel, outputval);
sel = 1;
#10
$display("inputs %2d & %2d, sel %1d, output %2d", input1, input2, sel, outputval);
这些只是一个更大项目的块,如果需要整个项目请告诉我
您的示例中的 case
语句本来可以是 generate 块,只是生成块不能将变量作为 select。在您的情况下 sel
是一个变量(输入线选择)。所以,这是你错误的根源。它既不是生成块,也不是任何其他合法的 verilog 构造。
如果我对你的代码的理解正确,你试图表达如下内容:
assign outputval = sel ? input1 : input2;
上面应该可以正确编译。