Source Code:
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 Code:
`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
Compilation of this Verilog Testbench code yeilds the following errors:
** Error: C:/Users/Muaz Aljarhi/Google Drive/Muaz/Hardware_Designs/Verilog Course/SingleOneBit_tb.v(7): Range must be bounded by constant expressions. ** Error: C:/Users/Muaz Aljarhi/Google Drive/Muaz/Hardware_Designs/Verilog Course/SingleOneBit_tb.v(11): Right-hand side of defparam must be constant.
How to declare a variable or a constant experssion which can be changed within a test bench? I tried using parameter but parameters are not variables which can be changed. Thanks in advance
Edit: Do I have to declare different instantiations of the module with possibly different input reg variables or there is another way?
I also tried this:
SingleOneBit sob(.N(N[0]),.T(T));
defparam sob.w = 32'd5;
but simulating, using modelsim yeilds the following:
# ** 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.
How to avoid getting this error at simulation? Thanks again.