Reputation: 23
I am trying to create multiple adders via Verilog to compare the speed of each adder.
I am getting the following error Unable to bind parameter WIDTH in arith_unit
This is my code so far:
module arith_unit
#(
parameter ADDER_TYPE = 0,
parameter WIDTH = 8)
(input [WIDTH-1:0] a,
input [WIDTH-1:0] b,
output [WIDTH-1:0] sum,
);
////////////////////////////////////////////////////////////////
if (ADDER_TYPE == 0)
begin
ripple_carry rc1 (a, b, cin, sum, cout);
end
////////////////////////////////////////////////////////////////
else if (ADDER_TYPE == 1)
begin
carry_bypass cb1 (a, b, cin, sum, cout);
end
//// more else statment for ADDER_TYPE...
endmodule
//////////////////////////////////////////////////////////////////
module ripple_carry_4_bit(a, b, cin, sum, cout);
input [3:0] a,b;
input cin;
wire c1,c2,c3;
output [3:0] sum;
output cout;
full_adder fa0(.a(a[0]), .b(b[0]),.cin(cin), .sum(sum[0]),.cout(c1));
full_adder fa1(.a(a[1]), .b(b[1]), .cin(c1), .sum(sum[1]),.cout(c2));
full_adder fa2(.a(a[2]), .b(b[2]), .cin(c2), .sum(sum[2]),.cout(c3));
full_adder fa3(.a(a[3]), .b(b[3]), .cin(c3), .sum(sum[3]),.cout(cout));
endmodule
////////////////////////////////////////////////////////////////
module ripple_carry (a, b, cin, sum, cout);
input [WIDTH-1:0] a,b;
input cin;
wire c1,c2,c3, c4, c5, c6, c7;
output [WIDTH-1:0] sum;
output cout;
if (WIDTH == 8) begin //<-------- compiler is pointing here as the problem
ripple_carry_4_bit rca1 (.a(a[3:0]),.b(b[3:0]),.cin(cin), .sum(sum[3:0]),.cout(c1));
ripple_carry_4_bit rca2 (.a(a[7:4]),.b(b[7:4]),.cin(c1), .sum(sum[7:4]),.cout(cout));
end
else if (WIDTH == 16) begin
ripple_carry_4_bit rca1 (.a(a[3:0]),.b(b[3:0]),.cin(cin), .sum(sum[3:0]),.cout(c1));
ripple_carry_4_bit rca2 (.a(a[7:4]),.b(b[7:4]),.cin(c1), .sum(sum[7:4]),.cout(c2));
ripple_carry_4_bit rca3 (.a(a[11:8]),.b(b[11:8]),.cin(c2), .sum(sum[11:8]),.cout(c3));
ripple_carry_4_bit rca4 (.a(a[15:12]),.b(b[15:12]),.cin(c3), .sum(sum[15:12]),.cout(cout));
end
//// more else statment for 32 & 64 bits...
endmodule
I looked online and it seems that my if and else statements are correct. So I am assuming that my WIDTH
is declared wrong? I tried passing in WIDTH
via module ripple_carry (a, b, cin, sum, cout, WIDTH);
kind of how you would do it with C++, but I still get the same error.
I've tested the ripple_carry
on its own (no if statements, no parameter) with 8 bits, 16 bits, etc. and it works fine. So I know that my logic for the ripple_carry
is fine.
Please help me, thank you.
Upvotes: 0
Views: 1366
Reputation: 42698
It would have helped to show the exact error message with the line number, but you are missing a WIDTH parameter declaration in the module ripple_carry
.
module ripple_carry #(parameter WIDTH=8)(...
And add it when instantiating it inside the generate block.
ripple_carry #(WIDTH) (a, b, cin, sum, cout);
Upvotes: 2