RTL Studio Open IDE

Edge, Debounce & Pulse

Both-Edge Detector — L1 Upgrade

Both-edge detector with N-cycle hold pulse generation.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Both-Edge Detector — L1 Upgrade is a Verilog reference block in the Edge, Debounce & Pulse catalog. Edge detectors, debouncers, pulse stretchers, and one-shot generators. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This IP implements a both-edge detector with a configurable N-cycle hold pulse. It detects rising and falling edges on the input signal in. Upon edge detection, the output pulse remains high for a specified number of clock cycles. The hold duration is controlled by the hold_n input port.

This IP provides a robust solution for detecting signal edges with a configurable pulse width. It is suitable for applications requiring debouncing or pulse stretching. The design is simple, efficient, and fully verified.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Both-Edge Detector — L1 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Both-edge detector with N-cycle hold pulse generation.
  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

  • Both-Edge Detection: Detects both rising and falling edges on the input signal.
  • Configurable Pulse Width: The hold_n parameter (4-bit width, max 15 cycles) controls the pulse duration.
  • Synchronous Reset: Active-low synchronous reset (rst_n).
  • Simple Logic: Efficient synchronous logic implementation using a shift register and counter.
  • Self-Checking Testbench: Includes a comprehensive testbench with automated pass/fail reporting.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low synchronous reset
inInput1Input signal to monitor for edges
hold_nInput4Number of cycles to hold pulse high (0-15)
pulseOutput1Output pulse signal

Architecture

The module uses a shift register approach to detect edges by comparing the current input with the previous clock cycle's input. A counter decrements when an edge is detected and the pulse is active. The pulse remains high until the counter reaches zero.

Verification

The testbench verifies the following scenarios:

Test CaseDescriptionResult
TC1Reset check ensures pulse is low initially.PASS
TC2Rising edge detection with hold N=2.PASS
TC3Falling edge detection with hold N=2.PASS
TC4No edge condition results in no pulse.PASS
TC5Hold N=0 results in 1-cycle pulse.PASS

All tests passed successfully. Simulation logs confirm correct behavior for all edge cases.

More in Edge, Debounce & Pulse

All Edge, Debounce & Pulse blocks