[英]Verilog Testbench constant exp and pram compilation and simulation errors
源代码:
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
Testbench代码:
`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 yeilds以下:
# ** 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.
如何避免在模拟时出现此错误? 再次感谢。
由于参数是编译时(技术上精化时间)常量,因此在执行过程中不能对它们进行更改。 因此, sob.w
被设置为n
的第一个错误无效,因为在sob.w
阶段(编译整个设计的一部分,在进行模拟之前), n
不能被确定为固定值。
第二个错误是声明SingleOneBit
模块sob
未定义hte w
参数的结果。 虽然稍后使用defparam
定义它,但您需要提供一些默认值w
。 您可以通过更改w
的声明以包含默认值来在模块本身中执行此操作:
parameter integer w = 32'd5;
由于您似乎想要测试此模块的各种宽度,我没有看到一种方法不声明此模块的多个宽度。 当然,您可以使用generate语句紧凑地生成各种宽度的模块; 但我非常确定在模拟过程中没有任何改变参数的方法。
编辑:我忘了提到defparam
结构可能会从语言中删除(IEE1800-2009和IEEE1800-2012都将其列为将来可能会被删除的东西),所以你应该避免使用它来允许你的代码兼容未来的工具。
编译器在模块实例化时需要一些参数值。 在“SingleOneBit”中提供默认参数值,如下所示:
parameter integer w= 12345;
之后你可以用“defparam”改变它。
或者您可以在实例化表达式中设置参数,如下所示:
SingleOneBit #(12345) sob(.N(N[0]),.T(T));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.