BitFlow

Up-Down Counter

intermediate · sequential · 145 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

Up-Down Counter A **synchronous up-down counter** that counts up or down depending on a direction control input. **Interface** | Port | Direction | Width | Description | |-----------|-----------|-------|------------------------------------| | `clk` | input | 1 | Clock — rising edge | | `rst` | input | 1 | Synchronous reset → count=0 | | `en` | input | 1 | Enable | | `up` | input | 1 | 1=count up, 0=count down | | `count[3:0]`| output | 4 | Current count value | **Behaviour on posedge clk:** - rst=1 → count = 0 - en=1, up=1 → count = count + 1 - en=1, up=0 → count = count - 1 - en=0 → count holds Both overflow (15→0) and underflow (0→15) wrap naturally in 4-bit arithmetic.

Constraints

  • Synchronous design — always @(posedge clk).
  • rst > en priority.
  • up=1 increments, up=0 decrements.
  • Use non-blocking assignments (<=).

Examples

Input: up=1, en=1, count=14, clk↑

Output: count=15

Input: up=0, en=1, count=0, clk↑

Output: count=15 (underflow)

Common questions

What does the Up-Down Counter problem ask you to build?
Up-Down Counter A **synchronous up-down counter** that counts up or down depending on a direction control input.
What constraints does Up-Down Counter have?
Synchronous design — always @(posedge clk).; rst > en priority.; up=1 increments, up=0 decrements.; Use non-blocking assignments (<=).
What is an example input and output for Up-Down Counter?
Input up=1, en=1, count=14, clk↑ gives output count=15.
Which Verilog concepts does Up-Down Counter practise?
sequential, counter, up-down, bidirectional, synchronous.