Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
    • Classic Brain Teasers
    • Probability Puzzles
    • Digital Logic Puzzles
      • Build XOR Using Only 2:1 MUXes
      • AND/OR/NOT from One 2:1 MUX Each
      • Minimum NAND Gates for XOR
      • Overlapping 1011 Sequence Detector
      • Mod-6 Counter Behavior Check
      • Metastability MTBF Improvement Estimate
    • Debugging Riddles
    • Logic & Aptitude Puzzles: Tricky Q&A
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Digital Logic Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Logic & Aptitude Puzzles
  4. Digital Logic Puzzles
  5. Mod-6 Counter Behavior Check

VLSI DV Interview Puzzles · All levels

Mod-6 Counter Behavior Check

Analyze this RTL and state the sequence and period of q. Also identify one synthesis-safe improvement.

On this page

    Puzzle

    Difficulty: Medium · Puzzle 5 of 6 · Topic: Digital Logic Puzzles

    Analyze this RTL and state the sequence and period of q. Also identify one synthesis-safe improvement.

    Code

    design.sv
    1
    2
    3
    4
    5
    always_ff @(posedge clk or negedge rst_n) begin
      if (!rst_n)      q <= 3'd0;
      else if (q == 3'd5) q <= 3'd0;
      else             q <= q + 3'd1;
    end

    Hint

    Trace q values cycle by cycle from reset.

    Step-by-step solution

    Diagram
    1) Starting from reset q=0.
    2) On each clock: 0,1,2,3,4,5 then wrap to 0.
    3) So modulus (period in states) is 6.
    4) Values 6 and 7 are unreachable in normal operation.
    5) Improvement: add explicit recovery for illegal states (q>5) to 0 for robustness after X-corruption or partial reset.

    Answer

    Answer: q cycles 0->1->2->3->4->5->0 with period 6; add illegal-state recovery for safety.

    Why candidates get it wrong

    Calling it a 3-bit free-running counter (mod-8) without reading the compare branch.

    Interviewer follow-up

    How would you implement a glitch-free terminal-count pulse for q==5?

    Related topics

    • Back to Digital Logic Puzzles

    • Logic & Aptitude Puzzles section

    Previous

    171 / 210

    Next: Metastability MTBF Improvement Estimate

    Up next

    Up nextMetastability MTBF Improvement Estimate

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Build XOR Using Only 2:1 MUXes
    • AND/OR/NOT from One 2:1 MUX Each
    • Minimum NAND Gates for XOR