# Is it possible to detect when a signal is 're-written' to the same value?

**URL:** <https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804>\
**Category:** SystemVerilog\
**Tags:** conceptual, always-blocks, SystemVerilog, events, sensitivity-list, event-scheduling\
**Created:** [February 2, 2017, 6:39pm UTC](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804 "2017-02-02T18:39:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jms8](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jms8](https://verificationacademy.com/forums/u/jms8)\
**Post date:** [February 2, 2017, 6:39pm UTC](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804/1 "2017-02-02T18:39:41Z")

</div>

I have a conceptual question about the way System Verilog works. To make this easy to explain, say that I have code which looks like this:

```verilog

interface my_interface();
  logic y;

  always @(y) begin
    $display("Activated!");
  end

  task set_y_zero();
    y = 0;
  endtask

  task set_y_one();
    y = 1;
  endtask
endinterface

```

```verilog

module test();

  my_interface int();

  initial begin
    int.set_y_zero();
    #10
    int.set_y_zero(); // Location A
    #10
    int.set_y_one(); // Location B
  end

```

I know from experiments that “Activated!” will be printed when test reaches location B but not location A. However, I would like some way to detect when the task set\_y\_zero, i.e. “y is written to 0” is called a second time at location A. Unfortunately, all my research seems to indicate that this is impossible; System Verilog events seem to only be scheduled when there is a _change_. But I would like to confirm:

Is there any way to detect when a variable (logic in this example, but it can be anything) is ‘re-written’ to the same value?

---

<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:** [February 2, 2017, 8:37pm UTC](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804/2 "2017-02-02T20:37:47Z")

</div>

_In reply to [jms8](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804):_

> Is there any way to detect when a variable (logic in this example, but it can be anything) is ‘re-written’ to the same value?

If the variable is clocked, you can use the action block or statement to take an action. However, this are restrictions. Also, a reassignment is not necessarily detected. You can tune the assertion or the cover to what you need. For example:

```verilog

cover property(property_spec) statement_or_null
cp: cover property( @(posedge clk) $rose(v) |=> v[->1]) $display("whatever");  
// If new "v", then another "v" will happen

cp_next1: cover property( @(posedge clk) $rose(v) |=> v) $display("whatever"); 
cp_next0: cover property( @(posedge clk) $fell(v) |=> !v) $display("whatever"); 
 

```

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

- [SVA Handbook 4th Edition, 2016 ISBN 978-1518681448](http://goo.gl/JOfuEB)
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- [Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712](https://goo.gl/d10QHh)
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

---

<div class="post-metadata">

**Author:** ![shanya](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@shanya](https://verificationacademy.com/forums/u/shanya)\
**Post date:** [February 3, 2017, 6:22am UTC](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804/3 "2017-02-03T06:22:38Z")

</div>

_In reply to [jms8](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804/2):_

interface my\_interface();  
logic y;  
event e;

always @(e) begin  
$display(“Activated!”);  
end

task set\_y\_zero();  
y = 0;  
-\>e;  
endtask

task set\_y\_one();  
y = 1;  
-\>e;  
endtask  
endinterface

module test();

my\_interface ints();

initial begin  
ints.set\_y\_zero();  
#10  
ints.set\_y\_zero(); // Location A  
#10  
ints.set\_y\_one(); // Location B  
end

endmodule

---

<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:** [February 3, 2017, 7:01am UTC](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804/4 "2017-02-03T07:01:08Z")

</div>

_In reply to [shanya](https://verificationacademy.com/forums/t/is-it-possible-to-detect-when-a-signal-is-re-written-to-the-same-value/32804/3):_

> Is there any way to detect when a variable (logic in this example, but it can be anything) is ‘re-written’ to the same value?

The requirements were for the general case;the above solution requires the application of an event after every set of assignments. It won’t work for variables of type wire.  
But it has value.  
Ben [Ben@systemverilog.us](mailto:Ben@systemverilog.us)
