A6.3.1 Past on the Global Clock

MediumImplementVerilator · serverReview the topic

Check a slow-clock capture against the fast clock, with a global clocking, $stable_gclk and $past_gclk.

Hardware context: A register that copies fast-domain data every system-clock tick, captured by a slow bus clock. Check setup and the copy against the last tick of the global clock, not the last tick of the slow clock.

Data d comes from a fast domain clocked by sys. A register copies it at every tick of sys: q is d, one fast tick later. A slow bus clock clk then captures both.

Write the checker resync_check. It declares sys as the global clock. Both rules are checked at each rising edge of clk, and both look back one tick of the global clock.

Rule setup: d has not changed since the last global tick. Rule copy: q equals the value d had at the last global tick.

Signals in the Timeline

SignalWidthRole
sys1stimulus, the same for every design
clk1stimulus, the same for every design
d4stimulus, the same for every design
q4stimulus, the same for every design
your late32stimulus, the same for every design
your wrong32stimulus, the same for every design
Full specification
The ports (keep them)
module resync_check (
  input  logic       sys,       // the fast system clock: use it as the global clock
  input  logic       clk,       // the slow bus clock: both rules are checked at its rising edge
  input  logic [3:0] d,         // data from the fast domain
  input  logic [3:0] q,         // the design's copy of d, one tick of sys later
  output int         late,      // failures of the setup rule
  output int         wrong      // failures of the copy rule
);
  // your global clocking and two rules
endmodule
TimeWhat the program shown here doesExpected
22d changes to 3, far from an edge of clkno failure
47d changes to 6, after the sys tick at 45 and before the clk edge at 50setup fails at 50
72 to 96the copy is stuck; d changes to 9 at 83copy fails at 90
128d changes to 2, just before the clk edge at 130setup fails at 130

In this program sys rises at 5, 15, 25 and so on, and clk rises at 10, 50, 90, 130 and 170.

The full check also runs a second program that this page does not show. It has other clock periods and the bugs in another order.

Examples

Example 1

Two Late Changes
Input
Program: d moves at 22, 47, 83, 128
Output
late = 2

The changes at 47 and 128 come after the last sys tick before a clk edge. The changes at 22 and 83 do not.

Example 2

One Stale Copy
Input
Program: the copy is stuck from 72 to 96
Output
wrong = 1

At the clk edge at 90, q still holds 6 while d was 9 at the tick at 85.

Example 3

Only the First Late Change by 100
Input
Program: d moves at 22, 47, 83
Output
late = 1

The change at 83 is seen by the sys tick at 85, so the clk edge at 90 finds d stable.

Constraints and Contract

  • Declare the global clocking in the module, on the rising edge of sys.
  • Use $stable_gclk in the setup rule and $past_gclk in the copy rule, both clocked by the rising edge of clk.
  • Count failures in late and wrong. Do not change the ports.

Hints

Hint 1

A global clocking is declared like a clocking block with no signals: global clocking @(event); endclocking.

Hint 2

On the slow clock, $stable(d) compares with the last edge of clk, 40 ns ago. Which function compares with the last tick of sys?

Hint 3

At an edge of clk, the sample of q was loaded at the last tick of sys, from the value d had then.

What the grader checks: Two copies of your checker each watch a fixed program: the one shown here and a hidden one with other clocks. Graded on each: setup failures, copy failures, and setup failures by a set time. The source must use $stable_gclk and $past_gclk in concurrent assertions.

6 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Two Late Changes

Input
Program: d moves at 22, 47, 83, 128
Expected output
late = 2

The changes at 47 and 128 come after the last sys tick before a clk edge. The changes at 22 and 83 do not.

Run samples executes all 3 public checks. Check all tests runs 6 checks on the server.

Verilator · server