2

I am trying to make a simple mux in verilog from a decoder with an enable, but for some reason when I try to use the decoder within my mux with the enable locked to 1, I get an error.

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

When I run the simulation I get the following error:

# ** 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).

Any help on how to fix this would be greatly appreciated. I feel like I may be misunderstanding something about how Verilog uses static values.

4

2 回答 2

3

您尚未提供TRUE信号的定义。我已将您的替换TRUE1'b1,现在模拟运行得更好:

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

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

或者,您可以在您的穆杜勒中声明TRUE为:wireMUX

wire TRUE = 1'b1;
于 2012-09-24T15:11:28.523 回答
2

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

`default_nettype none

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

parameter TRUE = 1'b1;
于 2012-09-24T17:49:47.807 回答