Codiode

Synchronous Up/Down Counter with Load

HardVerilog / SystemVerilogBuild

Design a parameterized synchronous up/down counter in Verilog.

The counter supports four operations in priority order:

  1. Reset — synchronous active-high; forces q to 0 and carry to 0
  2. Load — parallel loads d into q
  3. Count — increments (up_down=1) or decrements (up_down=0) q by 1

Carry / Borrow

carry is asserted for exactly one cycle when the counter wraps around:

  • Overflow: counting up from 2^WIDTH - 1 → wraps to 0, carry = 1
  • Underflow: counting down from 0 → wraps to 2^WIDTH - 1, carry = 1

The counter width is set by parameter WIDTH (default 4).

Priority Table

reset load Action
1 x q = 0, carry = 0
0 1 q = d
0 0 q = q ± 1

Constraints

  • All state changes occur on the rising edge of clk
  • reset has highest priority (synchronous, active-high)
  • load has second priority
  • carry is registered — asserted for one cycle at wrap
  • Parameterized WIDTH must work for any positive integer
  • No latches allowed

Topics

SequentialCounterClock DomainParameterizedRTL Design

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 26 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.