Work out which clock each of four assertions uses, and so when each first fails.
Hardware context: A small bench with two clocks, a default clocking, a clocking block and a clocked procedure. Find the clock each assertion uses before reading its failure time.
The main program below has two clocks, a default clocking, a clocking block and an assertion in a procedure. The signal ok is low from 22 to 36 ns.
Each assertion fails at the first of its clock edges that samples ok low. Write answer(q) so it returns that time for each assertion.
Questions 0 to 2 are worked examples on a smaller program. Questions 3 to 6 are graded only by the full check.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 4 | input of each check |
Full specification
module sub(input logic clk2, input logic ok);
// No default clocking here: the procedure's edge clocks the assertion.
always @(posedge clk2)
in_proc: assert property (ok) else $display("in_proc fails at %0t", $time);
endmodule
module tb;
logic clk = 0, clk2 = 0, ok = 1;
always #5 clk = ~clk; // rises 5, 15, 25, 35; falls 10, 20, 30, 40
initial begin #7 clk2 = 1; forever #7 clk2 = ~clk2; end // rises 7, 21, 35; falls 14, 28, 42
default clocking dc @(negedge clk); endclocking
clocking cb @(negedge clk2); endclocking
explicit_q: assert property (@(posedge clk) ok) else $display("explicit_q fails at %0t", $time);
sub u_sub (.clk2(clk2), .ok(ok));
block_q: assert property (@(cb) ok) else $display("block_q fails at %0t", $time);
bare_q: assert property (ok) else $display("bare_q fails at %0t", $time);
initial begin
#22 ok = 0; // low from 22 to 36
#14 ok = 1;
#20 $finish;
end
endmodule
| q | Assertion | Program |
|---|---|---|
| 0 | bare_x | worked example |
| 1 | fall_x | worked example |
| 2 | block_x | worked example |
| 3 | explicit_q | main, graded |
| 4 | u_sub.in_proc | main, graded |
| 5 | block_q | main, graded |
| 6 | bare_q | main, graded |
module tb;
logic clk = 0, slow = 0, ok = 1;
always #4 clk = ~clk; // rises 4, 12, 20, 28; falls 8, 16, 24, 32
always #6 slow = ~slow; // rises 6, 18, 30; falls 12, 24, 36
default clocking dc @(posedge clk); endclocking
clocking cx @(posedge slow); endclocking
bare_x: assert property (ok) else $display("bare_x fails at %0t", $time);
fall_x: assert property (@(negedge clk) ok) else $display("fall_x fails at %0t", $time);
block_x: assert property (@(cx) ok) else $display("block_x fails at %0t", $time);
initial begin
#13 ok = 0; // low from 13 to 30
#17 ok = 1;
#10 $finish;
end
endmodule
Simulator note: Verilator 5.052 rejects a procedural assertion in a module that has a default clocking. So the procedure sits in its own module, sub, which the default of tb does not reach.
Examples
Example 1
One Assertion on the Default Clock- Input
answer(0)
- Output
first_failure_ns = 20
bare_x has no clock of its own, so it takes the default. That is the rising edge of clk: 4, 12, 20 and 28. The first one with ok low is 20.
Example 2
A Clock Written in the Assertion- Input
answer(1)
- Output
first_failure_ns = 16
fall_x names the falling edge of clk: 8, 16, 24. The default does not apply. The first falling edge with ok low is 16.
Example 3
The Event of a Clocking Block- Input
answer(2)
- Output
first_failure_ns = 18
cx is on the rising edge of slow: 6, 18, 30. The edge at 18 is the first one with ok low.
Constraints and Contract
- Return one time per question from answer(q).
- Keep the function header.
Hints
Hint 1
An explicit clock in the assertion always wins over a default.
Hint 2
Which edge does always @(posedge clk2) give an assertion inside it? Does the default clocking of tb reach into sub?
Hint 3
@(cb) uses the clocking block's own event, not a raw edge of its clock.
What the grader checks: Seven constant answers: three worked examples and one per assertion of the main program. They are graded against the first failure times measured on Verilator 5.052.
7 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 3 steps and the final capstone