# How to create a parametrized assertion?

**URL:** <https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407>\
**Category:** SystemVerilog\
**Tags:** parameter, assertion\
**Created:** [January 14, 2025, 3:20pm UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407 "2025-01-14T15:20:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbverilog](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/13edae/32.png) [@mbverilog](https://verificationacademy.com/forums/u/mbverilog)\
**Post date:** [January 14, 2025, 3:20pm UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407/1 "2025-01-14T15:20:21Z")

</div>

I am trying to create an assertion which checks whether a signal has been stable over the last n cycles (from when the assertion is evaluated).  
I am trying to “parametrize the assertion” so that it can be applied to a signal of any width. I also want to put it in some package so that I can utilize it in any of my projects.  
I am a beginner so I do not know SystemVerilog syntax extensively. I found an entry on stackoverflow relating to “Passing parameters to a Verilog function”. I drew some inspiration from it and came up with this:

```auto
package verification_pkg;
virtual class extended_stable # (parameter int n = 1, int WIDTH = 1);
static function automatic logic stable_for_n_cycles (
    input logic [WIDTH-1:0] sig
);
    if (n <= 1) begin
		return 1'b1;
    end

    for (int i = 1; i < n; i++) begin
		if ($past(sig, i) !== $past(sig, i-1)) begin
			return 1'b0;
		end
    end

    return 1'b1;
endfunction
endclass
endpackage

```

I know this won’t work. Among other reasons why, when sig is passed into stable\_for\_n\_cycles, the function sees it as a logic value and no longer as a signal, so it no longer has a history and therefore it would not make sense to call $past from within the function.

That said, I still do not have any other idea on how to do this.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [January 14, 2025, 5:11pm UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407/2 "2025-01-14T17:11:28Z")

</div>

There is no need to write a function. SystemVerilog properties have all the syntax you need.

```auto
property stable_after_start(clk,rst,start, signal,N);
  @(posedge clk) disable iff (reset)
  $rose(start) |-> ##1 $stable(sig) [*N];
endproperty

```

---

<div class="post-metadata">

**Author:** ![mbverilog](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/13edae/32.png) [@mbverilog](https://verificationacademy.com/forums/u/mbverilog)\
**Post date:** [January 14, 2025, 8:11pm UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407/3 "2025-01-14T20:11:37Z")

</div>

Thanks a lot dave\_59 for a quick response.

I am assuming you are using $rose(start) as the “trigger” condition at which the stability of sig gets evaluated?

So then what I still need to know is this:

What does this modifier [\*N] mean?

1- For the previous N cycles? In this case it does the job.

2- For the next N cycles? In this case the property which you wrote does not fit what I have in mind.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [January 15, 2025, 6:56am UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407/4 "2025-01-15T06:56:30Z")

</div>

Yes I did mean $rose.  
`[*N]` means repeat the _next_ N cycles.

This should do what you have in mind

```auto
module top;
  bit clk, rst, sig, st;

  property stable_after_start(clk,reset,start, signal,N);
    @(posedge clk) disable iff (reset)
      $rose(start) |-> ##1 $stable($past(signal,N)) [*N];
  endproperty
  
  initial #0.5ns repeat(100) #0.5ns clk = !clk;
  
  initial begin
    repeat (5) @(posedge clk);
    st <=1;   
    repeat (1) @(posedge clk);
    st <=0;
    repeat (5) @(posedge clk);
    sig <=1;
    repeat (1) @(posedge clk);
    st <= 1;
  end
  assert property (stable_after_start(clk,rst,st,sig,3)) $info("pass"); else $error("fail");
    
endmodule

```

---

<div class="post-metadata">

**Author:** ![SG\_99](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@SG\_99](https://verificationacademy.com/forums/u/SG_99)\
**Post date:** [February 20, 2025, 7:17pm UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407/5 "2025-02-20T19:17:12Z")

</div>

> [@dave\_59](#):
>
> `$stable($past(signal,N))`

Hi @dave_59  
I want to know how it will execute, can you please elaborate more on it syntax. As i know past returns num of cycles and stable will true or false basses on past one clock cycle.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [February 20, 2025, 8:30pm UTC](https://verificationacademy.com/forums/t/how-to-create-a-parametrized-assertion/49407/6 "2025-02-20T20:30:55Z")

</div>

`$past` is simply a shortcut for creating a shift register of N cycles for a particular value. So $stable($past(signal,N)) compares the value of signal _N cycles_ in the past with _N-1 cycles_ in the past.
