Introduction to Verilog -21EC32
Syllabus
(Section 1.1 to 1.6.2, 1.6.4 (only Verilog), 2 of Text 3)
(Section 2.1 to 2.2 (only Verilog) of Text 3)
Module 4
2
11/5/2022
Text Books
3
11/5/2022
HDL
Module 2
4
11/5/2022
Module 2
5
11/5/2022
VERILOG
Module 2
6
11/5/2022
1. Structure of Verilog module
a. Declaration
b. Body
c. End of module
Module 2
7
11/5/2022
Example 1 : Half adder
Task 1:
Write truth table of half adder.
Assume a and b as inputs, find the expression for sum and carry using K-map.
Module 2
8
11/5/2022
Verilog structure:
module half_adder (a, b, sum, carry);
input a;
input b;
output sum;
output carry;
assign sum = a ^ b;
assign carry = a & b;
endmodule
Module 2
9
11/5/2022
Assignment :
Qstn 1:
Write Verilog code for full adder.
Module 2
10
11/5/2022
Verilog ports:
3. inout:
Module 2
11
11/5/2022
2. Operators:
Perform logical operations like AND, OR and XOR.
a)i) Bitwise logical operators:
Operand type: Bit, Result type: Bit
Task 2:
If X = 1001 and Y = 0111, find Z = X ^ Y.
Module 2
12
11/5/2022
a)ii) Boolean logical operators:
Task 3:
If X = 1011 and Y = 0001, find X>1001 && X>Y
a)iii) Reduction operators:
Task 4:
If X = 1010, find Y = &X, where & is the Reduction AND operator.
Y= (Bit 3 & Bit 2 & Bit 1 & Bit 0)
Module 2
13
11/5/2022
b. Relational operators
Task 5:
If X = 1010 and Y = 10, evaluate X <= Y.
Module 2
14
11/5/2022
c. Arithmetic operators
Task 6:
If A = 1010 and B = 0011, evaluate A % B.
Module 2
15
11/5/2022
d. Shift and Rotate operators
Example if operand Y is 1110,
Y << 1 = 110x
(shift X one position left logical)
Task 7:
Find Y << 2
Y >> 1
Y >> 2
Module 2
16
11/5/2022
3. Datatypes
a. Nets
Value | Definition |
0 | false |
1 | true |
x | unknown |
z | high impedance |
Module 2
17
11/5/2022
b. Registers
c. Vectors
(net a has 3 bits and its initial value is decimal 7.
Module 2
18
11/5/2022
d. Integers
integer sum; (sum is declared as integer)
e. Real
real mass; (mass is declared as real)
f. Parameters
g. Arrays
Module 2
19
11/5/2022
Eg: parameter M =3;
integer carry [0:M]
carry is an integer having 4 elements, each element is of integer datatype.
Module 2
20
11/5/2022
Styles of description
Module 2
21
11/5/2022
Example:
module half_adder (a, b, sum, carry);
input a, b;
output sum, carry;
reg sum, carry;
always @ (a, b)
begin
# 10 sum = a ^ b; // after 10 ns
# 10 carry = a & b; // after 10 ns
end
endmodule
Module 2
22
11/5/2022
2. Structural
Example:
module half_adder (a, b, sum, carry);
input a, b;
output sum, carry;
xor x1 (sum, a, b);
and a1 (carry, a, b) ;
endmodule
Module 2
23
11/5/2022
3. Data-flow
Example:
module half_adder (a, b, sum, carry);
input a, b;
output sum, carry;
assign sum = a ^ b;
assign carry = a & b ;
endmodule
Module 2
24
11/5/2022
Verilog Data Flow Description
Module 2
25
11/5/2022
Highlights of Data-flow Description
Module 2
26
11/5/2022
Structure of Data-flow Description
1. Signal declaration and assignment statements
Here Y1 and Y2 are intermediaries.
Module 2
27
11/5/2022
Signal assignment:
Eg: assign sum <= a and b
This value is not yet assigned to sum.
Assign #10 sum = a & b // delay time of 10 ns
Module 2
28
11/5/2022
Module 2
29
11/5/2022
Constant declaration and assignment:
time period = 10; (10 simulation screen time units )
assign #10 sum = a ^ b ;
Module 2
30
11/5/2022
E’ | SEL | Output |
H | X | 0 |
L | 0 | A |
L | 1 | B |
A
B
E’
S
Y
2 X 1 mux
Y = ES’A + ESB
Module 2
31
11/5/2022
Assignment
Qstn 2:
Write Verilog data flow code for: