consider i need to design a module with two submodule with same function but different bitwidth input, how i gonna define in higher level module?
For example adder1 is addition of 2bit, adder2 is addition of 4bit. how do i assign 'WIDTH' in higher level module?
module sum()
adder #(.WIDTH()) adder1( //2bit +2bit =2bit - This shows you are using default value of WIDTH, and you did not forget about it
.a(input1),
.b(input2),
.c(output1),
);
adder #(.WIDTH(4)) adder2( //4bit +4bit =4bit
.a(input3),
.b(input4),
.c(output2),
);
endmodule
Also for your module declaration, use this simpler style; you only mention the port names once.
Code:
module #(WIDTH = 2) //default value
(input [WIDTH-1:0] a,
input [WIDTH-1:0] b,
output [WIDTH-1:0] c
);
assign c=a+b;
endmodule