Home › Practice › Formal Verification › A clocked rule: the counter never passes 9

A clocked rule: the counter never passes 9

EasyFormalassertsequential

A circuit with a clock remembers things, so a rule about it has to say when to look. The usual answer: look at every rising clock edge.

Concept first. A clocked assertion sits in an always @(posedge clk) block. On every clock tick, the tool checks that the rule is true right then. The tool does not try one run. It tries every possible input on every tick, for as long as it can, and reports a run where the rule breaks. Example with other numbers: a 3-bit counter that counts 0 to 5 and starts over. The rule assert(q <= 3'd5) says it never goes past 5.

The design is a digit counter: it counts up 0, 1, 2 ... 9 and then wraps to 0. en makes it count, rst sets it to 0.

module dut(input clk, input rst, input en, output reg [3:0] q);
  initial q = 4'd0;
  always @(posedge clk) begin
    if (rst) q <= 4'd0;
    else if (en) q <= (q == 4'd9) ? 4'd0 : q + 4'd1;
  end
endmodule
Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← Assume vs assert: subtract oneCover: can the queue ever fill up? →