RTL Studio Open IDE

3.2 · SYSTEMVERILOG CLASS

clocking block

Define a clocking block to synchronize stimulus with the DUT clock and avoid race conditions.

Watch on YouTube

What you practice

clocking block (3.2). Define a clocking block to synchronize stimulus with the DUT clock and avoid race conditions. It is in Timing & Synchronization — Part 3 · Advanced SV & Mini-UVM of the SystemVerilog Masterclass. Timing, concurrency, constrained-random verification, assertions, and a pure-SV Mini-UVM environment.

The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.

What you will learn

You will learn how to define a clocking block in a testbench to synchronize stimulus application and signal sampling with the clock edge, preventing race conditions in simulation.

Learning objectives

  • Understand the purpose of a clocking block in SystemVerilog testbenches.
  • Define input and output skews using default input #<delay> output #<delay>.
  • Use @(clocking_block) to synchronize stimulus to clock edges.
  • Declare clocking block inputs and outputs with correct variable types.

Theory

A clocking block in SystemVerilog provides a mechanism to synchronize testbench signals with a clock, avoiding race conditions between the DUT and testbench. It defines when signals are sampled (input skew) and when they are driven (output skew) relative to the clock edge. Skews are typically small positive delays (e.g., #1) to ensure signals settle before sampling.

Clocking Block ElementPurpose
@(posedge clk)Clock event that drives the block
default input #1Delay before sampling inputs after clock edge
default output #1Delay before driving outputs after clock edge
output a, bList of signals driven by the testbench
input yList of signals sampled from the DUT

Practice

  1. Open this chapter in RtlStudio.

Files appear automatically in Explore.

  1. Open student/tb/tb.sv for editing.
  2. Fill in the clock delay in the forever loop: replace #__TODO__ with a value that matches the golden (e.g., #5).
  3. In the clocking block, set the input skew to match the golden (e.g., #1).
  4. Complete the output and input declarations: add logic after output and logic after input.
  5. Run Simulation and check the Log panel for expected INFO: output.

Summary

You practiced defining a clocking block to synchronize testbench stimulus with the DUT clock, avoiding race conditions through configurable input and output skews. By using ##1 or @(cb) to drive or sample signals, you ensured timing-safe communication between the testbench and the design. This technique is essential for reliable verification in synchronous digital systems.

Run it in the Verilog IDE

  1. Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
  2. Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
  3. Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
  4. Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.

The lesson is done when the simulation matches clocking block. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.