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
timevariable 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.
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.
| Remedy | Code | Reports the bug at 32 at |
|---|---|---|
| A delayed copy as the event | assign #1 data_d = data; and @(data_d) data == ERR |-> abort | 33 |
| A synchronous clock | @(posedge clk) data == ERR |-> abort | the next clock edge, 35 |
| An immediate assertion after the change | always @(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.
- Step
- Result
- Control
- Store the time
At the change at 10, the attempt stores
t0 = 10in its own local variable. - Measure
With
|=>, the next tick of@(en)is the next change, at 12. The phase lasted 2. - Report
Two is less than the minimum of 3, so this attempt fails at 12.
- 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).
property wide_phase;
time t0;
@(en) (1'b1, t0 = $time) |=> ($time - t0 >= MIN);
endpropertyClock 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
| Case | Standard | Verilator 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 clock | legal (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.
t=12 both_edges: phase too short t=16 both_edges: phase too short t=18 both_edges: phase too shortCheck Yourself
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.
@(data) data == ERR |-> abort@(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
$timein a local at one change and compares at the next with>=.