Advanced teams avoid copy-paste modules. Parameters define configurable interfaces, while generate duplicates structure safely.
Read the picture from the top: only the first box is chosen by the caller. Everything below it follows by formula or by elaboration.
Parameter: the one value the parent writes, at the instance, by name.
Localparam: a width computed from it once, such as 2 select bits for 4 lanes.
Generate: the copies of hardware, each with a block name you will see in the netlist.
The benches in this topic are finite digital checks, not physical signoff results.
3 lessons, about 9 min
Lesson | Idea |
|---|---|
One source for every width, with math that survives N equal to 1. | |
Lane replication with | |
Named overrides checked with fill/drain and walking-bit stimulus. |
Only the elaborated widths and replicated logic. The source stays single, so a fix lands in both builds at once.
The whole topic on one page, taken from each lesson's Remember box. Read it before an interview, or print it.
Parameters vs localparams
A parameter is an input to elaboration; a localparam derives from it and cannot be overridden.
Compute each dependent width once, in one localparam formula.
Guard $clog2 for N equal to 1, and require N and WIDTH to be positive.
Rule of thumb: if a value follows from another, make it a localparam, never a second parameter.
Generate loops and conditionals
A generate loop builds N copies of hardware, each under its own block name.
If and case generate pick a structure from an elaboration constant, never from a signal.
Keep the count parameter strictly positive.
Rule of thumb: structure replication is generate; value computation is a procedural loop.
Avoid defparam overrides
Named overrides keep order irrelevant and keep the value at the instance.
defparam sets a value by hierarchical path after instantiation, so the instance site hides it. This course bans it.
Prove an override with behaviour: fill each instance and check that full rises after exactly DEPTH writes.
Rule of thumb: if the value is not visible at the instantiation, a reviewer will not find it.
Mini project: a reusable FIFO IP with package, interface, assertions and a formal check
Code lab: Parameters and localparams
Practice question: Generate-for versus generate-if in a parameterised design
Code lab: Generate loop
Interview: run a mock interview on this topic