在Verilog中使用静态值

时间:2012-09-24 15:00:59

标签: verilog

我试图用一个带有启用功能的解码器在verilog中创建一个简单的多路复用器,但出于某种原因,当我尝试在我的多路复用器中使用解码器且启用锁定为1时,我得到一个错误。

module DECODER(out1, out2, out3, out4, A, B, enable);

  `define NOT not #50
  `define AND and #50

  input A, B, enable;
  output out1, out2, out3, out4;
  wire notA, notB, val1, val2, val3, val4;

  `NOT first (notA, A);
  `NOT second (notB, B);

  `AND firstEval(val1, notA, notB);
  `AND secondEval(val2, notA, B);
  `AND thirdEval(val3, A, notB);
  `AND fourthEval(val4, A,B);

  `AND firstOutput(out1, val1, enable);
  `AND secondOutput(out2, val2, enable);
  `AND thirdOutput(out3, val3, enable);
  `AND fourthOutput(out4, val4, enable);
endmodule

module MUX (out, A, B, C, D, select1, select2);
  `define AND and #50
  `define OR or #50

  output out;
  input A,B,C,D,select1,select2;
  wire selectA, selectB, selectC, selectD, firstOr, secondOr, andA, andB, andC, andD;

  DECODER decoderModule(selectA, selectB, selectC, selectD, select1, select2,TRUE);

  `AND checkA(andA, selectA, A);
  `AND checkB(andB, selectB, B);
  `AND checkC(andC, selectC, C);
  `AND checkD(andD, selectD, D);

  `OR firstStep(firstOr, andA, andB);
  `OR secondStep(secondOr, firstOr, andC);

  `OR throughPut(out, secondOr, selectD);

endmodule

module TEST;
  reg A,B,C,D, select1, select2;
  wire out;

  initial
  begin
    A = 1; B = 1; C = 1; D = 1; select1 = 0; select2 = 0;
    #300 A = 0;
    #300 A = 1;
    #300 select1 = 1;
    #300 B = 0;
    #300 B = 1;
    #300 select2 = 1;
    #300 D = 0;
    #300 D = 1;
    #300 select1 = 0;
    #300 C = 0;
    #300 C = 1;
  end

  MUX UUT(out, A,B,C,D,select1,select2);

  initial
    $monitor($time, ,out, , A,B,C,D,select1,select2);
endmodule

当我运行模拟时,我收到以下错误:

# ** Warning: (vsim-3015) C:/Modeltech_pe_edu_10.1c/win32pe_edu/Mux.v(9): [PCDPC] - Port size (1 or 1) does not match connection size (32) for port 'enable'. The port definition is at: C:/Modeltech_pe_edu_10.1c/win32pe_edu/Decoder.v(1).

如何解决这个问题的任何帮助将不胜感激。我觉得我可能误解了Verilog如何使用静态值。

2 个答案:

答案 0 :(得分:3)

您尚未提供TRUE信号的定义。我已将TRUE替换为1'b1,现在模拟效果更好:

  DECODER decoderModule(selectA, selectB, selectC, selectD, select1, select2, 1'b1);

在大多数模拟器中,未声明的信号默认为1'bx

或者,您可以在TRUE模块中将wire声明为MUX

wire TRUE = 1'b1;

答案 1 :(得分:2)

在你的代码中,TRUE看起来像一个隐式的线索,但我不确定为什么Modelsim认为它是32位。您可以使用预处理程序指令来阻止这些。

`default_nettype none

此外,您应该考虑使用常量参数,因为它们的范围有限。

parameter TRUE = 1'b1;