RTL Studio Open IDE

Control & Timers

Enable-Gated Set/Reset Flag

Enable-Gated Set/Reset Flag with priority clearing and hold state.

About this block

Simulate it in the Verilog IDE

Easyverilogsimsyn

Enable-Gated Set/Reset Flag is a Verilog reference block in the Control & Timers catalog. FSMs, timers, watchdogs, and control/state sequencing blocks. Marked Easy: a small block you can read, simulate, and synthesize in one sitting.

This IP implements a single-bit registered flag with enable-gated set and clear operations.

It features a priority mechanism where the clear signal takes precedence over the set signal when both are asserted simultaneously.

The flag state is held constant when the enable signal is low, regardless of set/clear inputs.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Enable-Gated Set/Reset Flag.
  2. Read the Verilog module in the editor. The catalog line for this block: Enable-Gated Set/Reset Flag with priority clearing and hold state.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. 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

  • Enable Gating: State updates (set/clear) only occur when en is high.
  • Priority Clear: If both set and clr are high, the flag is cleared.
  • Asynchronous Reset: The flag initializes to 0 on rst_n assertion.
  • Hold State: When en is low, the flag retains its previous value.
  • Fully Verified: Includes a comprehensive testbench covering all operational modes.

Architecture

The design utilizes a single D-type flip-flop for state storage. The logic is synchronous to the rising edge of clk but includes an asynchronous reset path.

  • Logic Equation:

- If !rst_n: flag <= 0 - Else if en: - If clr: flag <= 0 - Else if set: flag <= 1 - Else: flag <= flag (Hold) - Else: flag <= flag (Hold)

Ports

PortDirectionWidthDescription
clkInput1Clock input (rising edge triggered)
rst_nInput1Active-low asynchronous reset
enInput1Enable signal; gates set/clear operations
setInput1Set command (active high)
clrInput1Clear command (active high)
flagOutput1Registered flag output

Verification

The provided testbench (tb_sr_flag_en) verifies the following scenarios:

Test CaseDescriptionExpected Result
TC1Reset Initializationflag becomes 0
TC2Set Flag Operationflag becomes 1
TC3Clear Flag Operationflag becomes 0
TC4Hold State with en=0flag remains unchanged
TC5Gated Set with en=0flag remains unchanged
TC6Enable and Setflag becomes 1
TC7Clear Wins Over Setflag becomes 0 when both set/clear are active

Run the simulation to verify all test cases pass.

More in Control & Timers

All Control & Timers blocks