CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Sequential Logic

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 a real testbench — you get the waveform back, not a stored answer.

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

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Basic D Flip FlopEasy
  • Debug: Missing Edge in Sensitivity ListMedium
  • Read After Write Hazard DetectionEasy
  • Parameterized Interface with ModportsHard
  • Struct Array PipelineHard
  • T Flip Flop from D Flip Flop TemplateEasy
  • Recursive Generate Reduction TreeHard
  • Four Stage Shift RegisterEasy

Browse all problems · Learning tracks