# SVA to check clock toggling for a fixed number of cycles

**URL:** <https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630>\
**Category:** SystemVerilog\
**Tags:** SVA, Assertion-Multiple-clocks, SystemVerilog, assertion, clock\
**Created:** [January 22, 2021, 7:29pm UTC](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630 "2021-01-22T19:29:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nimitz\_class](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nimitz\_class](https://verificationacademy.com/forums/u/nimitz_class)\
**Post date:** [January 22, 2021, 7:29pm UTC](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/1 "2021-01-22T19:29:59Z")

</div>

Hi,

I’m trying to write assertions for **sclk** to be stable and toggling for 4 clock cycles before **ack** goes high and stable and toggling 8 clock cycles after **ack** goes low. **ack** goes high after **req** is asserted, so that’s the 4 clock cycles delay for **ack** before it’s asserted.

```verilog

property sclk_ack_req;
     @(posedge ref_clk) $rose(req) |-> sclk[*4] ##1 $rose(ack) ##3 $fell(ack) ##1 sclk[*8];
   endproperty

```

Please help me with this one, thanks.

---

<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:** [January 22, 2021, 8:52pm UTC](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/2 "2021-01-22T20:52:03Z")

</div>

_In reply to [foxtrot](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630):_

```verilog

// sclk to be stable and toggling for 4 clock cycles 
// Q: What is the definition of "stable"? 
// steady in value for 4 ref_clk cycles or 
// toggling for 4 sck cycles? You mention both

// before ack goes high and stable and toggling 8 clock cycles after ack goes low. 
// ack goes high after req is asserted, so that's the 4 clock cycles delay for ack before it's asserted. 
// Q: Very poor defintion of the requirements.  
// Now you are talking about sclk to be a clock used as delay. 
// GIGO. I don't understand your requirements. 

property sclk_ack_req;
     @(posedge ref_clk) $rose(req) |-> sclk[*4] ##1 $rose(ack) ##3 $fell(ack) ##1 sclk[*8];
   endproperty
// Above property says: 
   // At the rose(req) you have sclk==1 for 4 consecutive ref_clk clock cyccles.
   // This is then followed by a rose(ack)and 3 ref_clk later ack fell. 
   // This is then followed by sclk==1 for 8 consecutive ref_clk clock cyccles.

   // Note that $rose(ack) ##3 $fell(ack) does not cover the case of this sequence 
  // $rose(ack) ##1 ack==0 ##1 ack==1 ##1 ack==0
   // 0 1 x 1 0 
   // to avoid this, you need 
   // $rose(ack) ##0 ack[*3] ##1 $fell(ack)

```

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [http://cvcblr.com/home.html](http://cvcblr.com/home.html)  
\*\* SVA Handbook 4th Edition, 2016 ISBN 978-1518681448  
…

1. SVA Package: Dynamic and range delays and repeats [SVA: Package for dynamic and range delays and repeats | Verification Academy](https://rb.gy/a89jlh)
2. Free books: Component Design by Example [FREE BOOK: Component Design by Example … A Step-by-Step Process Using VHDL with UART as Vehicle | Verification Academy](https://rb.gy/9tcbhl)  
Real Chip Design and Verification Using Verilog and VHDL($3) [Amazon.com](https://rb.gy/cwy7nb)
3. Papers:

- Understanding the SVA Engine,  
[Verification Horizons - July 2020 | Verification Academy](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)
- SVA Alternative for Complex Assertions  
[Verification Horizons - March 2018 Issue | Verification Academy](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
- SVA in a UVM Class-based Environment  
[SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)

---

<div class="post-metadata">

**Author:** ![nimitz\_class](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nimitz\_class](https://verificationacademy.com/forums/u/nimitz_class)\
**Post date:** [January 22, 2021, 9:58pm UTC](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/3 "2021-01-22T21:58:08Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/2):_

> sclk must be stable and toggling before ACK asserts (min 4 SCLKs)  
>  sclk must be stable and toggling after ACK de-asserts (min 8 SCLKs)  
>  sclk must be stable and toggling when both the REQ and ACK are asserted

Here you go, this is what I need to do.

Thanks

---

<div class="post-metadata">

**Author:** ![nimitz\_class](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nimitz\_class](https://verificationacademy.com/forums/u/nimitz_class)\
**Post date:** [January 22, 2021, 10:27pm UTC](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/4 "2021-01-22T22:27:00Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/3):_

> _In reply to [foxtrot](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/3):_

```verilog

// sclk to be stable and toggling for 4 clock cycles 
// Q: What is the definition of "stable"? 
// steady in value for 4 ref_clk cycles or 
// toggling for 4 sck cycles? You mention both
// before ack goes high and stable and toggling 8 clock cycles after ack goes low. 
// ack goes high after req is asserted, so that's the 4 clock cycles delay for ack before it's asserted. 
// Q: Very poor defintion of the requirements.  
// Now you are talking about sclk to be a clock used as delay. 
// GIGO. I don't understand your requirements. 
property sclk_ack_req;
@(posedge ref_clk) $rose(req) |-> sclk[*4] ##1 $rose(ack) ##3 $fell(ack) ##1 sclk[*8];
endproperty
// Above property says: 
// At the rose(req) you have sclk==1 for 4 consecutive ref_clk clock cyccles.
// This is then followed by a rose(ack)and 3 ref_clk later ack fell. 
// This is then followed by sclk==1 for 8 consecutive ref_clk clock cyccles.
// Note that $rose(ack) ##3 $fell(ack) does not cover the case of this sequence 
// $rose(ack) ##1 ack==0 ##1 ack==1 ##1 ack==0
// 0 1 x 1 0 
// to avoid this, you need 
// $rose(ack) ##0 ack[*3] ##1 $fell(ack)

```

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [http://cvcblr.com/home.html](http://cvcblr.com/home.html)  
\*\* SVA Handbook 4th Edition, 2016 ISBN 978-1518681448  
…

1. SVA Package: Dynamic and range delays and repeats [SVA: Package for dynamic and range delays and repeats - SystemVerilog - Verification Academy](https://rb.gy/a89jlh)
2. Free books: Component Design by Example [https://rb.gy/9tcbhl](https://rb.gy/9tcbhl)  
Real Chip Design and Verification Using Verilog and VHDL($3) [https://rb.gy/cwy7nb](https://rb.gy/cwy7nb)
3. Papers:

- Understanding the SVA Engine,  
[https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)

- SVA Alternative for Complex Assertions  
[https://verificationacademy.com/news/verification-horizons-march-2018-issue](https://verificationacademy.com/news/verification-horizons-march-2018-issue)

- SVA in a UVM Class-based Environment  
[https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)

Let’s consider your comment, I don’t want to check for sclk==1 for 4 clock cycles, but I want to check whether it’s toggling for 4 clock cycles. I’m unable to do that toggling part, this is where I need your 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:** [January 23, 2021, 12:11am UTC](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/5 "2021-01-23T00:11:29Z")

</div>

_In reply to [foxtrot](https://verificationacademy.com/forums/t/sva-to-check-clock-toggling-for-a-fixed-number-of-cycles/38630/4):_  
You have not described the relationship between ref\_clk and sclk  
How are they derived? Something like:

```verilog

always_ff @(posedge sclk) begin
   ref_clk <= !ref_sclk;     
end
// That relationship determines how you proceeed. You may need multiclocking. 
// ref_clk ^ | ^ | ^ | ^ | ^ | ^ |
// sclk 1 0 1 0 1
// req 0 1 x
// for the *4 repeat, perhaps something like this? 
property sclk_ack_req;
    bit v; 
    @(posedge ref_clk) 
       $rose(req) |-> @(ref_clk) (1, v=ref_clk) 
                     ##0 (sclk==v ##1 sclk==!v)[*4] 
    ##1 @(posedge ref_clk) $rose(ack) ##3 $fell(ack) ##1 sclk[*8];
endproperty  

```

GBGO, be more specific in your definition of requirements  
Ben
