Professional Documents
Culture Documents
08 Intro To Verilog
08 Intro To Verilog
Digital Logic
http://www.ece.iastate.edu/~alexs/classes/
Intro to Verilog
x NOT x y AND x y OR
0 1 0 0 0 0 0 0
1 0 0 1 0 0 1 1
1 0 0 1 0 1
1 1 1 1 1 1
x x x x • y x x +y
y y
AND with Switches
AND Circuit
x=0 y=0
+
Battery _ Light
AND Circuit
x=0 y=1
+
Battery _ Light
AND Circuit
x=1 y=0
+
Battery _ Light
AND Circuit
x=1 y=1
+
Battery _ Light
NOT with Switches
NOT Circuit
Resistor
+
Battery _ Light
x=1
NOT Circuit
Resistor
+
Battery _ Light
x=0
NAND with Switches
NAND Circuit
Resistor
x=0
+
Battery _ Light
y=0
NAND Circuit
Resistor
x=0
+
Battery _ Light
y=1
NAND Circuit
Resistor
x=1
+
Battery _ Light
y=0
NAND Circuit
Resistor
x=1
+
Battery _ Light
y=1
NOR with Switches
NOR Circuit
Resistor
+
Battery _ Light
x=0 y=0
NOR Circuit
Resistor
+
Battery _ Light
x=0 y=1
NOR Circuit
Resistor
+
Battery _ Light
x=1 y=0
NOR Circuit
Resistor
+
Battery _ Light
x=1 y=1
The Three Basic Logic Gates
x NOT x y AND x y OR
0 1 0 0 0 0 0 0
1 0 0 1 0 0 1 1
1 0 0 1 0 1
1 1 1 1 1 1
x x x x • y x x +y
y y
NAND and NOR
x y NAND x y NOR
0 0 1 0 0 1
0 1 1 0 1 0
1 0 1 1 0 0
1 1 0 1 1 0
x • y x x +y
x
x y
XOR and XNOR
x y XOR x y XNOR
0 0 0 0 0 1
0 1 1 0 1 0
1 0 1 1 0 0
1 1 0 1 1 1
x x +y x x +y
y y
XNOR with Switches
XNOR Circuit
x=0 y=0
+
Battery _ Light
XNOR Circuit
x=0 y=1
+
Battery _ Light
XNOR Circuit
x=1 y=0
+
Battery _ Light
XNOR Circuit
x=1 y=1
+
Battery _ Light
XOR with Switches
XOR Circuit
x=0 y=0
+
Battery _ Light
XOR Circuit
x=0 y=1
+
Battery _ Light
XOR Circuit
x=1 y=0
+
Battery _ Light
XOR Circuit
x=1 y=1
+
Battery _ Light
7-Segment Display Example
7-Segment Display
f b
g
e c
d
Displaying Some Numbers
a a a
f b f b f b
g g g
e c e c e c
d d d
Displaying Some Hexadecimal Numbers
a a a a a a
f b f b f b f b f b f b
g g g g g g
e c e c e c e c e c e c
d d d d d d
Display of numbers
a = s0 c = s1 e = s0 g = s1 s0
b=1 d = s0 f = s1 s0
Intro to Verilog
History
• Created in 1983/1984
• SystemVerilog
• Verilog HDL
• VHDL
Verilog HDL != VHDL
• Verilog is closer to C
x1 x1
x x x1• x2 x1 + x2
x2 x2
You can build any circuit using only these three gates
x x
NOT gate
How to specify a NOT gate in Verilog
x y
NOT gate
How to specify a NOT gate in Verilog
x y not (y, x)
x1
f= x1• x2 and (f, x1, x2)
x2
x1
x2
f= x1 + x2 or (f, x1, x2)
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
k g
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
k g
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
k g
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
k g
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
Verilog Code for a 2-1 Multiplexer
k g
[ Figure 2.36 from the textbook ] [ Figure 2.37 from the textbook ]
2-to-1 Multiplexor in Verilog
(with abbreviated syntax)
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.40 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.40 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.40 from the textbook ]
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.40 from the textbook ]
2-to-1 Multiplexor in Verilog
(with behavioral specification)
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.42 from the textbook ]
Verilog Code for a 2-1 Multiplexer
• one output f
[ Figure 2.36 from the textbook ] [ Figure 2.42 from the textbook ]
Verilog Code for a 2-1 Multiplexer
• one output f
[ Figure 2.36 from the textbook ] [ Figure 2.42 from the textbook ]
always@ syntax
always @(x,y)
always @(x or y)
always @(*)
always @*
Verilog Code for a 2-1 Multiplexer
[ Figure 2.36 from the textbook ] [ Figure 2.43 from the textbook ]
Another Example
Let’s Write the Code for This Circuit
[ Figure 2.39 from the textbook ] [ Figure 2.38 from the textbook ]
Let’s Write the Code for This Circuit
[ Figure 2.39 from the textbook ] [ Figure 2.38 from the textbook ]
Let’s Write the Code for This Circuit
endmodule
[ Figure 2.39 from the textbook ] [ Figure 2.41 from the textbook ]
Yet Another Example
A logic circuit with two modules
a = s0 c = s1 e = s0 g = s1 s0
d = s0 f = s1 s0
b=1
The display module
a = s0
b=1
c = s1
d = s0
e = s0
f = s1 s0
g = s1 s0
[ Figure 2.46 from the textbook ]
Putting it all together
Putting it all together
Questions?
THE END