Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Generate and synchronize a Gray-code counter

Hardware interview practice

Generate and synchronize a Gray-code counter

MediumClock Domain CrossingSystemVerilog

Design a parameterized counter whose exported Gray code changes by one bit per source increment, then synchronize that Gray value into a destination clock domain.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Gray-code counter crossing from a source clock domain through a two-flop destination synchronizer, with one-bit transitions highlighted.
The Gray encoder limits adjacent count transitions to one bit; the destination synchronizer still handles metastability.
Reviewed example

Work through one case

Input
WIDTH=3; enabled source binary counts=[0,1,2,3]
Expected output
registered Gray values=[000,001,011,010]; each appears in destination after two destination edges

Each source increment changes one Gray bit, while the marked two-flop chain still handles metastability before destination use.

What to cover

Requirements

  1. Increment the binary source count by at most one on each enabled source edge.
  2. Register Gray code derived from the next binary value.
  3. Use a two-flop destination synchronizer for every Gray bit and mark the chain for CDC tools.
  4. Explain that Gray coding limits transition ambiguity but does not remove metastability or replace synchronization.
Continue practicing

Related questions

Clock Domain CrossingImplement asynchronous FIFO full and empty logic→Clock Domain CrossingEight-entry asynchronous FIFO→Clock Domain CrossingChoose a safe clock-domain crossing strategy→
asic.fyi · Learn silicon end to end.info@asic.fyi