RTL Studio Open IDE

Counters

Event Counter with Capture

16-bit event counter with rising-edge detection and synchronous capture register.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Event Counter with Capture is a Verilog reference block in the Counters catalog. Up/down, modulo, and loadable binary counters with enable logic. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This IP implements a 16-bit event counter with rising-edge detection and snapshot capture capability. It detects rising edges on the event_in signal and increments an internal counter. A capture register allows snapshotting the current count value on demand. The design supports asynchronous reset and synchronous clear operations.

This IP provides a robust solution for counting events with the ability to snapshot the count at specific moments. It is suitable for applications requiring event tracking and periodic data logging. The design is simple, efficient, and fully verified.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Event Counter with Capture.
  2. Read the Verilog module in the editor. The catalog line for this block: 16-bit event counter with rising-edge detection and synchronous capture register.
  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

  • 16-bit counting range (0 to 65535).
  • Rising-edge detection for debounced or pulse-based event inputs.
  • Synchronous capture of the current count value.
  • Synchronous clear to zero the counter.
  • Asynchronous active-low reset for system initialization.
  • Fully synchronous design suitable for high-frequency synthesis.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input for synchronous logic.
rst_nInput1Asynchronous active-low reset.
event_inInput1Event signal to count rising edges.
cap_enInput1Capture enable to snapshot count_out.
clrInput1Synchronous clear to reset counter to zero.
count_outOutput16Current count value.
cap_outOutput16Captured count value snapshot.

Architecture

The module consists of two main stages: edge detection and counting, followed by capture logic. The edge detector uses a two-stage flip-flop chain to identify rising edges on event_in. A pulse is generated when the previous state was low and the current state is high. The counter increments on each detected pulse unless cleared or reset. The capture register samples the counter value when cap_en is asserted.

Verification

The testbench verifies reset behavior, counting accuracy, capture functionality, and clear operation. All test cases passed successfully during simulation.

Test CaseDescriptionResult
TC1Reset behaviorPASS
TC2Count rising edgesPASS
TC3Capture valuePASS
TC4Continue counting after capturePASS
TC5Clear counterPASS

More in Counters

All Counters blocks