RTL Studio Open IDE

Control & Timers

Duty-Cycle Measurement 8-Bit — L2 Upgrade

Measures input signal duty cycle as 8-bit percentage with sticky IRQ threshold comparison.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Duty-Cycle Measurement 8-Bit — 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 measures the duty cycle of a periodic input signal over one complete period. It outputs an 8-bit integer percentage (0-100) representing the high-time ratio. The module features a sticky interrupt request (IRQ) that asserts when the measured duty cycle exceeds a configurable threshold. A busy flag indicates when a measurement cycle is in progress, preventing overlapping starts.

This IP is suitable for clock monitoring, signal integrity checks, and power management applications where duty cycle validation is critical.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Duty-Cycle Measurement 8-Bit — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Measures input signal duty cycle as 8-bit percentage with sticky IRQ threshold comparison.
  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

  • 8-Bit Precision: Outputs duty cycle as an integer percentage (0-100).
  • Configurable Threshold: 8-bit input allows setting a custom IRQ trigger point (0-100).
  • Sticky IRQ: Interrupt flag remains asserted until explicitly cleared via clear_irq.
  • Busy Flag: Prevents new measurements from starting while a cycle is in progress. Asserting start while busy is high is ignored.
  • Synchronous Control: Supports synchronous reset and enable signals for easy integration.
  • Full Period Measurement: Measures one full high and low cycle before outputting a result.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low synchronous reset
startInput1Trigger a new measurement cycle (ignored if busy is high)
clear_irqInput1Clear the sticky IRQ flag
thresholdInput8IRQ threshold percentage (0-100)
enInput1Enable signal for counting. Must be high for measurement to proceed.
duty_cycleOutput8Measured duty cycle percentage
irqOutput1Sticky interrupt when duty_cycle > threshold
busyOutput1High during measurement cycle

Architecture

The module uses a finite state machine (FSM) to track high and low periods of the input signal. The FSM transitions through four states: IDLE, HIGH, LOW, and DONE.

  1. Counting: Two 16-bit counters (high_count, low_count) accumulate clock cycles while the input signal is high or low, respectively, provided en is asserted.
  2. Calculation: Upon completion of a period (transition to DONE), the duty cycle is calculated as (high_count * 100) / total_count.
  3. IRQ Logic: The calculated duty cycle is compared against the threshold register. If duty_cycle > threshold, the irq flag is set.

Verification

The testbench validates basic functionality and edge cases. All test cases passed in the simulation log.

Test CaseDescriptionResult
TC1Basic 50% duty cycle measurementPASS
TC2IRQ assertion for 50% > 20% thresholdPASS
TC3Sticky IRQ clear functionalityPASS
TC4No IRQ when 50% <= 60% thresholdPASS
TC5Busy signal assertion and deassertionPASS

More in Control & Timers

All Control & Timers blocks