A parameter is an elaboration-time constant that an instance may override. A localparam is a derived or internal constant that should not be overridden directly. Use parameters to expose the intended configuration interface, then derive internal widths and encodings with localparams so related quantities cannot accidentally disagree.
Worked example
WIDTH is configurable, while MAX_VALUE follows from that width. Repeating one bit WIDTH times constructs the maximum unsigned value without relying on a machine-sized unsized shift. The module reports whether its input equals that limit.
module limit_check #(parameter WIDTH=8)(input [WIDTH-1:0] value,output at_max);
localparam [WIDTH-1:0] MAX_VALUE={WIDTH{1'b1}};
assign at_max=(value==MAX_VALUE);
endmodule
What to watch for
Exposing every derived constant as an independent parameter makes invalid combinations easier to create. Publish a small configuration contract and derive the rest.
Try it yourself
Should an instance override a localparam through a normal parameter override?
Answer: No. localparam expresses an internal constant. Override the public parameters from which the internal constant is derived.
How to study this topic
Save the example in a .v file and identify its top module before compiling. Separate stimulus and observation from synthesizable RTL. Change one input, width or boundary condition at a time, predict the result, and compare that prediction with simulation. A syntax check does not establish synthesis support or timing closure.
Continue learning
Previous: Pipelining and latency
Next: Generate loops and conditional generation
Browse the complete Verilog index
Explore related programmes
These recorded programmes are upcoming. This article is general educational content, not a syllabus or course sample.
Verilog