# Creating an assertion to verify that a change in one signal corresponds to the posedge of another

**URL:** <https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, implication, assertion\
**Created:** [May 15, 2023, 6:51am UTC](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662 "2023-05-15T06:51:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuval-Jacoby](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/y/7ba0ec/32.png) [@Yuval-Jacoby](https://verificationacademy.com/forums/u/Yuval-Jacoby)\
**Post date:** [May 15, 2023, 6:51am UTC](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/1 "2023-05-15T06:51:52Z")

</div>

Hey,

What I’m trying to do is essentially verify that the input port of some module is driven by the correct clock domain. To check this, I want to write an assertion that looks sort of like this:

@(input\_signal) |-\> @(posedge clk)

In order to verify that any change in input\_signal happens only on posedge of a given clock. To the best of my knowledge, it isn’t possible in SystemVerilog. Is there a way to implement this sort of functionality in an assertion (or via some other tool)?

Thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 16, 2023, 3:03am UTC](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/2 "2023-05-16T03:03:21Z")

</div>

I took 2 approaches,explore these solutions and get back to us.

It provides error counters or a pass counter for each edge of sig1.

> **[EDA Playground](https://www.edaplayground.com/x/e5cN)**
>
> Edit, save, simulate, synthesize SystemVerilog, Verilog, VHDL and other HDLs from your web browser.

```verilog

/* What I'm trying to do is essentially verify that the input port of some module
 is driven by the correct clock domain. To check this,
 I want to write an assertion that looks sort of like this:
@(input_signal) |-> @(posedge clk)
In order to verify that any change in input_signal
 happens only on posedge of a given clock. To the best of my knowledge,
  it isn't possible in SystemVerilog. Is there a way to implement
   this sort of functionality in an assertion (or via some other tool)?

*/
module top;
  bit clk, sig1, dis, reset_n=1; 
  int err1, err2, ok2, debug2, tfire;
 // always @(sig1) // approavh 1 
 // assert final($past(sig1,1,1, @(posedge clk)) != sig1) else 
 // err1=err1+1;
   function void f; err1=err1+1; endfunction
  always @(sig1) // approach 1, value based 
       #1 // needed for the $past
        assert ($past(sig1,1,1, @(posedge clk)) != sig1) else f(); 

  task automatic t_stable(); // 
     realtime t; 
    tfire=tfire+1;
     t=$realtime; // new sig1 change after posedge clk 
     //#1; // debug2=debug2+1; // debug
    @(posedge clk) debug2=debug2+1;
    assert($realtime - t <= 21ns && 
                               $realtime -t >= 20ns) ok2=ok2+1; 
                 else err2=err2+1; 
  endtask

  always @(sig1) begin 
    fork t_stable(); join_none; // time based
  end

  initial forever #10 clk = !clk;
  initial begin
    $dumpfile("dump.vcd"); $dumpvars;
    #5 sig1 = 1; 
    @(posedge clk) sig1<= !sig1;
    #3 sig1 <= !sig1; 
    @(posedge clk) sig1<= !sig1;
    @(posedge clk) sig1<= !sig1;
    #8 sig1 <= !sig1;
    repeat(4) @(posedge clk) sig1<= !sig1;
    #20 $finish(); 
  end
endmodule
 

```

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/d71d0b49bd5394ed8e9e3ed1e9258a3ede033ce1.png)

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/d71d0b49bd5394ed8e9e3ed1e9258a3ede033ce1.png)

Ben Cohen  
[Ben@systemverilog.us](mailto:Ben@systemverilog.us)  
Link to the list of papers and books that I wrote, many are now donated.

> **[Cohen\_Links\_to\_papers\_books.pdf](https://systemverilog.us/vf/Cohen_Links_to_papers_books.pdf)**
>
> 141.16 KB

or [Cohen\_Links\_to\_papers\_books - Google Docs](https://rb.gy/ibks5p)

Getting started with verification with SystemVerilog

> **[Ben Cohen on LinkedIn: Road map to start with verification: SV, SVA , UVM and TB](https://www.linkedin.com/posts/ben-cohen-1172a0_road-map-to-start-with-verification-sv-activity-7050267628208062464-wnzN?utm_source=share&utm_medium=member_desktop)**
>
> Got this question: 
> Q: I need your advice in getting started with verification with systemverilog. I 've built various projects using Verilog and they was…

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 16, 2023, 5:54pm UTC](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/3 "2023-05-16T17:54:49Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/2):_  
The assertion with the task could have been written as

```verilog
property p_dfromclk; 
 realtime t;
 @(sig1) (1, t=$realtime) ##1
 @(posedge clk) $realtime -t <= 21ns && 
 $realtime -t >= 20ns;
 endproperty 
 ap_dfromclk: assert property(p_dfromclk) ok3=ok3+1; 
 else err3=err3+1;

```

The reason I initially wrote it with the task is because that’s how I saw it: at the leading clocking event (the @(sig1) I fire an automatic task that has a life of its own. This is explained in my paper "Understanding the SVA Engine Using the Fork-Join Model  
[Verification Horizons - July 2020 | Verification Academy](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)  
Using a model, the paper addresses important concepts about attempts and threads. Emphasizes the total independence of attempts.  
You should read this paper if you want to relly understand a good modeling of assertions.  
The updated model with this new property is at [(4) - EDA Playground](https://www.edaplayground.com/x/Lyti)  
The simulation results are at

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 16, 2023, 8:43pm UTC](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/4 "2023-05-16T20:43:05Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/3):_

This diagram explains why we need the #1 in

```verilog
function void f; err1=err1+1; endfunction
 always @(sig1) // approach 1, value based 
 #1 // Needed for the $past of the posedge of clk just prior
 assert ($past(sig1,1,1, @(posedge clk)) != sig1) else f();

```

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/0484e5b77829fb696e120af9f3cd2b7eb12527ba.png)

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/0484e5b77829fb696e120af9f3cd2b7eb12527ba.png)

---

<div class="post-metadata">

**Author:** ![Yuval-Jacoby](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/y/7ba0ec/32.png) [@Yuval-Jacoby](https://verificationacademy.com/forums/u/Yuval-Jacoby)\
**Post date:** [May 22, 2023, 2:33pm UTC](https://verificationacademy.com/forums/t/creating-an-assertion-to-verify-that-a-change-in-one-signal-corresponds-to-the-posedge-of-another/41662/5 "2023-05-22T14:33:50Z")

</div>

Thanks Ben, I appreciate the answer. I figured that at the very least I could use $realtime, but your solution was more elegant than what I hacked together.
