BitFlow

Ring Counter

intermediate · sequential · 140 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

Ring Counter A **ring counter** is a circular shift register where the output of the last flip-flop is fed back into the input of the first. Exactly **one bit is high at a time** (one-hot), and it rotates around the register on each clock cycle. Implement a 4-bit ring counter: | Cycle | q[3:0] | |-------|--------| | Reset | 0001 | | 1 | 0010 | | 2 | 0100 | | 3 | 1000 | | 4 | 0001 | ← wrapped back **Interface** | Port | Direction | Width | Description | |-----------|-----------|-------|-------------------------| | `clk` | input | 1 | Clock | | `rst` | input | 1 | Synchronous reset | | `q[3:0]`| output | 4 | One-hot state output | **Key property:** Unlike a binary counter, the ring counter has only N states for N bits (not 2^N), but its outputs are **already decoded** — each bit directly indicates which state is active. Used in control sequencers and state machines.

Constraints

  • Reset loads 4'b0001 (LSB high).
  • Each clock: shift left, MSB wraps to LSB.
  • Exactly one bit is high at all times.

Examples

Input: After reset

Output: q=4'b0001

Input: 1 clock later

Output: q=4'b0010

Input: 4 clocks later

Output: q=4'b0001 (full rotation)

Common questions

What does the Ring Counter problem ask you to build?
Ring Counter A **ring counter** is a circular shift register where the output of the last flip-flop is fed back into the input of the first. Exactly **one bit is high at a time** (one-hot), and it rotates around the register on each clock cycle.
What constraints does Ring Counter have?
Reset loads 4'b0001 (LSB high).; Each clock: shift left, MSB wraps to LSB.; Exactly one bit is high at all times.
What is an example input and output for Ring Counter?
Input After reset gives output q=4'b0001.
Which Verilog concepts does Ring Counter practise?
sequential, counter, ring, one-hot, shift-register.