# Clock Frequency Check ( considering Jitter )

**URL:** <https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Clock-Frequency-Check--considering-Jitter-\
**Created:** [April 11, 2022, 6:53pm UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263 "2022-04-11T18:53:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hisingh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@hisingh](https://verificationacademy.com/forums/u/hisingh)\
**Post date:** [April 11, 2022, 6:53pm UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/1 "2022-04-11T18:53:32Z")

</div>

I have the following assertion ::

```verilog

property clock_frequency ( real TP , real J ) ; // TP is Time Period and J is for Acceptable Jitter
   realtime Tpos , T ; 

   @( posedge clk ) ( 1 , Tpos = $realtime ) |=> ( 1 , T = ( $realtime - Tpos ) ) 

   ##0 ( T inside { [( TP - J ) : ( TP + J )] } ) ; // Doubt here

endproperty

assert property( clock_frequency( 10**-6 , 0.05 * ( 10**-6 ) ) // 1MHz Clock Frequency with 5% Jitter acceptable 
        
         else $display(" TIME : %0t Assertion Fails " , $time ) ;

```

My question is regarding the end part :: **( T inside { [( TP - J ) : ( TP + J )] } )**

**Will the time precision come into picture while calculating the Upper and Lower bound ? OR  
Will it calculate the bounds accurately always irrespective of how small the real numbers are**

---

<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:** [April 12, 2022, 4:38am UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/2 "2022-04-12T04:38:40Z")

</div>

_In reply to [hisingh](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263):_

Time scale or time units is the problem here. $realtime returns the time scaled to current time scale/unit. The period of a 1Mhz clock is 1us. If the current timescale is 1ns, $realtime returns 1000.0, not 10\*\*-6. The you use a time literal, then you don’t have to worry about the current time scale

```verilog
assert property( clock_frequency( 1us , 0.05 * 1us) // 1MHz Clock Frequency with 5% Jitter acceptable 
         else $display(" TIME : %0t Assertion Fails " , $time ) ;

```

---

<div class="post-metadata">

**Author:** ![hisingh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@hisingh](https://verificationacademy.com/forums/u/hisingh)\
**Post date:** [April 12, 2022, 3:47pm UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/3 "2022-04-12T15:47:03Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/2):_

Dave ,

> The period of a 1Mhz clock is 1us. If the current timescale is 1ns, $realtime returns 1000.0, not 10\*\*-6.

**Hence if timescale is 1ns , clock frequency of 1MHz i.e 1 us is scaled to 1000ns**

EDIT : A short [sample\_code](https://verificationacademy.com/forums/systemverilog/expression-involving-realtime-n-real-variables) for the same .

Two quick questions ::

> $realtime returns the time scaled to current time scale/unit

**[Q1]** Assuming that I use a time literal , **would the numbers post the decimal point be taken care of automatically ?**

**My concern was that if the Clock period is in ns / ps / fs , would the actual argument to J ( 5% of 1ns / 1ps / 1fs ) be the appropriate value .**

**[Q2] What if the input argument of type ’ real ’ is unit less ?** Eg: Duty Cycle .

I have code snippet as :: [Duty\_Cycle\_EDA](https://www.edaplayground.com/x/vrHZ)

```
     If I were to add input argument to the property ' duty_cycle ' .

```

```verilog

       property duty_cycle ( real duty , real diff );
         realtime Tpos , Ton , T ; 

           ......................................
 
            ##0 ( T inside { [duty - diff] : [duty + diff] } ) ;  

         endproperty 

       // Duty Cycle Must be 55.555 % +- 0.05 %

         assert property( clock_frequency( 55.555 , 0.05 * ( 55.555 ) )

                 else $display(" TIME : %0t Assertion Fails " , $time ) ;
       

```

---

<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:** [April 12, 2022, 11:02pm UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/4 "2022-04-12T23:02:28Z")

</div>

_In reply to [hisingh](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/3):_

Like $realtime, time literals are real type values scaled to the current timescale.

If you do not provide a time unit for a numeric literal, than it assume the number is scaled to the current timeunit where the literal is written.

---

<div class="post-metadata">

**Author:** ![hisingh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@hisingh](https://verificationacademy.com/forums/u/hisingh)\
**Post date:** [April 13, 2022, 12:44am UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/5 "2022-04-13T00:44:54Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/4):_

For the duty cycle related assertion , similar to the solution to the original question I could use a time literal ::

```verilog

 // Duty Cycle Must be 55.555 % +- 0.05 % for 1MHz Clock
 
         assert property( clock_frequency( 555.55ns , 0.05 * ( 555.55ns ) )

```

But using a time literal restricts the usage of a generic property .

**If the clock period is unknown ( hence can’t use a time literal to the argument(s) ) and I simply want to check the duty cycle , is there any alternative ?**

---

<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:** [April 15, 2022, 7:06pm UTC](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/6 "2022-04-15T19:06:31Z")

</div>

_In reply to [hisingh](https://verificationacademy.com/forums/t/clock-frequency-check-considering-jitter/40263/5):_

The way you wrote your assertion requires to know the actual clock period. Otherwise you would have to add code that calculates the running average of the clock period and then check that the jitter does not go outside N% of the average period.
