【问题标题】:Unresolved Reference Error in Verilog Module when trying to simulate尝试模拟时未解决 Verilog 模块中的参考错误
【发布时间】:2014-03-05 00:43:19
【问题描述】:

当我尝试通过测试台模拟以下模块时,我收到此错误:

对“if2to4”的未解决引用

这是我的代码:

module h3to8(din, eout, en);

  //Port Assignments
  input [2:0] din;
  input [0:0] en;
  output reg [7:0] eout;

  //3-to-8 decoder

  always @(din)
    begin 
  
      eout = 8'b00000000;
      if(din[2] == 1'b0)
        if2to4 half1 (din[1:0], eout[3:0], en);
      else
        if2to4 half2 (din[1:0], eout[7:4], en);
      
    end

endmodule

module if2to4 (in, out, en);

  //Port Assignments
  input [1:0] in;
  input [0:0] en;
  output reg [3:0] out;

  //2-to-4 decoder
  always @(in)
    begin
  
    if(en == 0)
      out = 4'b0000;
    
    else
     if(in == 0)
       out = 1;
     else if(in == 1)
       out = 2;
     else if(in == 2)
       out = 4;
     else
       out = 8;
        
    end

endmodule

verilog 代码旨在使用两个 2 到 4 解码器实现 3 到 8 解码器。我以为我正确地实例化了模块,但我一直收到关于模块if2to4 的未解决的引用错误。代码编译没有错误,并且这个特定错误仅在尝试运行模拟时发生。

【问题讨论】:

    标签: verilog


    【解决方案1】:

    你不能在这样的 always 块中实例化模块。试试这个:

    module h3to8(din, eout, en);
    
      //Port Assignments
      input [2:0] din;
      input [0:0] en;
      output reg [7:0] eout;
    
      //3-to-8 decoder
    
        if2to4 half1 (din[1:0], eout[3:0], en);
        if2to4 half2 (din[1:0], eout[7:4], en);
    
    endmodule
    

    或者,您可以使用din[2] 作为启用的一部分:

    module h3to8(din, eout, en);
    
      //Port Assignments
      input [2:0] din;
      input [0:0] en;
      output reg [7:0] eout;
    
      //3-to-8 decoder
    
        if2to4 half1 (din[1:0], eout[3:0], en&~din[2]);
        if2to4 half2 (din[1:0], eout[7:4], en&din[2]);
    
    endmodule
    

    【讨论】:

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