Ic Overview Session7 Verilog Part2
Ic Overview Session7 Verilog Part2
Fundamental – Part 2
Module 1. Verilog module
2. Module instance
.
1
VERILOG MODULE
endmodule
2
VERILOG MODULE
module port declaration
A module port defines the interface between module and other external modules.
Ports are used to pass the signals in and out of a module.
There are 3 types of ports:
▪ input: receive signal into module. It should be net type.
▪ output: send signal out of the module. It can be net or reg type.
▪ inout (bidirectional port): can both receive and send signal. It should be net type.
wire
wire inout
3
VERILOG MODULE
module port declaration
Note: The vector part-select port should not be used to avoid the confusion. But it is perfectly
fine with that declaration.
4
VERILOG MODULE
module port declaration
It’s illegal to declare the data type again for those ports as below:
5
VERILOG MODULE
module port declaration
endmodule
Similar to the above slide, it’s illegal to declare again the ports or data types in the body of the module if using
this method.
6
VERILOG MODULE
HALF ADDER
7
VERILOG MODULE
module hierarchy
module aaa
8
VERILOG MODULE
port connection
▪ When connecting directly port-to-port, input port must be connected to output port of connected module.
▪ The ports connected to each other can have different names.
▪ Need a wire (net type) to connect between 2 ports, wire can have name same as the port or can be different.
bb u_bb ( .b ( a ) , .c ( y ) );
9
VERILOG MODULE
port connection
Note:
▪ 1 output port can be connected to more than 1 input port (fan-out).
▪ 1 input port can NOT be connected from more than 1 output port (multi driver).
10
VERILOG MODULE
practice
Practice: complete the hierarchy of and_gate below based on the and_gate module on previous example
endmodule in3
in4 out34
11
VERILOG MODULE
FULL ADDER from HALF ADDER
A B Cin S Cout
0 0 0 0 0
0 0 1 1 0
a sum
0 1 0 1 0
b
0 1 1 0 1 Full adder carry
c
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
12
VERILOG MODULE
FULL ADDER
full_adder
a a_in sum_out tmp1 a_in sum_out sum
tmp2
c
13
SESSION 7
SUMMARY
SUMMARY:
❑ A module is a fundamental building block, which can be simulated and synthesized .
❑ Module can be instatiated in another module to generate hierarchical structure.
14
HOMEWORK
Homework1: Design a 2-bit full adder module to perform 2-bit binary addition based on 1 bit full-adder
1. Go to 07_ss7 folder under your home directory
2. Copy /ictc/student-data/share/teacher/07_ss7/full_adder_2b/ to your folder
3. Create the full_adder_2b.v under rtl folder and writing your code
4. Go to sim and compile, run to check the result.
0 0 0 carry 0 1 0 carry 1 1 0 carry 1 1 0 carry
0 0 a[1:0] 0 1 a[1:0] 0 1 a[1:0] 1 1 a[1:0]
0 1 b[1:0] 0 1 b[1:0] 1 1 b[1:0] 1 1 b[1:0]
------- ------- ------- -------
0 1 sum[1:0] 1 0 sum[1:0] 0 0 sum[1:0] 1 0 sum[1:0]
a[0] sum[1:0]
a[1]
15
HOMEWORK
Homework2(*): Design 16-bit full adder module based on full-adder on previous practice
1. Go to 07_ss7 folder under your home directory
2. Copy /ictc/student-data/share/teacher/07_ss7/full_adder_16b/ to your folder
3. Create the full_adder_16b.v under rtl folder and writing your code
4. Go to sim and compile, run to check the result.
a[15:0] sum[15:0]
b[15:0] full_adder_16b
carry
Homework3(*): Prove that full_adder can be generated from 2 half-adder (as the diagram in
previous practice) by logic equivalent.
16