【问题标题】:Verilog: error instantiating moduleVerilog:错误实例化模块
【发布时间】:2015-08-05 00:40:38
【问题描述】:

我正在尝试编写可重复使用的模块,但遇到了问题。代码如下:

35  always @(BTN) begin  
36    case (BTN)  
37      4'b0001:  
38        begin  
39          digit1 <= digit1 + 1;  
40          sevensegcase digi1 (      // the module i'm trying to reuse  
41            .SEG_SEL_IN(n2B0[1:0],  // n2B0 is a defined constant  
42            .BIN_IN(digit1[3:0]),  
43            .DOT_IN(n1B1),          // another constant  
44            .SEG_SEL_OUT(AN[3:0]),  // Send digit selection to the anodes  
45            .HEX_OUT(A_TO_G[7:0])); // Select appropriate segments  
46         end  

......  
......  
......  

当我保存模块时,它编译时出现错误。
当我合成我得到的模块时:

ERROR:HDLCompliers:26 - "Seven_Seg.v" line 40 unexpected token 'sevensegcase'

如果我将实例化放在 always 块之外,我会得到同样的错误。

【问题讨论】:

    标签: verilog


    【解决方案1】:

    您正在 always @ 块内实例化一个模块。在always @ 块之外实例化它,给它输入线,然后在你的always @ 块中将这些输入线分配给所需的信号。

    sevensegcase digi1 (
      .SEG_SEL_IN(n2B0[1:0], // n2B0 is a defined constant
      .BIN_IN(digit1[3:0]),
      .DOT_IN(n1B1), // another constant
      .SEG_SEL_OUT(AN[3:0]), // Send digit selection to the anodes
      .HEX_OUT(A_TO_G[7:0])); // Select appropriate segments
    )
    
    reg digit_reg[3:0];
    
    always @(BTN) begin
      case (BTN)
        4'b0001:
        begin
          digit_reg <= digit_reg + 1;
        end
    
    assign digit1 = digit_reg;
    

    旁注:不要忘记您的default: 案例!

    【讨论】:

    • 我还建议使用自动敏感度列表 always @* 而不是 always @(BTN)
    【解决方案2】:

    我认为问题在于您可能正在交换模块名称和实例名称。在 Verilog 中实例化模块时,它需要采用以下格式:

    module_name instance_name (port_a, port_b, ...);
    

    我猜 digi1 可能是您的模块名称,而 Sevensegcase 是实例名称?如果是这样,您已经调换了顺序,如果您解决了这个问题,它应该可以编译。另外,请确保在顶级模块之前编译子模块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多