Asynchronous Assertions and Glitch Detection

Clock an assertion by a signal change, avoid the sampled-value trap, and measure pulse widths with a local time capture.

You Will Be Able To

  • Write an assertion whose clock is a signal change.
  • Explain why an event signal read inside its own assertion shows its old value.
  • Choose one of three remedies for that trap.
  • Measure a pulse width with a local time variable and flag glitches.
Lesson
A6.8
Time
25 min
Runs on
Verilator
Check
5 questions

A spec line: "whenever data shows the error code, abort is high". There is no clock in it, so a first draft uses the change of data as the clock: @(data) data == ERR |-> abort. In simulation it missed the bug and reported a failure 10 ns late, when data left the error code.

What the draft reads at each change of data
0123change of data at (ns)12223242data after the change9394data as the assertion reads it0939abort as readverdictvacuouspassvacuousfailthe real bug: missedreported here instead
Scroll horizontally ↔

An assertion reads sampled values: the values from before the time step. At a change of data, that is the old value of data.

An Event as the Clock

Any event expression can clock a concurrent assertion. @(req) ticks at every change of req, rising or falling. @(posedge irq or negedge rst_n) ticks at either edge; Verilator 5.052 cannot parse that form in an assertion, so this site uses one-signal events.

Each tick starts an attempt, as a clock edge would. The values in the expression are still the sampled values of that time step.

The Trap: Reading the Event Signal

At a change of data, the sampled value of data is the value from before the change. So @(data) data == ERR asks "was data the error code just before it changed?".

The event

@(data)          // ticks at 32
                 // data: 3 -> 9

Fires because data changed in this time step.

The expression

data == ERR      // reads 3
                 // (the sampled value)

Reads the value from before the change, so 9 is never seen here.

Three Remedies

Each remedy makes the check read data after it has settled.

RemedyCodeReports the bug at 32 at
A delayed copy as the eventassign #1 data_d = data; and @(data_d) data == ERR |-> abort33
A synchronous clock@(posedge clk) data == ERR |-> abortthe next clock edge, 35
An immediate assertion after the changealways @(data) begin #1; assert (data != ERR \|\| abort) ...33

All three measured on Verilator 5.052 against the draft, which reports at 42.

The delayed copy keeps the asynchronous style; the delay must be shorter than the shortest legal phase of data. The clocked form is the most robust, if a clock exists. The immediate assertion reads current values and needs no sampling at all.

Glitch Width with a Local Time Capture

A glitch is a phase shorter than the design allows. Clock the assertion by every change of the signal. Store $time in a local variable at one change, and compare at the next.

One Attempt per Change of EnEach change starts an attempt that stores the time. The next change ends it and measures the phase.
  • Step
  • Result
  • Control
call: who calls whom
One attempt per change of enEach change starts an attempt that stores the time. The next change ends it and measures the phase. step change at 10 t0 = 10 step change at 12 12 - 10 = 2 < 3 result failure at 12 a low glitch step new attempt at12 t0 = 12 |=> the next changetoo shortalso starts one
  1. step change at 10t0 = 10
    • |=> the next change → change at 12
  2. step change at 1212 - 10 = 2 < 3
    • too short → failure at 12
    • also starts one → new attempt at 12
  3. result failure at 12a low glitch
  4. step new attempt at 12t0 = 12
  1. Store the time

    At the change at 10, the attempt stores t0 = 10 in its own local variable.

  2. Measure

    With |=>, the next tick of @(en) is the next change, at 12. The phase lasted 2.

  3. Report

    Two is less than the minimum of 3, so this attempt fails at 12.

  4. Overlap

    The change at 12 also starts the next attempt, which measures the following phase.

Read the diagram as text
  • change at 10: t0 = 10
  • change at 12: 12 - 10 = 2 < 3
  • failure at 12: a low glitch
  • new attempt at 12: t0 = 12
  • change at 10 → change at 12: |=> the next change
  • change at 12 → failure at 12: too short
  • change at 12 → new attempt at 12: also starts one

Each attempt has its own copy of the local variable (IEEE 1800-2023 16.10).

The property
property wide_phase;
  time t0;
  @(en) (1'b1, t0 = $time) |=> ($time - t0 >= MIN);
endproperty

Clock it by @(en), not @(posedge en). A rising-edge clock measures from one rise to the next: the period, not a phase.

Where the Tool and the Standard Part

CaseStandardVerilator 5.052 (measured)
an assertion on @(req), with or without logic req = 0;no attempt at time 0. The value is set before any process starts, so no change is seen (inferred from 6.8 and 10.5)an attempt starts at time 0
@(posedge irq or negedge rst_n) as an assertion clocklegal (16.5)compile error: syntax error at or

IEEE 1800-2023 6.8 and 10.5. Measured by tools/probes/sva-w1b/departures.mjs.

The extra attempt at time 0 matters for a width check: it measures from 0 to the first change. The examples here keep the first change at least MIN after 0.

Try It

both_edges measures every high and every low phase. The phases of 2, 1 and 2 fail when they end. The last change, at 18, starts an attempt that never ends: no next change comes.

rising_only sees rises at 5, 12 and 16 and measures 7 and 4. It never fails, although three glitches happened. Change MIN to 5 and predict which lines appear.

RUNVerilator · simulator service
Edit the code, then run it
Expected: t=12 both_edges: phase too short t=16 both_edges: phase too short t=18 both_edges: phase too short

Check Yourself

Predict the outputA width check with a minimum of 4. Predict the first line printed.
module tb;
  logic p = 0;
  property min4;
    time t0;
    @(p) (1'b1, t0 = $time) |=> ($time - t0 >= 4);
  endproperty
  w: assert property (min4) else $display("t=%0t short phase", $time);
  initial begin
    #6  p = 1;                                 // t=6
    #4  p = 0;                                 // t=10
    #3  p = 1;                                 // t=13
    #6  p = 0;                                 // t=19
    #10 $finish;
  end
endmodule
Spot the bugEvery high or low phase of g must last at least 3. The bench makes one phase of 2. Which option misses it?
ConceptAn assertion is clocked by @(data) and its expression reads data. Which value of data does it read?
ConceptWhy does a glitch check clock on @(g) and not on @(posedge g)?
ConceptA remedy uses assign #1 data_d = data; and clocks the assertion by @(data_d). When does it read the new value of data?

Common Mistakes

Wrong Clock an assertion by a signal and compare that same signal in the expression.

The expression reads the value from before the change, so the check is one change late.

Fix Clock on a delayed copy or a real clock, or use an immediate assertion after the change.

Before
@(data) data == ERR |-> abort
After
@(data_d) data == ERR |-> abort
// assign #1 data_d = data;

Wrong Measure a glitch with @(posedge g).

From one rise to the next is a period, so a short low or high phase inside it is never seen.

Fix Clock on @(g), which ticks at both edges.

Wrong Write the width check with > where the spec says "at least".

A phase of exactly the minimum then fails.

Fix Use >= with the minimum the spec gives.

Remember

  • Any event can clock a concurrent assertion; @(sig) ticks at both edges.
  • The expression reads sampled values, so the event signal shows its value from before the change.
  • Remedies: a delayed copy as the event, a real clock, or an immediate assertion after the change.
  • A width check stores $time in a local at one change and compares at the next with >=.

Practice

Report a problem with this page