Multiple module instatiations on a bus

Guest
If I need to instantiate one copy of a module I've written for every
signal on a bus, eg:

module foo ( BAR, EN, Q);

Suppose that I want to implement foo modules on the 32-bit BAR bus, and
the 32-bit Q bus, but with a common enable:

BAR[31:0], EN, Q[31:0]

How do I do that without writing the module implementation 32 times?
 
annirak@gmail.com wrote:
If I need to instantiate one copy of a module I've written for every
signal on a bus, eg:

module foo ( BAR, EN, Q);

Suppose that I want to implement foo modules on the 32-bit BAR bus, and
the 32-bit Q bus, but with a common enable:

BAR[31:0], EN, Q[31:0]

How do I do that without writing the module implementation 32 times?
You can use an array of instances. In this case:

foo foo_array[31:0](BAR, EN, Q);

For BAR and Q, whose total width matches the total width of all the
instance ports, it will attach one bit of the bus to each instance (or
in the general case of a multi-bit port, a part-select of the bus to
each instance). For EN, whose width matches the width of a single
instance, it will attach EN to each of the instances, giving you your
common enable. In other words, it is defined to work exactly the way
you want it to.

For a more complex connection scheme, you could use a
generate-for-loop. But for this simple situation, an array of
instances is sufficient and is simpler.
 
sharp@cadence.com wrote:
You can use an array of instances. In this case:

foo foo_array[31:0](BAR, EN, Q);

For BAR and Q, whose total width matches the total width of all the
instance ports, it will attach one bit of the bus to each instance (or
in the general case of a multi-bit port, a part-select of the bus to
each instance). For EN, whose width matches the width of a single
instance, it will attach EN to each of the instances, giving you your
common enable. In other words, it is defined to work exactly the way
you want it to.

For a more complex connection scheme, you could use a
generate-for-loop. But for this simple situation, an array of
instances is sufficient and is simpler.
If I wanted to add a parameter instantiation with the array index, how
would I do that?
 
annirak@gmail.com wrote:
If I wanted to add a parameter instantiation with the array index, how
would I do that?
foo #(param_val) foo_array[31:0](BAR, EN, Q);

Or you can use connection by name in the parameter list if you prefer.
Note that the parameter value will be the same for all the instances in
the array. There is no way to give different values to different
instances in the instantiation. You can use defparams to do it, though
they are widely frowned upon.

If you wanted to give different parameter values to different instances
in some regular pattern (such as ascending numbers matching their
index in the array), a generate for-loop would do that more compactly.
 

Welcome to EDABoard.com

Sponsor

Back
Top