我尝试在这个参数化模块上使用
generate
,但我一直得到错误的输出。
module constant_gen #(
parameter [4:0]round = 5'b00
)
(
output [31:0] con
);
assign con = {round};//{round,5'b00000,round,2'b00,round,5'b00000,round} ^ 32'h6547a98b;
endmodule
// Testbench
module constGen_tb;
logic clk_i = 1;
typedef logic [31:0] data_m [20:0];
localparam period = 2;
data_m const_table;
//simulate the clock
always
begin
clk_i= 1; #period; clk_i= 0; #period; // // 40ns period at each clock edge
end
genvar i;
generate
for (i=0; i < 20; i++) begin : con_gen
constant_gen #(.RN(i)) dut (const_table[i]);
end
endgenerate
always @(negedge clk_i)
begin
for (integer i = 0; i <= 20; i = i + 1) begin
$display("const: %h",const_table[i]);
end
$finish;
end
endmodule
输出:
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
const: 00000000
Eda游乐场: 游乐场代码在这里
在您的示例中,参数名称
round
与您在实例化中使用的名称不同:RN
。
这应该有效:
constant_gen #(.round(p)) dut (const_table[i]);
编译中有一个警告,需要注意:
# ELBREAD: Warning: ELBREAD_0097 testbench.sv (21): Parameter 'RN' not found in work.constant_gen instantiated in unit work.const_gen_tb.