Week 3 · Day 11 · 7 hours

Verilog RTL II – Reuse

Parameterization, FSM, memories, FIFO, arbiter, interrupts

Daily plan

What you will learn and practise

Complete the stages in order and retain the requested evidence.

Theory · 2h

parameter/localparam
Functions and tasks
generate-for / generate-if
Hierarchical reusable RTL
Compile-time configuration

Guided lab · 2h

1. Parameterized adder/MUX/comparator
2. Parameterized register/counter
3. Arithmetic/parity functions
4. Stimulus task
5. Generate register bank

Independent lab · 2h

6. Generate adder array
7. Conditional generate
8. Multi-channel configurable design
9. WIDTH 8/16/32 reuse challenge
10. Parameter override at instantiation

Debug and assignment · 1h

Fix bad parameter widths and generate conditions
Create reusable RTL package folder

Expected deliverable

Reusable parameterized RTL set

Practical work

Create reusable configurable RTL using parameters, localparams, functions, tasks and generate constructs.

Setup
  1. Create project_workspace/week3_verilog_rtl2/day11_reuse with rtl, tb, sim and logs directories.
  2. Use Icarus Verilog for compile/simulation and GTKWave when waveform evidence is useful.
  3. Keep WIDTH configurations 8, 16 and 32 available for reuse testing.
Execution steps
  1. Implement parameterized adder, MUX and comparator blocks.
  2. Implement parameterized register and counter blocks.
  3. Create arithmetic/parity functions and a reusable stimulus task.
  4. Build a generated register bank.
  5. Build a generated adder array and conditional-generate example.
  6. Create one configurable multi-channel design.
  7. Override parameters at instantiation and test WIDTH 8/16/32.
Written assignment
  1. Differentiate parameter and localparam.
  2. Explain elaboration-time generate-for and generate-if.
  3. State when a function is preferable to duplicated combinational expressions.
  4. Explain the role of tasks in reusable simulation stimulus.
  5. Describe two width-related defects that can break reusable RTL.
Debug challenge

Repair bad parameter widths and incorrect generate conditions, then document why each failure occurred.

Evidence to retain
  • Reusable RTL source
  • testbench
  • 8/16/32 simulation results
  • debug notes
  • written answers
Completion criteria
  • All configured widths compile
  • Required configurations simulate correctly
  • No hard-coded width dependency remains in the reusable blocks
Executable lab

Build, run and retain evidence

project_workspace/week3_verilog_rtl2/day11_reuse/

Required files
    Mandatory tests
      Compile
      Run
      Waveform
      PASS criteria
        Knowledge check

        Review before completing Day 11

        1. Concept

          What is the practical difference between parameter and localparam in reusable RTL?

          Review answer

          A parameter is intended to be overridden when a module is configured or instantiated; a localparam is an internal constant that cannot be overridden from outside the module.

        2. RTL reasoning

          A module has parameter WIDTH=8 but an internal temporary is declared [7:0]. What can happen when WIDTH is overridden to 16?

          Review answer

          The fixed 8-bit temporary can truncate or corrupt 16-bit values. Internal widths that depend on configuration should normally be derived from WIDTH or another appropriate parameter/localparam.

        3. Debugging

          Why is using a runtime input signal as the condition of generate-if incorrect?

          Review answer

          Generate constructs are elaboration-time structural choices and require constant expressions. Runtime behavior must be implemented with normal RTL logic rather than generate-if.

        4. Short answer

          Why should a reusable block be tested at WIDTH 8, 16 and 32 rather than only at its default width?

          Review answer

          Multiple configurations expose hidden hard-coded slices, width mismatches, truncation and loop-bound assumptions that may not appear at the default width.

        Skills and assessment traceability

          Assessment: