Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to Verilog modules

I am in the process of writing some Verilog modules for an FPGA design. I looked around the internet to find out how I best parametrize my modules. I see two different methods occurring often. I included an example hereunder of the two different methodologies. Which of these methods is the best way to parametrize modules? What is the difference? Is it vendor-dependent (Altera vs Xilinx)?

The first method: Module definition:

module busSlave #(parameter DATA_WIDTH = 1) (
  input [DATA_WIDTH-1:0] bus_data,
  input                  bus_wr,
  ...
);
endmodule

Module instantiation:

module top;

  //DATA_WIDTH is 32 in this instance
  busSlave #(.DATA_WIDTH(32)) slave32(
    .bus_data(data_0),
    .bus_wr(wr_0),
    ...
    );

  //DATA_WIDTH is 64 in this instance
  busSlave #(.DATA_WIDTH(64)) slave64(
    .bus_data(data_1),
    .bus_wr(wr_1),
    ...
    );
endmodule

The second method: Module definition:

module busSlave(
  parameter DATA_WIDTH = 1;
  input [DATA_WIDTH-1:0] bus_data,
  input                  bus_wr,
  ...
);
endmodule

Module instantiation:

module top;

  //DATA_WIDTH is 32 in this instance
  busSlave slave32(
    .bus_data(data_0),
    .bus_wr(wr_0),
    ...
    );
  defparam slave32.DATA_WIDTH = 32;

  //DATA_WIDTH is 64 in this instance
  busSlave slave64(
    .bus_data(data_1),
    .bus_wr(wr_1),
    ...
    );
  defparam slave32.DATA_WIDTH = 64;
endmodule

Thanks in advance

EDIT: a few corrections in the examples

like image 991
eavsteen Avatar asked Dec 18 '14 20:12

eavsteen


People also ask

How do you instantiate a parameterized module in Verilog?

Instantiating Parameterized Modules As with assigning ports by name, in the parameter list precede the parameter's name with a period and place its value in the parenthesis following the name. The value given must be constant, it can't be assigned from another type as the value cannot be known at synthesis time.

Can we force parameter in Verilog?

NO verilog can not do that.

What is parameter module?

Module Parameter Overview Module parameters allow you to reference the same application module using different expression values. Declare module parameters in the context of a single module. The scope of a module parameter is the containing module.


1 Answers

The defparam statement is scheduled for deprecation. The IEEE Std 1800-2012, Annex C (Deprecation), section "C.4.1 Defparam statements" states:

users are strongly encouraged to migrate their code to use one of the alternate methods of parameter redefinition.

Many features of Verilog are vendor-dependent.

like image 126
toolic Avatar answered Oct 04 '22 17:10

toolic