Shared parameter for several modules (Verilog)

verilog

I want to define a parameter in Verilog in such a way that several modules will be able to use it.

Each module is implemented in different file.

Can it be done or should I (re)define this parameter in each module ?

Best Answer

If you want to share a parameter among a limited set of modules within your ovarall design, you can define the parameter in an enclosing module, and then pass it into the modules that need it using the following instantiation syntax:

parameter PARAM = value;

module_name #(.PARAM(PARAM)) instance_name ( ... );

Each of the lower-level modules must also declare the parameter, and they can optionally give it a default value as well (which will be overridden by the value passed in during instatiation).