Codiode

Overriding Parameters via Hash Parentheses

MediumVerilog / SystemVerilogBuild3 solved

Reusing a block usually means changing a parameter, not editing its code. The #( ) syntax at instantiation is how you do it.

A generic counter module named generic_counter is provided in the environment. It has a default parameter WIDTH set to 8. The top-level solution module must instantiate this generic counter, override its WIDTH parameter to 16 using hash-parentheses syntax, and connect the top-level ports to the counter instance. The counter increments by one on every positive clock edge where the enable signal is asserted.

  • Clock edge: posedge clk
  • Reset type: Asynchronous
  • Reset polarity: Active-low rst_n
  • Reset behavior: Output out clears to 16'b0
  • Priority: Reset takes priority over enable

Cycle 1: rst_n=0 → out=0
Cycle 2: rst_n=1, en=1 → out=1
Cycle 3: en=1 → out=2
Cycle 4: en=0 → out=2 (hold)

Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst_n input 1 Asynchronous active-low reset; clears out to 0
en input 1 Enable signal; increments counter when 1
out output 16 Current count value; resets to 16'b0

Constraints

  • Instantiate generic_counter exactly once.
  • Use the #(.PARAMETER_NAME(value)) syntax to override the width to 16.
  • The output must be exactly 16 bits wide.
  • Do not write the counter logic from scratch; rely entirely on the instantiated module.

Topics

CountersParametersVerilog SyntaxInstantiation

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Verilog Syntax and Language Basics

Problem 8 of 25 in the Verilog Syntax and Language Basics track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.