Read one vector on a fast global clock and a slow assertion clock, and say when each past function fires.
Hardware context: A four-bit vector watched on a fast global clock and a slow assertion clock. Say when each past global-clock function fires, from the samples one global tick apart.
The main program below has a global clock that ticks every 10 ns and a slow clock clk. One assertion uses the global clock itself. Four more are clocked by clk and each calls one past global-clock function on the vector v.
Write answer(q). For questions 3 to 6 it returns the time of the first failure of one assertion. For question 7 it returns how many times changed_q fails in the whole run.
Questions 0 to 2 are worked examples on a smaller program. Questions 3 to 7 are graded only by the full check.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 4 | input of each check |
Full specification
module tb;
logic sys = 0, clk = 0;
always #5 sys = ~sys; // global ticks at 5, 15, 25, ...
global clocking @(posedge sys); endclocking
initial begin #10 clk = 1; forever #20 clk = ~clk; end // clk rises at 10, 50, 90, 130, 170
logic [3:0] v = 4'd2;
tick_q: assert property (@($global_clock) v != 4'd5) else $display("tick_q fails at %0t", $time);
rose_q: assert property (@(posedge clk) !$rose_gclk(v)) else $display("rose_q fails at %0t", $time);
fell_q: assert property (@(posedge clk) !$fell_gclk(v)) else $display("fell_q fails at %0t", $time);
stable_q: assert property (@(posedge clk) $stable_gclk(v)) else $display("stable_q fails at %0t", $time);
changed_q: assert property (@(posedge clk) !$changed_gclk(v)) else $display("changed_q fails at %0t", $time);
initial begin
#22 v = 4'd5; // t=22
#65 v = 4'd6; // t=87
#40 v = 4'd3; // t=127
#40 v = 4'd1; // t=167
#8 $finish; // t=175
end
endmodule
| q | Return | Program |
|---|---|---|
| 0 | the value of ticks printed at 38 | worked example |
| 1 | the value of $past_gclk(w) printed at 38 | worked example |
| 2 | the value of $past(w) printed at 38 | worked example |
| 3 | first failure time of tick_q | main, graded |
| 4 | first failure time of rose_q | main, graded |
| 5 | first failure time of fell_q | main, graded |
| 6 | first failure time of stable_q | main, graded |
| 7 | number of failures of changed_q | main, graded |
module tb;
logic sys = 0, clk = 0;
always #4 sys = ~sys; // global ticks at 4, 12, 20, 28, 36
global clocking @(posedge sys); endclocking
initial begin #6 clk = 1; forever #16 clk = ~clk; end // clk rises at 6 and 38
logic [3:0] w = 4'd1;
int ticks = 0;
always @($global_clock) ticks++;
always @(posedge clk)
$display("t=%0t past_gclk=%0d past=%0d ticks=%0d", $time, $past_gclk(w), $past(w), ticks);
initial begin
#10 w = 4'd4; // t=10
#20 w = 4'd9; // t=30
#7 w = 4'd7; // t=37
#5 $finish; // t=42
end
endmodule
Simulator note: The key was measured on Verilator 5.052. Your answer function is checked by a small bench on Icarus 12.
Examples
Example 1
Count the Global Ticks- Input
answer(0)
- Output
answer = 5
The global clock rises at 4, 12, 20, 28 and 36. Five ticks come before the clk edge at 38.
Example 2
One Global Tick Back- Input
answer(1)
- Output
answer = 9
The last global tick before 38 is 36. There w was 9; the change to 7 at 37 comes later.
Example 3
One Tick of the Block's Own Clock Back- Input
answer(2)
- Output
answer = 1
The block is clocked by clk. Its last edge was at 6, where w was still 1.
Constraints and Contract
- Return one value per question from answer(q).
- Keep the function header.
Hints
Hint 1
First list the edges of each clock. Then write down the sample of v at every global tick and at every edge of clk.
Hint 2
A past global-clock function at an edge of clk compares with the last global tick before it, 5 ns earlier here.
Hint 3
$rose_gclk and $fell_gclk look at bit 0 only. $stable_gclk and $changed_gclk look at all four bits.
What the grader checks: Eight constant answers: three worked examples and five graded questions, one per construct. They are graded against times and counts measured on Verilator 5.052.
8 checks on Icarus · browser samples / server checks. 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