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 Element | Purpose |
|---|---|
@(posedge clk) | Clock event that drives the block |
default input #1 | Delay before sampling inputs after clock edge |
default output #1 | Delay before driving outputs after clock edge |
output a, b | List of signals driven by the testbench |
input y | List of signals sampled from the DUT |
Practice
- Open this chapter in RtlStudio.
Files appear automatically in Explore.
- Open
student/tb/tb.svfor editing. - Fill in the clock delay in the
foreverloop: replace#__TODO__with a value that matches the golden (e.g.,#5). - In the
clockingblock, set the input skew to match the golden (e.g.,#1). - Complete the
outputandinputdeclarations: addlogicafteroutputandlogicafterinput. - 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
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- 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.