Modules communicate with external world using ports. They provide interface to the modules. A module definition contains list of ports. All ports in the list of ports must be declared in the module, ports can be one the following types:
- Input port, declared using keyword input.
- Output port, declared using keyword output.
- Bidirectional port, declared using keyword inout.
Port Connection Rules
- Inputs: Always of type net(wire). Externally, they can be connected to reg or net type variable.
- Outputs: Can be of reg or net type. Externally, they must be connected to a net type variable.
- Bidirectional ports (inout): Always of type net. Externally, they must be connected to a net type variable.
- It is possible to connect internal and external ports of different size. In general you will receive a warning message for width mismatch.
- There can be unconnected ports in module instances.
module module_1( input a, input b, output c);
If there is an instance of above module, in some other module. Port connections can be made in two types.
Connection by Ordered List:
module_1 instance_name_1 ( A, B, C);
Connecting ports by name:
module_1 instance_name_2 (.a(A), .c(C), .b(B));
In connecting port by name, order is ignored.
|<< Previous||Home||Next >>|