【发布时间】:2015-06-14 19:40:01
【问题描述】:
源代码:
module SingleOneBit(N,T);
parameter integer w; //width or number of inputs N
input wire [w-1:0] N;
output wire T;
wire[w*(w-1):0] N1; //for anding all possible combinations of 2 bits
wire R; // for oring all tha ands. If R = 1 then N contians more than one bit with value 1
wire RS; //ors all the bits of the input. Used for checking if there is one bit with value 1 or all 0s
wire R1; // not of R;
buf(R, 0); //initialy R should be 0;
buf(RS, 0); //initialy RS should be 0;
genvar i, j;
generate
for(i = 0; i<w; i=i+1) begin
or(RS,N[i],RS);
for(j = i+1; j<w; j=j+1) begin
and(N1[(i*w)+j], N[i], N[j]);
or(R,N1[(i*w)+j],R);
end
end
endgenerate
not(R1, R);
and(T,RS,R1);
endmodule
测试台代码:
`include "C:/Users/Muaz Aljarhi/Google Drive/Muaz/Hardware_Designs/Verilog Course/SingleOneBit.v"
module SingleOneBit_tb();
integer n = 5;
reg[n-1:0] N;
wire T;
SingleOneBit sob(.N(N),.T(T));
defparam sob.w = n;
initial begin
$monitor("N = %b, T = %b",N,T);
end
endmodule
编译此 Verilog Testbench 代码会产生以下错误:
** 错误:C:/Users/Muaz Aljarhi/Google Drive/Muaz/Hardware_Designs/Verilog Course/SingleOneBit_tb.v(7):范围 必须以常量表达式为界。 ** 错误:C:/Users/Muaz Aljarhi/Google Drive/Muaz/Hardware_Designs/Verilog Course/SingleOneBit_tb.v(11): defparam 的右边必须是常数。
如何声明可以在测试台中更改的变量或常量表达式?我尝试使用参数,但参数不是可以更改的变量。提前致谢
编辑:我是否必须使用可能不同的输入 reg 变量声明模块的不同实例化,还是有其他方法?
我也试过这个:
SingleOneBit sob(.N(N[0]),.T(T));
defparam sob.w = 32'd5;
但使用 modelsim 进行模拟会产生以下结果:
# ** Error: (vopt-2293) The parameter 'w' in the instance ('/SingleOneBit_tb/sob') of ('SingleOneBit') is declared without a value,
#
# and the instantiation does not provide a value for this parameter.
如何避免在模拟时出现此错误?再次感谢。
【问题讨论】:
标签: verilog simulation hdl modelsim