Verilog:模块参数,代码模拟但不合成

tet*_*ope 1 verilog

我在合成一些Verilog代码时遇到了一些问题 - 尽管模拟看起来很好.

具体来说,模块定义如下..

module nexys2_sevensegment(
  input clk,
  input [NUM_CHARS*4-1: 0] disp_chars,
  output [NUM_CHARS-1: 0] anodes,   // The common cathodes for each display.
  output [6: 0] cathodes // The seven segments in the form {G,F,E,D,C,B,A}
  );

  parameter NUM_CHARS = 4; // The number of characters that need to be
                           // displayed. Should be in [1, 4].
Run Code Online (Sandbox Code Playgroud)

并实例化如下,

  nexys2_sevensegment #(4) seven_seg_disp(clk, disp_bus, an, seg);
Run Code Online (Sandbox Code Playgroud)

模拟似乎工作正常,但当我合成它时,我收到以下错误:

=========================================================================
*                          HDL Compilation                              *
=========================================================================
Compiling verilog file "nexys2_sevensegment.v" in library work
ERROR:HDLCompilers:28 - "nexys2_sevensegment.v" line 8 'NUM_CHARS' has not been declared
ERROR:HDLCompilers:28 - "nexys2_sevensegment.v" line 9 'NUM_CHARS' has not been declared
Compiling verilog file "tb_nexys2_seven_segment.v" in library work
Module <nexys2_sevensegment> compiled
Module <tb_nexys2_seven_segment> compiled
Analysis of file <"tb_nexys2_seven_segment.prj"> failed.
Run Code Online (Sandbox Code Playgroud)

我正在使用Spartan3e-1200 - Digilent Nexys2在Xilinx上工作.

谢谢 !

Mar*_*rty 6

如果您正在使用参数,则必须在使用之前声明.尝试:

module nexys2_sevensegment
  #( parameter NUM_CHARS=4 )
  (
  input clk,
  input [NUM_CHARS*4-1: 0] disp_chars,
  output [NUM_CHARS-1: 0] anodes,   // The common cathodes for each display.
  output [6: 0] cathodes // The seven segments in the form {G,F,E,D,C,B,A}
  );

  // ( remove parameter statement here )
Run Code Online (Sandbox Code Playgroud)

现在编译器NUM_CHARS在端口定义中看到它之前遇到了一个定义.

您可能需要在编译器上设置Verilog-2001开关才能使其正常工作.


小智 5

您也可以在端口列表后使用端口声明:

//non-ANSI style header
module nexys2_sevensegment(
  clk,
  disp_chars,
  anodes,   // The common cathodes for each display.
  cathodes // The seven segments in the form {G,F,E,D,C,B,A}
  );

  parameter NUM_CHARS = 4; // The number of characters that need to be
                           // displayed. Should be in [1, 4]

  input                     clk;
  input  [NUM_CHARS*4-1: 0] disp_chars;
  output [NUM_CHARS-1: 0]   anodes;   // The common cathodes for each display.
  output [6: 0]             cathodes; // The seven segments in the form {G,F,E,D,C,B,A}

endmodule
Run Code Online (Sandbox Code Playgroud)