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

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
    • Reset Puzzles
    • Clock Gating & Clock Mux Puzzles
      • AND Gate Fed Straight From a Flop
      • A Latch Makes the Gate Safe
      • Which Gate Wants Which Phase?
      • Switching a Clock Mux With the Select
      • The Glitch-Free Clock Switch
      • Does the Gated Flop See the Old Data?
    • CDC Basics Puzzles
    • Verifying CDC & Reset Puzzles
    • Clock, Reset & CDC Puzzles: Tricky Q&A
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Clock Gating & Clock Mux Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Clock, Reset & CDC Puzzles
  4. Clock Gating & Clock Mux Puzzles
  5. Switching a Clock Mux With the Select
On this page

    VLSI DV Interview PuzzlesAll levels

    Switching a Clock Mux With the Select

    clk_o = sel ? clkb : clka, with clka (period 10, high 5 ns) and clkb (period 6, high 3 ns). sel changes from 0 to 1 at t=7 when clka is high and clkb is low. List the high pulses of clk_o and say whether any is illegal.

    Puzzle

    Difficulty: Medium · Puzzle 4 of 6 · Topic: Clock Gating & Clock Mux Puzzles

    clk_o = sel ? clkb : clka, with clka (period 10, high 5 ns) and clkb (period 6, high 3 ns). sel changes from 0 to 1 at t=7 when clka is high and clkb is low. List the high pulses of clk_o and say whether any is illegal.

    Code

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    `timescale 1ns/1ns
    module tb;
      reg clka = 0, clkb = 0, sel = 0;
      always #5 clka = ~clka;                     // period 10, high 5..10, 15..20
      always #3 clkb = ~clkb;                     // period 6, rises at 3, 9, 15; high for 3 ns each time
      wire clk_o = sel ? clkb : clka;
      integer t_r = -1;
      always @(clk_o)
        if (clk_o) t_r = $time;
        else if (t_r >= 0) $display("clk_o high %0d..%0d width=%0d", t_r, $time, $time - t_r);
      initial begin
        #7 sel = 1;                               // switch while clka is high and clkb is low
        #12 $finish;
      end
    endmodule

    Hint

    At t=7 the mux output was following clka (high) and starts following clkb (low).

    Step-by-step solution

    Diagram
    1) clka rises at t=5, so clk_o rises at t=5.
    2) At t=7 sel switches. clka is high, clkb is low, so clk_o drops from 1 to 0 at t=7: the pulse is only 2 ns wide instead of 5.
    3) clk_o then follows clkb: clkb rises at 9 and falls at 12, a normal 3 ns pulse; the next one is 15..18.
    4) The 2 ns pulse is a runt: shorter than the minimum pulse width of even the faster clock (3 ns), so it is illegal.

    Answer

    Answer: Pulses: 5..7 (width 2), 9..12 (width 3), 15..18 (width 3). The first is an illegal runt: it is below the minimum pulse width (3 ns), created because sel changed while the two clocks were in different states.

    How this was checked

    Checked by running the code in Icarus Verilog 13; the printed output supports the answer above. Icarus: a 2 ns runt pulse appears at the switch.

    Why candidates get it wrong

    Calling this 'just a glitch in simulation'. The same pulse exists in silicon as a runt that can clock flops unreliably or leave them metastable, and zero-delay RTL shows it exactly as it would be, so a bench that checks minimum pulse width after every sel change catches it.

    Interviewer follow-up

    Would the result be safe if sel switched at t=11, when both clocks happen to be low? Model answer: yes for that one instant only (the output is low before and after and the next edge comes from clkb), but it is luck of phase, not a design: the select can change at any phase, so a safe switch needs the proper handshake structure.

    Related topics

    • Back to Clock Gating & Clock Mux Puzzles

    • Clock, Reset & CDC Puzzles section

    Previous

    245 / 293

    Next: The Glitch-Free Clock Switch

    Up next

    Up nextThe Glitch-Free Clock Switch

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • AND Gate Fed Straight From a Flop
    • A Latch Makes the Gate Safe
    • Does the Gated Flop See the Old Data?