Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional instantiation of verilog module

Is it possible to instantiate a module conditionally in verliog ?

example :

if (en==1)  
  then module1 instantiation  
else  
  module2 instantiation  
like image 692
vlsi2013 Avatar asked Mar 06 '13 06:03

vlsi2013


People also ask

What is module instantiation in Verilog?

When a module is invoked, Verilog creates a unique object from the template. Each object has its own name, variables, parameters, and I/O interface. The process of creating objects from a module template is called instantiation, and the objects are called instances.

Which of the following construct is used to conditionally instantiate a module?

Verilog generate statement is a powerful construct for writing configurable, synthesizable RTL. It can be used to create multiple instantiations of modules and code, or conditionally instantiate blocks of code.

Can you instantiate in an if statement Verilog?

You can't instantiate a module conditionally within an if statements (*), and you definitely can't instantiate them within procedural blocks.

Can we instantiate module in always block?

Hardware modules may not be instantiated inside an always block. All of the always blocks in a module are considered to be parallel blocks of hardware. Likewise, modules are considered to be separate hardware blocks that operate in parallel. Functions, however, can be instantiated in an always block.

Can Verilog modules be instantiated within each other?

Verilog Module Instantiations As we saw in a previous article, bigger and complex designs are built by integrating multiple modules in a hierarchical manner. Modules can be instantiated within other modules and ports of these instances can be connected with other signals inside the parent module.

What is a GENERATE block in Verilog?

A generate block allows to multiply module instances or perform conditional instantiation of any module. It provides the ability for the design to be built based on Verilog parameters.

What is the syntax for module instantiation?

Syntax: Module instantiation consists of module_name followed by instance_name and port_association_list. Need of instance_name is, we can have multiple instance of same module in the same program. Instance name should be unique for each instance of the same module. Port_association_list shows how ports are mapped.

Can I instantiate a module based on a wire value?

to choose an instantiation at compile time. If in you are asking if you can instantiate a module based on a wire value, no you cannot do that. Show activity on this post.


1 Answers

From IEEE Std 1364-2001 :

12.1.3.3 generate-conditional A generate-conditional is an if-else-if generate construct that permits modules, user defined primitives, Verilog gate primitives, continuous assignments, initial blocks and always blocks to be conditionally instantiated into another module based on an expression that is deterministic at the time the design is elaborated.

example given in LRM :

module multiplier(a,b,product);
parameter a_width = 8, b_width = 8;
localparam product_width = a_width+b_width; // can not be modified
// directly with the defparam statement
// or the module instance statement #
input [a_width-1:0] a;
input [b_width-1:0] b;
output [product_width-1:0] product;

generate
    if((a_width < 8) || (b_width < 8))
        CLA_multiplier #(a_width,b_width) u1(a, b, product);
        // instantiate a CLA multiplier
    else
        WALLACE_multiplier #(a_width,b_width) u1(a, b, product);
        // instantiate a Wallace-tree multiplier
endgenerate
// The generated instance name is u1

endmodule
like image 77
nav_jan Avatar answered Sep 20 '22 09:09

nav_jan