Clock Generators
Glitch-Free Clock Select 2 — L2 Upgrade
Glitch-free clock selector with busy indicator for two asynchronous clock sources.
About this block
Simulate it in the Verilog IDE
Glitch-Free Clock Select 2 — L2 Upgrade is a Verilog reference block in the Clock Generators catalog. Clock dividers, gating, and clock distribution helpers. Marked Hard: a larger reference. Simulate the packaged testbench before you change the RTL.
This IP provides a simple, glitch-free clock selector for two asynchronous input clocks (clk_a and clk_b). It ensures safe switching between clock sources by gating the inputs with enable signals derived from a selection control (sel). A busy output signal indicates when the clock output is stable and valid, which is high after reset deassertion.
This module is classified as Level 2 difficulty, suitable for educational purposes and basic clock domain management.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Glitch-Free Clock Select 2 — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: Glitch-free clock selector with busy indicator for two asynchronous clock sources.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- Glitch-Free Switching: Uses enable logic to prevent output glitches during clock source transitions.
- Asynchronous Support: Handles clock sources with different frequencies and phases.
- Busy Indicator: Provides a
busysignal that goes high after reset, indicating the output clock is valid. - Simple Interface: Minimal port count for easy integration.
Ports
| Port | Direction | Width | Description |
|---|---|---|---|
clk_a | Input | 1 | Primary clock input |
clk_b | Input | 1 | Secondary clock input |
sel | Input | 1 | Selection control (1 = clk_a, 0 = clk_b) |
rst_n | Input | 1 | Active-low synchronous reset |
clk_out | Output | 1 | Selected glitch-free clock output |
busy | Output | 1 | High when clock output is valid (high after reset) |
Architecture
The module implements a glitch-free mux using enable gating. Two enable registers (en_a and en_b) are driven by their respective clock domains. The sel signal controls these enables:
- If
selis high,en_ais asserted, allowingclk_ato pass through an AND gate. - If
selis low,en_bis asserted, allowingclk_bto pass through an AND gate. - The outputs of these AND gates are ORed together to produce
clk_out.
This structure ensures that only one clock path is active at any time, preventing glitches. The busy signal is set high immediately after the reset rst_n is deasserted, indicating that the clock output is stable.
Verification
The provided testbench verifies the following behaviors:
- Reset behavior:
busygoes high after reset deassertion. - Clock selection:
clk_outfollows the selected clock source. - Transition stability:
busyremains high during switches.
### Expected Simulation Results
After running the simulation, the log should display:
TC1 PASS: busy high after resetTC2 PASS: clk_out follows clk_aTC3 PASS: clk_out follows clk_bTC4 PASS: busy high during A->B switchTC5 PASS: busy high during B->A switchINFO: PASS
More in Clock Generators
- 1-Cycle Data Delay
- 16-Bit DDS Phase Accumulator — L2 Upgrade
- 2:1 Clock Divider (Toggle Flip-Flop)
- 4-Phase Clock-Enable Sequencer — L1 Upgrade — L2 Upgrade
- Burst Enable for N Cycles — L1 Upgrade — L2 Upgrade
- CE Pulse Every N Cycles
- Clock Enable with Soft-Reset Stretch — L2 Upgrade
- Clock-Enable Divider (CE Pulse) — L1 Upgrade — L2 Upgrade
- Clock-Enable Stretcher N — L1 Upgrade — L2 Upgrade
- Divide-by-3 Clock (50% Duty)
- Dual-Edge DDR Sampler — L2 Upgrade
- Duty-Correct Divide-by-2 — L1 Upgrade — L2 Upgrade
- Fractional Clock Divider with Jitter Control
- Fractional Clock Enable M/N — L2 Upgrade
- Integer Clock Divider
- Lost-Clock Detector — L2 Upgrade