Module is basic building block in Verilog where we can describe any hardware block. When design is very big or complex it is not easy to describe entire hardware block in a module. Istead of describing entire hardware in a single modlue, we can break the hardware into smaller modules and we can instantiate any module in out main module.
For example, we know that we can make full adder using two half adder. Even though we can describe a full adder in a module but we can also describe a half adder and instantiate half adder in main module to descrive a full adder.
First of all your main module and sub-module should be in same path/folder. You can instntiate sub-module in main module, to do this write sub-module name inside the main module followed by a unique instance name. For example, if main module name is fulladder and sub-module name is halfadder then you can instantiate it as given below: halfadder ha0(port lists); Note: Module instantiation should be inside of module and endmodule
For example, in above halfadder module, a and b are two inputs and sum and carry are two outputs and port declaration order is a,b,sum,carry.
As shown in above figure, a,b,w1 and w2 are ports and wire of main module. As per porr list order, a of main module will be mapped to a of sub-module halfadder, b of main module will be mapped to b of sub-module, w1 of main module will be mapped to sum of sub-module and so on.
In this method of module instantiation, we use port or wire name of both the module for mapping. For example if we want to map port a of main module to the port a of sub module, we write inside of the bracket of module instantiation: .sub_module_port_name(main_module_port_or_wire_name)
In this Verilog code, both methods of module instantiation is demonstrated. Line 13 is using ordered port mapping and line 16 is port mapping using defined port or wire name.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.