I want to define an add
module which has a modified parameter in my declaration of the new instance but it doesn't go well.
It is in Verilog. I want to define an instance of this module:
module add #(parameter wd=1) (input wire [wd-1:0] a,b, output wire [wd-1:0] o);
assign o = a + b;
endmodule
I tried this line but I get an error:
add len_plus_1 #(8)(.a(len),.b(8'h1),.o(lenPlus1));
Best Answer
You've got the order wrong. When using module-instance parameter value assignment (the rather wordy terminology for this method), the syntax is:
where the parameter assignment can be by name or by the order of the values. You're already familiar with the module terminal list, so I'll just give the parameter BNF:
So your example should be one of the following:
The former (named) version is preferred, because it maintains its behavior if you add another parameter.
The following example gives additional options (this is adapted from Figure 9-4 in Verilog HDL: A Guide to Digital Design and Synthesis by Palnitkar)
There is also another method which uses the
defparam
keyword to define the values before instantiation like this:but that's considered poor style (though personally, I'd prefer it to the values-by-order syntax).