0

I am writing a module in Verilog that uses parameters. Later I will need to implement it several times in my project using different parameters, so instead of crating several modules I want to pass the parameters as if they were inputs, although they are specified in the compilation.

I think this can be done in VHDL, so I guess it can be done in Verilog too although I cannot find anything.

kwoxer
  • 3,734
  • 4
  • 40
  • 70

3 Answers3

0

Module parameters can be overridden in these 2 ways:

  1. Using defparam statement:

    module Stack;
    
    parameter param1 =  1;
    parameter param2 = 12;
    
    endmodule
    
    module Test;
    
    defparam s1.param1 =  6;
    defparam s1.param2 = 32;
    
    Stack s1();
    
    endmodule
    
  2. Passing parameters during instantiating: in this method, parameters must be overridden in the order they were defined so code below, is the same as above.

    module Stack;
    
    parameter param1 =  1;
    parameter param2 = 12;
    
    endmodule
    
    module Test;
    
    Stack #(6, 32) s1();
    
    endmodule
    
    • In Verilog 2001, there is a new feature which makes it more readable (note that above codes all work in Verilog 2001).

      module Stack;
      
      parameter param1 =  1;
      parameter param2 = 12;
      
      endmodule
      
      module Test;
      
      Stack #(.param1(6), .param2(32)) s1();
      
      endmodule
      
Mehran Torki
  • 977
  • 1
  • 9
  • 37
0

Another way.

`module top #(
parameter N, // Number of instance
parameter [(N*32-1):0] A, // First Parameter
parameter [(N*2-1):0] B   // second parameter
);
generate
for (int i=0; i<N; i++) begin: instance
  s #(.A(A[(i*32-1):0]),
      .B(B[(i*2-1):0])
     ) s_i;
end
endgenerate`
Sourabh
  • 634
  • 5
  • 12
-1

You can directly assign parameter during the input and output assignment. for example: " parameter i0=0,i1=1; " and call these values in code such as:" a[0]=N[i0];" =>the 0th bit of input N; will be stored in 0th bit of reg a; "a[1]=N[i1];"=> the 1th bit of input N; will be stored in 1th bit of reg a; if your N is 4'b1011, then the value of " a=0011 ". You may have to initialize a to 0.

Satheesh.R
  • 47
  • 1
  • 4