Codiode

Free Running Up Counter

EasyVerilog / SystemVerilogBuild3 solved

Timers, dividers and timeouts are all counters underneath. The simplest one counts up while enabled and wraps to zero after its maximum.

This module maintains a 4-bit value that increments by one whenever the enable signal is asserted. When the counter reaches its maximum value of 15, the next increment rolls the value back to 0. If the enable signal is de-asserted, the counter holds its current value indefinitely.

  • Clock edge: posedge clk
  • Reset type: Asynchronous, active-low
  • Output on reset: count becomes 4'b0000
  • Priority: Reset has the highest priority. If rst_n is 0, the output evaluates to 0 regardless of the state of en.

Worked Trace:
Cycle 1: rst_n=0, en=X → count=0 (reset)
Cycle 2: rst_n=1, en=1 → count=1 (increment)
Cycle 3: rst_n=1, en=1 → count=2 (increment)
Cycle 4: rst_n=1, en=0 → count=2 (hold)
Cycle 5: rst_n=1, en=1 → count=3 (increment)

Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst_n input 1 Asynchronous active-low reset; drives count to 0 when asserted
en input 1 Enable; counter increments on posedge clk while en=1
count output 4 Current count value; resets to 4'b0000

Constraints

  • The reset must be asynchronous and active-low.
  • The counter must naturally wrap from 4'b1111 to 4'b0000 without requiring an explicit reset.
  • count must be a registered output.
  • The module must handle enable de-assertion by holding the exact value from the previous clock cycle.

Topics

Synchronous LogicRegistersCounters

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 Sequential RTL

Problem 15 of 26 in the Sequential RTL track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

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