Basic Clock Enable Register
To stall a register, don't gate its clock; give it an enable. The register then simply keeps its value on cycles when the enable is low.
The solution module captures the input data on the rising edge of the clock only when the enable signal is asserted. When the enable is de-asserted, the module retains its current value, ignoring any changes on the data input.
The module is driven by a positive-edge triggered clock clk and an asynchronous active-low reset rst_n. On reset, the output q must be cleared to 0. The reset signal has the highest priority; if rst_n is asserted, the output must clear immediately regardless of the state of the clock or the enable signal.
Cycle 1: rst_n=0 → q=0
Cycle 2: rst_n=1, en=1, d=170 → q=170
Cycle 3: rst_n=1, en=0, d=187 → q=170 (hold)
Cycle 4: rst_n=1, en=1, d=204 → q=204
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; output goes to 0 when asserted |
en |
input | 1 | Active-high enable; register captures d on posedge clk when en=1 |
d |
input | 8 | Data input |
q |
output | 8 | Data output; resets to 8'b00000000 |
Constraints
- The module must trigger on the positive edge of
clk. - The reset
rst_nmust be asynchronous and active-low. - Output
qmust initialize to8'b00000000on reset. - The enable logic must be implemented in the data path rather than gating the clock signal.
- Reset has priority over the enable signal.
Topics
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 Sequential RTL
Problem 9 of 26 in the Sequential RTL track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks