Codiode

Latch-Based Clock Gating Cell

MediumVerilog / SystemVerilogBuild

Gating a clock saves power, but ANDing it with an enable makes a glitch if the enable changes while the clock is high.

A standard glitch-free clock gating cell solves this by synchronizing the enable signal. The circuit uses a negative-level sensitive latch to hold the enable signal steady during the high phase of the clock. The latched enable is then ANDed with the source clock to produce the gated clock. This ensures the output clock transitions cleanly and safely.

Timing and Reset Rules:

  • Latch transparency: The internal latch is transparent when clk is 0; it directly passes the en signal.
  • Latch hold: The internal latch holds its current value when clk is 1, ignoring any changes on en.
  • Output logic: The gated_clk output is a combinational AND of clk and the internal latched enable.
  • Reset: There is no explicit reset pin; the latch assumes the value of en when clk is 0.

Worked Trace:

Step 1: clk=0, en=1 → latched_en=1, gated_clk=0
Step 2: clk=1, en=1 → latched_en=1 (hold), gated_clk=1
Step 3: clk=1, en=0 → latched_en=1 (hold), gated_clk=1 (glitch prevented)
Step 4: clk=0, en=0 → latched_en=0, gated_clk=0
Step 5: clk=0, en=1 → latched_en=1, gated_clk=0
Step 6: clk=1, en=1 → latched_en=1 (hold), gated_clk=1

Port Table:

Signal Direction Width Description
clk input 1 Source clock
en input 1 Clock enable signal
gated_clk output 1 Gated output clock

Constraints

  • Must infer a negative-level sensitive latch for the internal enable signal.
  • Do not use edge-triggered flip-flops (posedge or negedge).
  • The output gated_clk must be the continuous logical AND of clk and the latched enable.
  • All ports are 1-bit wide.

Topics

Clock Domain CrossingLatchesPower Management

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

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.

Part of Clock Domain Crossing and Synchronization

Problem 8 of 36 in the Clock Domain Crossing and Synchronization track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.