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

Gray Code Counter with Non Power of Two Modulus

HardLogic CircuitDebug

A modulo-6 Gray code counter generates a sequence of 6 states for clock domain crossing pointers. The counter must preserve the strict Gray code property across all state transitions.

Expected behavior:

| Cycle | rst | gray_out (Binary) | gray_out (Decimal) | |-------|-------|---------------------|----------------------| | 0 | 1 | 001 | 1 | | 1 | 0 | 011 | 3 | | 2 | 0 | 010 | 2 | | 3 | 0 | 110 | 6 | | 4 | 0 | 111 | 7 | | 5 | 0 | 101 | 5 | | 6 | 0 | 001 | 1 |

The testbench reports a CDC violation during the counter wrap-around. After reaching gray_out = 7 (binary 111), the next clock cycle outputs gray_out = 0 (binary 000). This causes three bits to transition simultaneously. Inspect the circuit and correct the fault.

Constraints

  • The sequence must contain exactly 6 unique states.
  • Exactly one bit must change between any two consecutive states, including the wrap-around.
  • The counter must initialize to the first state of the valid sequence when rst = 1.

Topics

Gray CodeClock Domain CrossingCounters

Solve this problem

Place the gates, wire them up and watch the signals settle. Every submission runs on the same simulation engine that grades it.

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

  • 3-bit Ripple Counter from Toggle Flip-FlopsEasy
  • D Latch from a 2:1 MUXEasy
  • 2-bit Ring CounterEasy
  • T Flip-Flop from a D Flip-FlopEasy
  • Handshake Deadlock Due to Early ResetHard
  • Reconvergence of Individually Synchronized BitsHard
  • Debug: Asynchronous Clear GlitchHard
  • Clock Gate Enable Crossing DomainsHard

Browse all problems · Learning tracks