yamcake01096
Newbie level 2
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 adder1( //2bit +2bit =2bit
.a(input1),
.b(input2),
.c(output1),
);
adder adder2( //4bit +4bit =4bit
.a(input3),
.b(input4),
.c(output2),
);
endmodule
////////////////////////////////////////////////////////////////
module adder (a,b,c);
parameter WIDTH = 2; //defult value
input [WIDTH-1:0] a;
input [WIDTH-1:0] b;
output [WIDTH-1:0] c;
assign c=a+b;
endmodule
For example adder1 is addition of 2bit, adder2 is addition of 4bit. how do i assign 'WIDTH' in higher level module?
///////////////////////////////////////////////////
module sum()
adder adder1( //2bit +2bit =2bit
.a(input1),
.b(input2),
.c(output1),
);
adder adder2( //4bit +4bit =4bit
.a(input3),
.b(input4),
.c(output2),
);
endmodule
////////////////////////////////////////////////////////////////
module adder (a,b,c);
parameter WIDTH = 2; //defult value
input [WIDTH-1:0] a;
input [WIDTH-1:0] b;
output [WIDTH-1:0] c;
assign c=a+b;
endmodule