【问题标题】:Verilog disable Statement not Working but $finish works but it is not synthesizable?Verilog disable 语句不工作但 $finish 工作但它不可合成?
【发布时间】:2013-10-16 18:40:41
【问题描述】:

我想设计一个计数到某个数字的计数器,假设它是 3,为此我编写了一个与 "$finish" 配合使用但不适用于 " 的代码禁用”

我想用这个计数器进行综合,所以我必须使用“禁用”语句.....

我已经附上了我的两个代码- (1) $finish 可以轻松准确地停止

// Code with $finish   
module counter(input wire  clk);

reg [23:0]N=24'b0000_0000_0000_0000_0000_0000;

always @ (posedge clk)
 begin 

  if (N == 24'b0000_0000_0000_0000_0000_0011)
   begin 
    $display("Inside If N=%d in Time=",N,$time);
    $finish;
   end
   else 
   begin 
    N <= N +1;    
    $display("Inside Else N=%d in Time=",N,$time);
   end 
  end

endmodule

(2) 禁用根本不会停止..

// Code with disable that not stop    
module counter(input wire  clk);

reg [23:0]N=24'b0000_0000_0000_0000_0000_0000;

always @ (posedge clk)
 begin :close

  if (N == 24'b0000_0000_0000_0000_0000_0011)
   begin 
    $display("Inside If N=%d in Time=",N,$time);
    disable close; 
  end
  else 
  begin 
    N <= N +1;    
    $display("Inside Else N=%d in Time=",N,$time);
  end 
 end

endmodule

【问题讨论】:

  • 先生,根据您的说法,我需要做的更改是什么……我的意思是您能否通过提供一些代码来简要描述一下……

标签: verilog xilinx system-verilog hdl


【解决方案1】:

toolic 和 Greg 都表示不正确地使用了 $finish 和 disable,这只是为了补充这两点并展示一个可能的解决方案,将 test 与可综合的 RTL 分开。

module counter(input clk);

  reg [23:0] N = 24'b0;

  always @ (posedge clk) begin 
    if (N < 24'd3) begin 
      N <= N +1; 
      $display("Inside If N=%d in Time=",N,$time);
    end
    else begin 
      $display("Inside Else N=%d in Time=",N,$time);
    end 
  end
endmodule

测试它:

module test;

//Create clk
reg clk;
initial begin
  clk = 0 ;
  forever begin
    #5  clk =   ~clk;
  end
end

//instantiate DUT (Device Under Test)
counter counter_i0(
  .clk( clk )
);

// The test
//  Run for 6 clock cycles then end
initial begin
  repeat (6) begin
    @(posedge clk)
  end
  $finish;
end
endmodule

如果您的意思是在计数 3 处停止,我会使用十进制表示法 24'd3 作为常数,因为它给出了明确的意图。

另外,如果使用== 停止计数器,故障可能会导致错过,您必须等待它环绕。或者使用小于比较器意味着可以即时调整计数目标,而不必担心会跳过 == 中的确切值,并且必须等待很长时间才能返回。

输入是隐式的连线,不需要像这样定义它们,但如果你愿意,你可以。

【讨论】:

    【解决方案2】:

    $finish 放在测试台的末尾,而不是放在综合 RTL 中。

    $finish 停止所有正在运行的进程并结束模拟。 disable 停止一个进程及其子进程。在您的示例代码中,disable close 终止了 always 块中的代码,它不会停止时钟。下一个上升沿时钟和 always 块将再次尝试运行。

    有关$finish 语句的信息请参见IEEE std 1800-2012 § 20.2,有关禁用语句的信息请参见第 9.6.2 节

    【讨论】:

    • 格雷格先生,但在实际的硬件中,我怎么能停止一个时钟,除了 FPGA 的时钟......我的意思是你描述我必须禁用顶层模块而不是设计单位...
    • 查看时钟发生器模块定义。通常有一个输入端口用于启用/禁用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多