2

Below is the property that I currently use.

property freq_chk (time clk_period , bit disable_chk=0);
  time current_time; 
  disable iff ( disable_chk )
  ('1, current_time = $time) |=> 
   ( (($time - current_time) >= (clk_period-1)) && 
     (($time - current_time) <= (clk_period+1)) );
endproperty : freq_chk

so we here we consider a tolerance limit in the clock period as +/-1. What would be the best method to have a tolerance percentage passed and the frequency checked accordingly.

I am looking at something like the one below (THIS DOES NOT WORK, just for demonstration of what I am looking at.)

property freq_chk_with_tol (time clk_period , bit disable_chk=0, int tolerance=0);
  time current_time; 
  disable iff ( disable_chk )
  ('1, current_time = $time) |=> 
   ( (($time - current_time) >= ( (clk_period * (1 - (tolerance/100) )) - 1)) && 
     (($time - current_time) <= ( (clk_period * (1 + (tolerance/100) )) + 1)) );
endproperty : freq_chk_with_tol

What would be the best method to check the frequencies of clocks that has a +/- tolerance % ?

Greg
  • 18,111
  • 5
  • 46
  • 68
Vineeth VS
  • 404
  • 8
  • 18
  • 2
    `tolerance/100` returns an integer; therefore a tolerance of 8 would be 0. Try `tolerance/100.0` which will return a real (aka float). – Greg May 11 '17 at 17:19

2 Answers2

1

As Greg suggested, changing the integer values to real did the trick for me.

Below is the working code.

property freq_chk_tol (time clk_period , bit disable_chk=0, real tolerance=0.00);
  time current_time; 
  disable iff ( disable_chk )
  ('1, current_time = $time) |=> 
   ( (($time - current_time) >= ( (clk_period * (1 - (tolerance/100.00) )) - 1)) && 
     (($time - current_time) <= ( (clk_period * (1 + (tolerance/100.00) )) + 1)) );
endproperty : freq_chk_tol
Vineeth VS
  • 404
  • 8
  • 18
0

Why use assertion? Wouldn't it easier to use behavioral code?

time clk_margin = <set it to whatever value you need>;   // calculate it once, don't calculate on the fly
time last_clk_tick;
always_ff @(posedge clk) begin
  assert (abs($time - last_clk_tick) < clk_margin);  // abs() is a user function return the absolute value
  last_clk_tick = $time;
end
hevangel
  • 95
  • 5
  • Personally I feel using property-assertion method makes it easier to reuse the same piece of code for multiple clocks and also easier for functional coverage tracking. – Vineeth VS Jul 25 '17 at 16:07