源代码:
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:/User/Muaz Aljarhi/Google /Muaz/Hardware_Designs/Verilog Course/SingleOneBit_tb.v(7):范围必须以常量表达式为界。**错误: C:/Users/Muaz Aljarhi/Google Drive/Muaz/hand_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.如何避免在仿真中出现此错误?再次感谢。
发布于 2015-06-15 16:23:02
由于参数是编译时(从技术上讲是精化时间)常量,因此在执行过程中不能更改它们。因此,将sob.w设置为n的第一个错误无效,因为在精化阶段(在进行仿真之前,编译整个设计的一部分),n不能确定为固定值。
第二个错误是SingleOneBit模块sob的声明没有定义hte w参数的结果。稍后使用defparam定义它时,需要提供一些w的默认值。通过更改w的声明以包含默认值,您可以在模块本身中做到这一点:
parameter integer w = 32'd5;因为您似乎想测试这个模块的各种宽度,所以我看不出有什么方法不声明这个模块的多个宽度。当然,您可以使用generate语句来简洁地生成这些不同宽度的模块;但我非常肯定,在模拟过程中没有任何方法可以更改参数。
编辑:我忘了提到defparam结构可能会从语言中被删除( in 1809-2009和code 1800-2012都将其列为将来可能被淘汰的东西),所以您应该避免使用它来允许您的代码与未来的工具兼容。
发布于 2015-06-15 16:21:40
编译器在模块实例化时需要一些参数值。提供"SingleOneBit“中的默认参数值,如下所示:
parameter integer w= 12345;稍后,您可以用"defparam“来更改它。
也可以在实例化表达式中设置参数,如下所示:
SingleOneBit #(12345) sob(.N(N[0]),.T(T));https://stackoverflow.com/questions/30833708
复制相似问题