Free Running Up Counter
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:
countbecomes4'b0000 - Priority: Reset has the highest priority. If
rst_nis 0, the output evaluates to 0 regardless of the state ofen.
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'b1111to4'b0000without requiring an explicit reset. countmust be a registered output.- The module must handle enable de-assertion by holding the exact value from the previous clock cycle.
Topics
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