Edge, Debounce & Pulse
2-Bit Edge Detector with Edge Type Selection — L1 Upgrade — L2 Upgrade
A 2-bit edge detector with configurable rising/falling edge selection, programmable window timer, hold mode, and sticky flag for event latching.
About this block
Simulate it in the Verilog IDE
2-Bit Edge Detector with Edge Type Selection — L1 Upgrade — L2 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 robust 2-bit edge detector with configurable edge type selection, window gating, hold mode, and a sticky status flag. It is designed for low-latency edge detection in synchronous systems, particularly suitable for L1/L2 upgrade scenarios where precise pulse timing and event logging are critical.
This IP provides a flexible and reliable 2-bit edge detection solution capable of detecting rising or falling edges on a 2-bit data bus. Key capabilities include:
- Configurable Edge Detection: Supports both rising and falling edge detection via the
type_selcontrol signal. - Window Gating: A programmable window timer allows pulses to be gated within a specific time window, enhancing noise immunity.
- Hold Mode: Ensures reliable pulse capture by extending the output pulse to the next clock cycle upon detection.
- Sticky Flag: Latches edge events for later processing, with an explicit clear mechanism (
sticky_clr). - Synchronous Reset: Asynchronous active-low reset for quick initialization.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 2-Bit Edge Detector with Edge Type Selection — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: A 2-bit edge detector with configurable rising/falling edge selection, programmable window timer, hold mode, and sticky flag for event latching.
- 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
- Detects rising or falling edges on a 2-bit data input.
- Configurable edge type via the
type_selcontrol signal (0: Falling, 1: Rising). - Programmable window timer limits the duration of the output pulse.
- Hold mode extends the pulse to the next clock cycle upon detection.
- Sticky flag remains set until explicitly cleared by
sticky_clr. - Asynchronous active-low reset initializes all internal states.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Active-low reset |
data_in | Input | 2 | Input data bus |
en | Input | 1 | Enable signal for detection |
type_sel | Input | 1 | 0 for falling, 1 for rising edge |
hold_mode | Input | 1 | 1 to hold pulse for one cycle |
window_en | Input | 1 | Enable window timer |
window_cnt | Input | 4 | Window timer count value |
sticky_clr | Input | 1 | Clear sticky flag |
edge_pulse | Output | 1 | Detected edge pulse |
sticky_flag | Output | 1 | Latched edge event flag |
Architecture
The module uses a delay register to store the previous state of data_in. Edge detection logic compares current and delayed data bits. The type_sel signal selects between rising and falling edge conditions.
A window timer counts cycles when window_en is asserted. The timer resets when it reaches window_cnt or when window_en is deasserted. The edge_pulse output is gated by the window_active status.
Hold mode overrides the window logic to pulse for one cycle. The sticky_flag is set on any enabled edge detection event and remains set until cleared.
Verification
The testbench performs self-checking verification of all modes. It tests:
- Rising edge detection with window active.
- Falling edge detection with window active.
- Pulse suppression when the window is inactive.
- Setting and clearing of the sticky flag.
- Hold mode pulse generation and clearance.
- Enable gating suppression.
- Asynchronous reset behavior.
All test cases passed successfully.
More in Edge, Debounce & Pulse
- 8-Bit Sticky OR Accumulator — L1 Upgrade — L2 Upgrade
- Both-Edge Detector — L1 Upgrade
- Configurable Minimum Pulse Stretcher
- Double-Pulse Rejector
- Edge Count Window 8-bit — L1 Upgrade — L2 Upgrade
- Edge-Triggered Single-Cycle Pulse Generator — L1 Upgrade — L2 Upgrade
- Falling-Edge Hold for N Cycles — L1 Upgrade
- Level-Change Sticky Flag — L1 Upgrade — L2 Upgrade
- Level-to-Pulse Enable — L1 Upgrade — L2 Upgrade
- Min-Width Pulse Filter N
- Pulse Gap Detector 8-bit
- Pulse Width Monitor
- Quadrature Decoder x4 — L2 Upgrade
- Rising-Edge Event Counter 8-Bit — L1 Upgrade — L2 Upgrade
- Rising-Edge Hold for N Cycles — L1 Upgrade — L2 Upgrade
- Single-Cycle Pulse Generator with Enable Gating — L1 Upgrade — L2 Upgrade