Control & Timers
8-Bit Window Comparator — L1 Upgrade — L2 Upgrade
8-Bit Window Comparator with sticky IRQ capture and synchronous clear.
About this block
Simulate it in the Verilog IDE
8-Bit Window Comparator — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Control & Timers catalog. FSMs, timers, watchdogs, and control/state sequencing blocks. Marked Medium: more state or a wider datapath, still one workspace in the IDE.
This IP core implements an 8-bit window comparator that monitors a data stream against configurable lower and upper bounds. It provides two primary outputs:
in_window: A combinational signal indicating if the input data is currently within the specified range.irq_sticky: A sequential, sticky interrupt signal that asserts high upon the first transition ofdata_ininto the window. It remains asserted until explicitly cleared viairq_clearor a system reset (rst_n).
This design is suitable for applications requiring detection of transient events within a specific data range, ensuring that entry events are captured even if the data leaves the window immediately.
The module operates synchronously with a clock (clk) and an active-low asynchronous reset (rst_n).
- Window Check: Combinational logic compares
data_inagainstlower_boundandupper_bound. - Sticky IRQ Logic: Sequential logic detects the rising edge of the window condition (transition from outside to inside) and latches the interrupt state.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Window Comparator — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: 8-Bit Window Comparator with sticky IRQ capture and synchronous clear.
- 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
- 8-Bit Data Width: Supports 8-bit input data and bounds.
- Configurable Bounds: Independent
lower_boundandupper_boundinputs. - Sticky Interrupt:
irq_stickyasserts on window entry and holds state. - Synchronous Clear:
irq_clearresets the sticky interrupt without affecting the window check logic. - Asynchronous Reset:
rst_nresets all internal state immediately.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Active-low asynchronous reset |
data_in | Input | [7:0] | Data to compare |
lower_bound | Input | [7:0] | Lower bound of window |
upper_bound | Input | [7:0] | Upper bound of window |
irq_clear | Input | 1 | Synchronous IRQ clear |
in_window | Output | 1 | High if lower_bound <= data_in <= upper_bound |
irq_sticky | Output | 1 | Sticky IRQ triggered on window entry |
Architecture
The design separates combinational comparison from sequential state management to ensure deterministic behavior.
- Combinational Stage:
in_window_combis calculated every cycle based on input bounds. - Edge Detection: A D-Flip-Flop (
prev_in_window) stores the previous cycle's window status. An edge detector identifies the transition from0to1. - Sticky Latch: The sticky register (
irq_sticky_q) is set on the detected edge and cleared byirq_clearorrst_n.
Verification
The provided testbench (tb_window_comparator_sticky_8_sticky_irq_capture.v) validates the following scenarios:
| Test Case | Description | Expected Result |
|---|---|---|
| TC1 | Data inside window | in_window is 1 |
| TC2 | Data below window | in_window is 0 |
| TC3 | Transition into window | irq_sticky becomes 1 |
| TC4 | Data stays inside | irq_sticky remains 1 |
| TC5 | Data leaves window | irq_sticky remains 1 |
| TC6 | IRQ clear asserted | irq_sticky becomes 0 |
| TC7 | Reset asserted | irq_sticky becomes 0 |
| TC8 | Re-trigger after clear | irq_sticky becomes 1 again |
More in Control & Timers
- 1 MHz Tick Generator — L1 Upgrade — L2 Upgrade
- 16-Bit Down Timer (Match on Load-Zero Too) — L2 Upgrade
- 16-Bit Programmable Prescaler — L1 Upgrade — L2 Upgrade
- 16-bit Programmable Timer with Interrupt — L2 Upgrade
- 16-Bit Pulse Width Modulator (PWM) Controller
- 32-Bit Interval Timer with IRQ
- 32-Bit Kick Watchdog with Configurable Timeout and Reset Pulse
- 8-Bit Down Timer (Pulse Match on Zero) — L2 Upgrade
- 8-Bit Programmable Digital Deglitch Filter — L1 Upgrade — L2 Upgrade
- 8-Channel 16-Bit PWM Controller
- Activity Timeout Flag 8-bit — L2 Upgrade
- Bang-Bang Thermostat 8-bit
- Complementary PWM Dead-Time Inserter — L2 Upgrade
- Duty-Cycle Measurement 8-Bit — L2 Upgrade
- Edge Rate Limiter 8-bit — L2 Upgrade
- Enable-Gated Set/Reset Flag