System verilog 检查具有+;/-的时钟频率的最佳方法是什么公差%?

System verilog 检查具有+;/-的时钟频率的最佳方法是什么公差%?,system-verilog,uvm,system-verilog-assertions,System Verilog,Uvm,System Verilog Assertions,下面是我当前使用的属性 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)

下面是我当前使用的属性

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
属性频率周期(时间周期,位禁用周期=0);
时间-当前时间;
禁用敌我识别(禁用敌我识别)
('1,当前_时间=$time)|=>
(($time-当前时间)>=(时钟周期-1))&

(($time-current_time)正如格雷格所建议的,将整数值改为real对我来说是个好办法

下面是工作代码

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
property freq\u chk\u tol(时间时钟周期,位禁用时间=0,实际公差=0.00);
时间-当前时间;
禁用敌我识别(禁用敌我识别)
('1,当前_时间=$time)|=>
(($time-当前时间)>=((时钟周期*(1-(公差/100.00))-1))&

(($time-current_time)为什么要使用断言?使用行为代码不是更容易吗

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
time clk_margin=;//计算一次,不要在运行中计算
上次时钟滴答的时间;
始终_ff@(posedge clk)开始
assert(abs($time-last_clk_tick)
您可能需要检查标题是否有拼写错误……是的,这是个错误。谢谢。更正:)
tolerance/100
返回一个整数;因此,8的公差将是0。请尝试
tolerance/100.0
返回实数(又称浮点)@Greg谢谢。我没有提到这一点。就我个人而言,我觉得使用属性断言方法可以更容易地将同一段代码用于多个时钟,也更容易进行功能覆盖率跟踪。
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