Edge, Debounce & Pulse
Pulse Width Monitor
Measures the width of an input pulse in clock cycles and latches the result.
About this block
Simulate it in the Verilog IDE
Pulse Width Monitor 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.
The Pulse Width Monitor is a lightweight, synchronous digital IP core designed to measure the duration of an input pulse in clock cycles.
It latches the count upon the falling edge of the input signal and provides a valid flag to indicate when a measurement is complete.
This IP is suitable for timing analysis, pulse detection, and simple event duration monitoring in digital designs.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Pulse Width Monitor.
- Read the Verilog module in the editor. The catalog line for this block: Measures the width of an input pulse in clock cycles and latches the result.
- 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
- Pulse Width Measurement: Measures pulse duration from 1 to 255 clock cycles.
- Asynchronous Reset: Active-low reset (
rst_n) clears all internal states immediately. - Valid Flag: Output
width_validasserts for one clock cycle when a measurement is complete. - 8-bit Output: Provides the measured width in an 8-bit register (
width_count). - Synchronous Operation: All logic is synchronous to the rising edge of
clk.
Architecture
The module implements a simple finite state machine (FSM) with two states: IDLE and MEASURING.
- IDLE State: The counter is zero, and
width_validis low. The module waits fordinto go high. - MEASURING State: The counter increments on each clock cycle while
dinis high. Ifdingoes low, the current count is latched towidth_count,width_validis asserted, and the state returns toIDLE.
### Block Diagram
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input (rising edge triggered) |
rst_n | Input | 1 | Active-low asynchronous reset |
din | Input | 1 | Pulse input signal to measure |
width_valid | Output | 1 | Asserted high for 1 cycle when measurement is complete |
width_count | Output | 8 | Measured pulse width in clock cycles |
Verification
The provided testbench (tb_pulse_width_monitor.v) verifies the following scenarios:
- Reset Behavior: Ensures all outputs are zero after reset.
- Single-Cycle Pulse: Verifies correct measurement of a 1-cycle pulse.
- Multi-Cycle Pulse: Verifies correct measurement of 5-cycle and 10-cycle pulses.
- Idle State: Ensures
width_validremains low when no pulse is present.
### Running Simulation
- Compile the RTL and testbench files.
- Run the simulation.
- Check the log output for
INFO: PASS.
Expected log output:
More in Edge, Debounce & Pulse
- 2-Bit Edge Detector with Edge Type Selection — L1 Upgrade — L2 Upgrade
- 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
- 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