In Verilog, how can I define the width of a port at instantiation? -


in verilog 2001 module, how can define width of port @ instantiation?

for example, multiplier , module instantiates might this:

module multiplier #(parameter width = 8, parameter width1 = 8, width2 = 8) (     output [width-1:0] product,     input [width1-1:0]  factor1,     input [width2-1:0]  factor2 );  parameter widthi = width1+width2; wire [widthi-1:0] intermediate_product; assign intermediate_product = factor1 * factor2; assign product = (intermediate_product >>> (widthi-width));  endmodule  module user();  parameter width_of_product = 8; parameter width_of_factor_1 = 8; parameter width_of_factor_2 = 8;  wire [width_of_product] product; reg  [width_of_factor_1] factor1; reg  [width_of_factor_2] factor2;  multiplier #(width_of_product,width_of_factor_1,width_of_factor_2)      m0(product, factor1, factor2);  endmodule 

if widths of nets in user defined @ compile time, there way widths of ports in instantiation of multiplier can defined automatically?

i'd instantiation looks this:

multiplier m0(product, factor1, factor2); 

that involve changing definition of multiplier module.

keep in mind these examples. point of question regards how 2 modules defined respect nets , ports.

thanks in advance!

update:

here case not work multiplier defined is:

module top(); parameter wide = 8; parameter narrow = 4;  wire [narrow-1:0] narrow_product; wire [wide-1:0]   wide_product; reg  [narrow-1:0] narrow_factor_1; reg  [wide-1:0] wide_factor_1; reg  [narrow-1:0] narrow_factor_2; reg  [wide-1:0] wide_factor_1;  multiplier mwide(wide_product, wide_factor_1, wide_factor_2); multiplier mnarrow(narrow_product, narrow_factor_1, narrow_factor_2); // problem  endmodule 

my motivation nets represent fixed point numbers, representation of numbers fractional parts. have specify precision fixed point numbers. while global constant, may want use different precisions. so, need parameters specify precisions of ports in modules.

update: well, can't wanted do. here have done, in case helps anyone:

since widths of input , output same defined them way:

module multiplier #(parameter width = 8,     parameter width1 = width,     parameter width2 = width1) (     output [width-1:0] product,     input [width1-1:0]  factor1,     input [width2-1:0]  factor2 );  ...  endmodule 

so can instantiate way:

multiplier #(16) m0(product, factor1, factor2); 

if product , factors have same length. it's little less verbose specifying of them, when working fixed point numbers instantiation this:

multiplier #(16,8) m0(product, factor1, factor2);  

where second number precision parameter giving width of fractional part. (this require update multiplier module definition include precision, precision1, , precision2 definitions analogous width definitions.

parameter defined reason have pass parameters instance:

module top(); localparam wide   = 8; localparam narrow = 4;  wire [narrow-1:0] narrow_product; wire   [wide-1:0]   wide_product; reg  [narrow-1:0] narrow_factor_1; reg    [wide-1:0]   wide_factor_1; reg  [narrow-1:0] narrow_factor_2; reg    [wide-1:0]   wide_factor_1;  multiplier #(   .width  (wide),   .width1 (wide),   .width2 (wide) ) mwide (   .product (wide_product),   .factor1 (wide_factor_1),   .factor2 (wide_factor_2) );   multiplier #(   .width  (narrow),   .width1 (narrow),   .width2 (narrow) ) mnarrow(   .product (narrow_product),   .factor1( narrow_factor_1),   .factor2( narrow_factor_2) ); // not problem  endmodule 

multiplier :

module multiplier #(   parameter width = 8,    parameter width1 = 8,   parameter width2 = 8 ) (     output [width-1:0]   product,     input  [width1-1:0]  factor1,     input  [width2-1:0]  factor2 ); //... 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -