Introduction to Computing Lab Manual
Introduction to Computing Lab Manual
INTRODUCTION TO COMPUTING
LABORATORY MANUAL
TABLE OF CONTENT
ABOUT THE MANUAL ......................................................................................................................... 1
LAB 1: IMPLEMENTATION OF BOOLEAN FUNCTION ON BREADBOARD
WITH LOGIC GATES AND FUNCTIONAL ICS ............................................................................ 2
A. PRELAB .................................................................................................................2
I. IMPLEMENTATION OF DIGITAL CIRCUIT ON BREADBOARD ............2
II. QUESTIONS: .........................................................................................................6
B. LAB MANUAL: ...................................................................................................13
I. OBJECTIVES: .....................................................................................................13
II. LAB PREPARATION:........................................................................................13
III. LAB INSTRUCTION: .........................................................................................13
LAB 2: IMPLEMENTATION OF BASIC LOGIC GATES AND FUNCTIONAL ICs
ON FPGA 26
A. PRELAB ...............................................................................................................26
B. LAB MANUAL: ...................................................................................................34
I. OBJECTIVES: .....................................................................................................34
II. LAB PREPARATION:........................................................................................34
III. LAB INSTRUCTIONS:.......................................................................................34
LAB 3: COMBINATIONAL CIRCUIT AND SEQUENTIAL CIRCUIT DESIGN...... 48
A. PRELAB ...............................................................................................................48
B. LAB MANUAL: ...................................................................................................55
I. OBJECTIVES ......................................................................................................55
II. PREPARATION ..................................................................................................55
III. LAB INSTRUCTIONS ........................................................................................55
LAB 4: IMPLEMENTATION OF BASIC COMBINATIONAL AND SEQUENTIAL
LOGIC CIRCUITS ON FPGA............................................................................................................ 65
A. PRELAB ...............................................................................................................65
B. LAB MANUAL ....................................................................................................72
I. OBJECTIVES ......................................................................................................72
II. PREPARATION: .................................................................................................72
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 1
III. LAB INSTRUCTIONS ........................................................................................72
LAB 5: CIRCUIT IMPLEMENTATION ON BREADBOARD AND
COMMUNICATION WITH FPGA .................................................................................................... 90
A. PRELAB ...............................................................................................................90
B. LAB MANUAL ..................................................................................................104
I. OBJECTIVES: ...................................................................................................104
II. LAB PREPARATION:......................................................................................104
III. LAB INSTRUCTION: .......................................................................................104
APPENDIX 1: QUARTUS AND UBUNTU INSTALLATION ON WINDOWS..........117
A. UBUNTU INSTALLATION ON WINDOWS: ...............................................117
I. Download and install Xming and WSL2: ........................................................117
II. Install Ubuntu on Windows: .............................................................................117
III. Some basic commands in Linux........................................................................119
B. INSTALL QUARTUS 13.0SP1 .........................................................................122
APPENDIX 2: DIGITAL CIRCUIT DESIGN FLOW USING SYSTEMVERILOG .123
A. DESIGN FLOW .................................................................................................123
B. COMBINATIONAL LOGIC MODELING ....................................................124
I. Problem:..............................................................................................................124
II. Design: .................................................................................................................124
C. SEQUENTIAL LOGIC/FSM MODELING ....................................................138
I. Problem:..............................................................................................................138
II. Problem analysis: ...............................................................................................138
III. Design: .................................................................................................................139
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 2
ABOUT THE MANUAL
This document is intended to serve as a lab manual for students enrolled in Introduction to
Computing Lab at HCMC University of Technology. All the Lab Experiment is designed for students
to:
Lab 1 – Implementation of Boolean function on breadboard with Logic Gates and Functional ICs.
Lab 2 – Implementation of Boolean function on FPGA with Logic Gates and Functional Digital ICs.
In order to complete the lab on time, all students are required to do prelabs before each class.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 1
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
A. PRELAB
I. IMPLEMENTATION OF DIGITAL CIRCUIT ON BREADBOARD
Breadboard is the component on which the circuits can be set up and external experiments can
be done. The information about usage is given in Figure 1.1 .
Before you insert a DIP into the breadboard, make sure all pins are straight. When you insert
a DIP in the breadboard, make sure that the pins on one side of the DIP are not connected to
the pins on the other side of the DIP. This means that the DIP must straddle one of the long
gaps that divide the breadboard into separate sections.
- Providing access to the DIP:
As you wire your circuit, be sure to leave yourself easy access to the DIP's pins so that you can
touch them with a probe and so that you can replace the DIP without disconnecting any wires.
In particular:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 2
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Never pass a wire over a DIP. Instead, route the wires around the DIP.
When you run wires to a DIP, use the breadboard holes farther away from the DIP before
you use the holes that are closer.
- Removing a DIP:
Do not use your fingers to remove a DIP from the breadboard. It's too easy for your fingers to
slip, causing the DIP to twist. This results in bent pins. Instead, use a chip puller to gently pull
the chip up from the board.
- Input and output connections:
There are two logic levels of input data: HIGH (1) level and LOW (0) level. In this course,
almost digital ICs are TTL, in which HIGH level and LOW level are prescribed as below:
Input: the signal is called HIGH when the voltage is between 2V and 5V, and LOW when
the voltage is from 0 to 0.8V.
Output: the signal is called HIGH when the voltage is between 2.7V and 5V, and LOW
when the voltage is from 0 to 0.5V.
We usually apply 5V to implement HIGH level signal and 0V for LOW level signal.
In this lab, DIP switches are used to supply input signal. Several ways of input connections are
shown in Figure 1.2; resistors in these circuits are usually chosen 10 Kohm. It is recommended
that students implement input circuit as in Figure 1.2 (c), in which the signal equal 1 when the
switch is at upper position and vice versa.
Outputs are commonly displayed in LEDs, bar-LEDs, 7-segment LEDs,… Figure 1.3 shows
how to connect the output to LED; LEDs in the left circuit will be on when the signal is 1 while
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 3
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
level 1 signal turn off the lights in the right circuit. Resistors in output circuits are usually
chosen 1 Kohm.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 4
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 5
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
II. QUESTIONS:
1. What is numbering principle in DIP IC?
3. If f1,f2,f3,f4 are respectively 0,1,1,0. Indentify status of each LEDs in below figure.
IC Definition Pins
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 6
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
74LS02
74LS04
74LS08
74LS32
74LS86
74LS125
74LS126
74LS138
74LS151
5. Compare IC 74LS125 and IC 74LS126. Explain the difference between these 2 ICs.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 7
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
7. Implement boolean function 𝑓(𝑥, 𝑦, 𝑧) = 𝑥̅ . 𝑦 + 𝑦̅𝑧 using NAND2 gates (2-input NAND
gates).
Convert the function using NAND equivalents:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 8
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
9. Implement boolean function 𝑓(𝑥, 𝑦, 𝑧) = m1 + m3 + m6, using NOR2 gates (2-input NOR
gates)
Convert the function using NOR equivalents:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 9
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 10
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 11
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 12
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
B. LAB MANUAL:
I. OBJECTIVES:
- Getting familiar with TTL 74LS series IC.
- Implementation of simplified Boolean functions with different logic gate combinations.
- Getting to know functional combinational ICs.
II. LAB PREPARATION:
Students have to complete Prelab before class. Students without lab preparation won’t be
allowed to join in the class.
III. LAB INSTRUCTION:
EXPERIMENT 1
Objectives: Implementation of a function math 𝑓(𝑥, 𝑦, 𝑧) = 𝑥̅ . 𝑦 + 𝑦̅𝑧 in AND – OR form.
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS04, 74LS08, 74LS32
- Connection wires.
Procedure:
- Construct the circuit and apply the power (remember to note pin numbers on ICs).
- Apply all possible combinations to the inputs; obtain the output values then take note of
the output fTest in the Table 1.1.
x y z f fTest fnand
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 1.1
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 13
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 14
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
- Construct the circuit and apply the power (remember to note pin numbers on ICs).
- Apply all possible combinations to the inputs and obtain and take note of the outputs
fNAND in the Table 1.1
EXPERIMENT 2
Objectives: Implementation of a boolean function given in the truth table (Figure 1.2).
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS04, 74LS08, 74LS32
- Connection wires.
Procedure:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 15
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
- Construct the circuit and apply the power (remember to note pin numbers on ICs).
- Apply all possible combinations to the inputs; obtain the output values then take note of
the output fTest in the Table 1.2.
- Write the Boolean expression: F =
x y z f fTest fnor
0x 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 0
Table 1.2
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 16
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 17
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
- Construct the circuit and apply the power (remember to note pin numbers on ICs).
- Apply all possible combinations to the inputs; obtain the output value then take note of
the outputs fNOR in the Table 1.2.
EXPERIMENT 3
Objectives: Implementation of a boolean function given in the following schematic.
Figure 1.6
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS04, 74LS08, 74LS32, 74LS86.
- Connection wires.
Procedure:
- Construct the circuit and apply the power (remember to note pin numbers on ICs).
- Apply all possible combinations to the inputs; obtain the output value then take note of the
outputs F1 in the Table 1.3.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 18
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
x y z F1 F2
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 1.3
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 19
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
EXPERIMENT 4
Objectives: Implementation of a Boolean function 𝑓 (𝑥, 𝑦, 𝑧) = ∑(2,3,5,7) by using a 8x1
Multiplexer.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 20
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs): 74LS151, 74LS04.
- Connection wires.
Procedure:
Draw the schematic diagram to implement the boolean function using 74LS151.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 21
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Application cicruit
- Construct the circuit and apply the power (remember to note IC pin numbers).
- Apply all possible combinations to the inputs and obtain and take note of the outputs FTest in
the Table 1.4.
x y z f fTest
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 1.4
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 22
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
EXPERIMENT 5
Objectives: Implementation of a Boolean function (𝑥, 𝑦, 𝑧) = ∑(2,3,5,7) by using a 3x8
Decoder.
Equipments: x y z f fTest
- Analog Discovery Studio 0 0 0
- Integrated Circuits (ICs): 74LS138, and other logic 0 0 1
gates. 0 1 0
- Connection wires.
0 1 1
Connection diagram and function table: 1 0 0
1 0 1
1 1 0
1 1 1
Table 1.5
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 23
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
Procedure:
Draw the schematic diagram to implement the boolean function using 74LS138.
Application cicruit
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 24
Lab 1: Implementation of Boolean function on breadboard with logic gates and functional ICs
- Construct the circuit and apply the power (remember to note IC pin numbers).
- Apply all possible combinations to the inputs and obtain and take note of the outputs FTest in
the Table 1.5.
Student’s implementation on breadboard
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 25
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
LAB 2: IMPLEMENTATION OF
BASIC LOGIC GATES AND
FUNCTIONAL ICs ON FPGA
Student’s names: Class:
Student ID: Date:
A. PRELAB
In Lab 2, the project use the LEDR, LEDG, and SW as peripherals. Below are the basic
headers code of these peripherals when students synthesize a project on Intel Quartus. (Note:
Import file DE2_pin_list/assignment).
Note, the top-level file of the project must be named the name of the header file, for example
"lab2tn1_wrapper", with the module "lab2tn1" being the module containing the code
describing the design of experiment 1.
Ex: The experiment of writing hardware design in SystemVerilog language for the function
𝑓 (𝑥, 𝑦, 𝑧) = x̅𝑦𝑧 as experiment 1 of lab 2, we have the following SystemVerilog code:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 26
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Next, students perform the simulation, and load the Kit as instructed at Lab 0.
For the experiments that require the use of IC 74LS151/74LS138, students write the code
describing this IC and call that module as above.
PREPARATION 1
Objective: Implementation of Boolean function 𝑓 (𝑥, 𝑦, 𝑧) = 𝑥̅ 𝑦𝑧 + 𝑥𝑦
̅̅̅𝑧 + 𝑥𝑦 on FPGA DE2.
Procedure:
● Construct the truth table of 𝑓 (𝑥, 𝑦, 𝑧) = 𝑥̅ 𝑦𝑧 + 𝑥𝑦
̅̅̅𝑧 + 𝑥𝑦
● Write the SystemVerilog code that describe 𝑓(𝑥, 𝑦, 𝑧) = 𝑥̅ 𝑦𝑧 + 𝑥𝑦
̅̅̅𝑧 + 𝑥𝑦s
instructed in lab 0 with the following pin assignment:
○ Pins x, y, z assigned to SW2, SW1, SW0 and LEDR2, LEDR1, LEDR0
respectively.
○ Pin f assigned to LEDG0.
● Compile and simulate the project. The output waveform have to show all possible input
combinations. Capture the output waveform.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 27
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Waveform:
PREPARATION 2
Objectives: Write SystemVerilog code to X Y Z F Fsim FKit
describe the truth table in Table 2.1. 0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
Table 2.1
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 28
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Procedure:
● Write the SystemVerilog code that describe the digital circuit in Figure 2.3 with the
following pin assignment:
○ Pins x, y, z assigned to SW2, SW1, SW0 and LEDR2, LEDR1, LEDR0
respectively.
○ Pin f assigned to LEDG0.
● Compile and simulate the project. The output waveform have to show all possible input
combinations. Capture the output waveform.
Waveform:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 29
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
PREPARATION 3
Objective: Write SystemVerilog code to describe the digital circuit in Figure 2.3.
Figure 2.3
Procedure:
● Write the SystemVerilog code that describe the digital circuit in Figure 2.3 with the
following pin assignment:
○ Pins x, y, z assigned to SW2, SW1, SW0 and LEDR2, LEDR1, LEDR0
respectively.
○ Pin f assigned to LEDG0.
● Compile and simulate the project. The output waveform have to show all possible input
combinations. Capture the output waveform.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 30
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Waveform:
PREPARATION 4
Objective: Write SystemVerilog code to describe IC Multiplexer 74LS151. Implement
function 𝑓 (𝑥, 𝑦, 𝑧) = ∑(1,2,4,7) using that multiplexer.
Procedure:
● Write SystemVerilog code describe IC multiplexer 74LS151 operation.
● Using above multiplexer, write SytemVerilog code implementing Boolean function
𝑓 (𝑥, 𝑦, 𝑧) = ∑(1,2,4,7):
○ Pins x, y, z assigned to SW2, SW1, SW0 and LEDR2, LEDR1, LEDR0
respectively
○ Pin f assigned to LEDG0
○ Call IC 74LS151 as a submodule.
● Compile and simulate the project. The output waveform have to show all possible input
combinations. Capture the output waveform.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 31
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Waveform:
PREPARATION 5
Objective: Write SystemVerilog code to describe IC Decoder 74LS138. Implement function
𝑓 (𝑥, 𝑦, 𝑧) = ∑(0,2,5,7) using that decoder.
Procedure:
● Write SystemVerilog code describe IC decoder 74LS138 operation.
● Using above decoder, write SytemVerilog code implementing Boolean function
𝑓 (𝑥, 𝑦, 𝑧) = ∑(0,2,5,7):
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 32
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Waveform:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 33
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
B. LAB MANUAL:
I. OBJECTIVES:
- To prepare well for the test, students MUST read Appendix 1 first and complete the
steps of Sample lab in Appendix 2, and submit it with Prelab 2 before entering class.
- Students must complete and submit Prelab 2 before entering class.
- Students read the appendix and the Kit DE2 Manual to understand how to use the DE2
Kit, wiring, peripherals, and how to use Quartus software to simulate and synthesize
circuits. Students refer to the documentation to understand how to write hardware
designs in the SystemVerilog language.
EXPERIMENT 1
Objectives: Implementation of a function math 𝑓(𝑥, 𝑦, 𝑧) = 𝑥̅ 𝑦𝑧 + ̅̅̅𝑧
𝑥𝑦 + 𝑥𝑦 on DE 2 kit.
Procedure:
x y z f fSim fKit
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 2.2
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 34
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Apply all possible combinations to the inputs and take note the outputs in the f column
of Table 2.2.
➢ Synthesize the SystemVerilog design and take note the output in the fsim column in
Table 2.2.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 35
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Students view the result of the circuit (Tool → Netlist Viewer → RTL Viewer). Is this
result similar to the logic gate diagram drawn above? Exlain.
➢ Download the code to DE2 Kit. Does the design perform exactly as required? Take
note the results in f Kit column of Table 2.2
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 36
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
EXPERIMENT 2
Objectives: Implementation of a boolean function given in the truth table on DE 2 kit.
X Y Z F Fsim FKit
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
Table 2.3
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 37
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Procedure:
➢ Write the Boolean expression of f (x, y, z):
➢ Write the SystemVerilog describe the operation of 𝑓 (𝑥, 𝑦, 𝑧) with the pin assignment
as follows:
o Pins x, y, z assigned to SW2, SW1, SW0 and LEDR2, LEDR1, LEDR0
respectively.
o Pin f assigned to LEDG0.
➢ Synthesize the SystemVerilog design and take note the output in the fsim column in
Table 2.3.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 38
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Students view the result of the circuit (Tool → Netlist Viewer → RTL Viewer). Is this
result similar to the logic gate diagram drawn above? Exlain.
➢ Download the code to DE2 Kit. Does the design perform exactly as required? Take
note the results in f Kit column of Table 2.3.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 39
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
EXPERIMENT 3
Objectives: Implementation of a boolean function given in the following schematic.
X Y Z Fsim FKit
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Figure 2.4 Table 2.4
Procedure:
➢ Write the SystemVerilog describe the operation of 𝑓 (𝑥, 𝑦, 𝑧) with the pin assignment
as follows:
o Pins x, y, z assigned to SW2, SW1, SW0 and LEDR2, LEDR1, LEDR0
respectively.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 40
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Students view the result of the circuit (Tool → Netlist Viewer → RTL Viewer). Is this
result similar to the logic gate diagram drawn above? Exlain.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 41
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Download the code to DE2 Kit. Does the design perform exactly as required? Take
note the results in f Kit column of Table 2.4.
EXPERIMENT 4
Objectives: Write SystemVerilog code to describe IC x y z f fsim fKit
Multiplexer 74LS151. 0 0 0
Implement function 𝑓 (𝑥, 𝑦, 𝑧) = ∑(1,2,4,7) using that 0 0 1
multiplexer. 0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 2.5
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 42
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Procedure:
➢ Draw the circuit that implement f(x,y,z) using 74LS151.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 43
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Students view the result of the circuit (Tool → Netlist Viewer → RTL Viewer). Is this
result similar to the logic gate diagram drawn above? Exlain.
➢ Download the code to DE2 Kit. Does the design perform exactly as required? Take
note the results in f Kit column of Table 2.5.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 44
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
EXPERIMENT 5
Objectives: Write SystemVerilog code to describe IC x y z f fsim fKit
Decoder 74LS138. 0 0 0
Implement function 𝑓 (𝑥, 𝑦, 𝑧) = ∑(0,2,5,7) using that 0 0 1
decoder. 0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 2.6
Procedure:
➢ Draw the circuit that implement f(x,y,z) using 74LS138.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 45
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
➢ Synthesize the SystemVerilog design and take note the output in the fsim column in
➢ Students view the result of the circuit (Tool → Netlist Viewer → RTL Viewer). Is this
result similar to the logic gate diagram drawn above? Exlain.
➢ Download the code to DE2 Kit. Does the design perform exactly as required? Take
note the results in f Kit column of Table 2.5.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 46
Lab 2: Implementation of Boolean function with logic gates and functional ICs on FPGA
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 47
Lab 3: Combinational Circuit – Sequential Circuit Design
A. PRELAB
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 48
Lab 3: Combinational Circuit – Sequential Circuit Design
Application Circuit:
GND
+5V
8
14
13
12
11
10
14
13
12
11
10
14
13
12
11
10
1 2 34
ON
1
7
GND
+5V
Question 2: Design a 4 bit full adder/full subtractor circuit using IC 74LS283. The circuit has three inputs: Sel
(1bit), A (4bit) và B (4bit) and 2 outputs: S (4bit), Cout (1bit).
- When Sel = 0, S = A + B
- When Sel = 1, S = A – B
74LS283 is an IC 4-bit ripple-carry adder. It adds two 4-bit binary numbers [A (A4A3A2A1) and B
(B4B3B2B1)] and a carry in bit (Cin). It is composed of four fulladders. The augend’s bits of “B” are
added to the addend bits of “A” respectfully of their binary position. Each bit addition produces a sum (S)
and a carry out (Co). The carry out is then transmitted to the carry in (Ci) of the next higher-order bit. The
final result produces a sum of four bits S (S4S3S2S1) plus a carry out (Cout) bit.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 49
Lab 3: Combinational Circuit – Sequential Circuit Design
Draw logic diagram and show how to design: 4-bit parallel adder
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 50
Lab 3: Combinational Circuit – Sequential Circuit Design
Application circuit:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 51
Lab 3: Combinational Circuit – Sequential Circuit Design
Application circuit:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 52
Lab 3: Combinational Circuit – Sequential Circuit Design
Question 4: Design sequential circuit for the state diagram in Figure 3.4:
State table:
Required ICs:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 53
Lab 3: Combinational Circuit – Sequential Circuit Design
Application circuit:
GND
+5V
8
14
13
12
11
10
14
13
12
11
10
14
13
12
11
10
1 2 34
ON
1
7
GND
+5V
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 54
Lab 3: Combinational Circuit – Sequential Circuit Design
B. LAB MANUAL:
I. OBJECTIVES
Students have to complete Prelab before class. Students without lab preparation won’t
be allowed to join in the class..
III. LAB INSTRUCTIONS
EXPERIMENT 1
Objective: Using logic gates, design Full Adder circuit.
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS86, 74LS08, 74LS32
- Connection wires.
Procedure:
➢ Logic diagram:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 55
Lab 3: Combinational Circuit – Sequential Circuit Design
➢ Application circuit:
GND
+5V
8
14
13
12
11
10
14
13
12
11
10
14
13
12
11
10
1 2 34
ON
1
7
GND
+5V
Table 3.3
EXPERIMENT 2
Objectives: Design a 4 bit full adder/full subtractor circuit using IC 74LS283. The circuit has three inputs:
Sel (1bit), A (4bit) và B (4bit) and 2 outputs: S (4bit), Cout (1bit).
- When Sel = 0, S = A + B
- When Sel = 1, S = A – B
Equipments:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 56
Lab 3: Combinational Circuit – Sequential Circuit Design
➢ Application circuit:
➢ Construct the circuit and apply the power. Apply all possible combinations to the
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 57
Lab 3: Combinational Circuit – Sequential Circuit Design
output values given in Table 3.4 and take note of the outputs (Cout S4 S3 S2 S1) in
the Table 3.4:
A Số A Số B B Ngõ ra (base
S (base (base
10)
10) 10)
A4 A3 A2 A1 B4 B3 B2 B1 Cout S4 S3 S2 S1
0 10 1 0 1 0 1 0 1 1 11
0 14 1 1 1 0 1 0 1 0 10
0 12 1 1 0 0 0 1 0 0 4
0 5 0 1 0 1 0 0 1 1 3
0 4 0 1 0 0 0 1 0 1 5
0 13 1 1 0 1 1 1 0 1 13
0 6 0 1 1 0 1 0 0 1 9
0 2 0 0 1 0 1 0 0 0 8
0 1 0 0 0 1 0 0 1 0 2
0 7 0 1 1 1 0 0 0 1 1
0 15 1 1 1 1 0 1 1 0 6
0 9 1 0 0 1 1 1 1 1 15
1 10 1 0 1 0 1 0 1 1 11
1 14 1 1 1 0 1 0 1 0 10
1 12 1 1 0 0 0 1 0 0 4
1 5 0 1 0 1 0 0 1 1 3
1 4 0 1 0 0 0 1 0 1 5
1 13 1 1 0 1 1 1 0 1 13
1 6 0 1 1 0 1 0 0 1 9
1 2 0 0 1 0 1 0 0 0 8
1 1 0 0 0 1 0 0 1 0 2
1 7 0 1 1 1 0 0 0 1 1
1 15 1 1 1 1 0 1 1 0 6
1 9 1 0 0 1 1 1 1 1 15
Table 3.4
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 58
Lab 3: Combinational Circuit – Sequential Circuit Design
EXPERIMENT 3
Objectives: Examination of D Flipflop – IC 74LS74.
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS74.
- Connection wires.
Preliminary information: The schematic symbol and the function table of 74LS74 dual rising
edge triggered D flip-flops is shown in Fig. 3.5.
Figure 3.5 The schematic symbol and the function table of 74LS74 dual rising edge triggered
D flip-flops.
Procedure:
➢ Logic diagram:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 59
Lab 3: Combinational Circuit – Sequential Circuit Design
➢ Application circuit:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 60
Lab 3: Combinational Circuit – Sequential Circuit Design
EXPERIMENT 4
Objectives: Design 0 →7 up counter, using IC D-FF 74LS74.
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS74.
- Connection wires.
Procedure:
➢ Logic diagram:
➢ Application circuit:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 61
Lab 3: Combinational Circuit – Sequential Circuit Design
➢ Construct the circuit and apply the power. In the beginning of the experiment, connect
the Clock to a switch.
➢ Set A = B = 1, supply Clock signal using Digital Pattern Generator. Set the parameter
as below:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 62
Lab 3: Combinational Circuit – Sequential Circuit Design
EXPERIMENT 5
Objectives: Design sequential circuit for the state
diagram in Figure 3.6.
Equipments:
- Analog Discovery Studio
- Integrated Circuits (ICs) : 74LS74, 74LS08,
74LS32.
- Connection wires.
Procedure:
➢ Logic diagram: Figure 3.6
➢ Application circuit:
GND
+5V
9
8
14
13
12
11
10
14
13
12
11
10
14
13
12
11
10
1 2 34
ON
1
GND
+5V
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 63
Lab 3: Combinational Circuit – Sequential Circuit Design
Connect the Clock and input X to two DIOs of Analog Discovery Kit and set them as
a switch. Move the switch X to either on or off position according to the table, turn on
the switch and then turn off to make a pulse into CLK input
➢ Complete the table below to show the states corresponding to the given input sequence:
Input 0 1 1 0 0 0 1
State A
Verify that this sequence follows the transitions as dictated by the state transition table
in Figure 3.6.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 64
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
A. PRELAB
PREPARATION 1
Objectives: Describe Full Adder circuit using SystemVerilog.
Read the following program.
module FA_ex1(
input A,
input B,
input Ci,
output S,
output Co);
assign S = A ^ B ^ Ci;
assign Co=(A&B)|(A&Ci)|(B&Ci);
Figure 4.1: Full Adder
endmodule
➢ Compile the above program and simulate the output waveform in all cases of the input.
Capture the output waveform..
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 65
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
PREPARATION 2
Objective: Describe 4-bit adder/subtractor using SystemVerilog.
Design 4-bit adder/subtractor which has 2 inputs A and B respectively, 1 output S and the flags
Ci and Co. Its operation depends on the input sel:
o sel=0: S = A + B
o sel=1: S = A - B
Students write the SystemVerilog code that performs the operation of the combinational circuit
in two methods:
- Method 1: Instantiate Full Adder module (using preparatory lesson 1).
Hint:
wire wire0,wire1,wire2
FA_ex1 u0(.Ci(0),.A(A[0]),.B(B[0]),.S(S[0]),.Co(wire0));
FA_ex1 u1(.Ci(wire1),.A([1]),.B([1]),.S(S[1]),.Co(wire1));
…
Hint:
always@(*) assign S=(sel)?A+B:A-B;
if (sel)
…
else
…
➢ Compile the above program and simulate the output waveform in all cases of the input.
Capture the output waveform.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 66
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
PREPARATION 3
Objective: Design the combinational circuit that decodes BCD numbers to common anode 7-
segment LED codes.
Complete the truth table of the decoder circuit:
I3 I2 I1 I0 g f e d c b a
0 0 0 0 1 0 0 0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0 Figure 4.2 Common anode 7-segment
1 0 0 1 LED
1 0 1 0 (source: internet)
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
Table 4.1
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 67
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
PREPARATION 4
Objective: Design a circuit that converts a pulse of frequency 50 MHz to a pulse of frequency 1
Hz.
Gợi ý:
- A pulse of frequency 50MHz will make 50 000 000 oscillations in 1s. (1 oscillation consists
of 1 high-level and 1 low-level).
- A pulse with a frequency of 1Hz will make 1 oscillation in 1s.
- Applying the principle of the counter circuit, the circuit receives an input pulse of 50MHz,
when the input pulse counts 25 000 000, that will reverse the state of the output pulse.
Hint:
integer i=0;
reg temp=0;
always_ff@(posedge clk)
begin
i = i + 1;
if (i == 25 000 000) begin
out = ~ out;
i = 0;
end
end
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 68
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Compile the above program and simulate the output waveform in all cases of the input.
Capture the output waveform.
PREPARATION 5
Objective: Describe a state machine using systemverilog.
➢ Draw a state machine for the requirement in experiment 5 of Lab 4. Students explain the
meaning of states and encode the state into a bit string.
➢ Students design the state machine above using systemverilog language. (Refer to the
program below.) Assume the state machine have :
o Input: X (1 bits)
o Output: Y (1 bits)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 69
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 70
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Compile the above program. Then, students simulate the output waveform in all cases
of the input. Capture the output waveform.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 71
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
B. LAB MANUAL
I. OBJECTIVES
II. PREPARATION:
- To prepare well for the test, students MUST read Appendix 1 first and complete the steps
of Sample lab in Appendix 2, and submit it with Prelab 4 before entering class.
- Students must complete and submit Prelab 4 before entering class.
- Students read the appendix and the Kit DE2 Manual to understand how to use the DE2
Kit, wiring, peripherals, and how to use Quartus software to simulate and synthesize
circuits. Students refer to the documentation to understand how to write hardware
designs in the SystemVerilog language.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 72
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students write the SystemVerilog code to perform the function's circuit as instructed
from Prelab with the pin assignment as follows:
o Pins A[3:0] assigned to SW[3:0]
o Pins S[3:0] assigned to LEDR[3:0].
➢ Students compile the above program. Then, students simulate the output waveform in all
cases of the input. Capture the output waveform.
(Insert a photo demonstrating that the student has simulated the circuit)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 73
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students view the results (Tool → Netlist Viewer → RTL Viewer) of the circuit.
(Insert a photo proving that the student has uploaded the Kit)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 74
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
EXPERIMENT 2
Objective: Design the combinational circuit that implements the ALU
The ALU calculates two 4-bit numbers (the two inputs are A and B respectively, the output is
S, the flags are Ci and Co) through the 2-bit input: Sel.
- If Sel=00: S=A+B
- If Sel=01: S=A-B
- If Sel=11: S=A OR B
➢ Students write the SystemVerilog code to perform the function's circuit as instructed
from Prelab with the pin assignment as follows:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 75
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students compile the above program. Then, students simulate the output waveform in all
cases of the input. Capture the output waveform.
(Insert a photo demonstrating that the student has simulated the circuit).
➢ Students view the results (Tool → Netlist Viewer → RTL Viewer) of the circuit..
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 76
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
(Insert a photo proving that the student has uploaded the Kit)
EXPERIMENT 3
Objective: Design a 3-bit down counter circuit.
The count value changes every 1s. The output is connected to a common anode 7-segment LED.
In addition, the counter has an RST pin (active high) used to reset the counter state to 0.
Hint:
- The clock signal is generated from the frequency divider from 50MHz to 1Hz.
- Students use the 7-segment LED decoder module in PRELAB, connecting the output of
the counter to the input of the module.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 77
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students write the SystemVerilog code to perform the function's circuit as instructed
from Prelab with the pin assignment as follows:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 78
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students compile the above program. Then, students simulate the output waveform in all
cases of the input. Capture the output waveform.
(Insert a photo demonstrating that the student has simulated the circuit)
➢ Students view the results (Tool → Netlist Viewer → RTL Viewer) of the circuit.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 79
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
(Insert a photo proving that the student has uploaded the Kit)
EXPERIMENT 4
Objective: Design a 4-bit up counter circuit from 5 to 14.
The count value changes every 1s. The output is connected to a common anode 7-segment LED.
In addition, the counter has an RST pin (active high) used to reset the counter state to 0.
Hint:
- The clock signal is generated from the frequency divider from 50MHz to 1Hz.
- Students use the 7-segment LED decoder module in PRELAB, connecting the output
of the counter to the input of the module.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 80
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students write the SystemVerilog code to perform the function's circuit as instructed
from Prelab with the pin assignment as follows:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 81
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students compile the above program. Then, students simulate the output waveform in all
cases of the input. Capture the output waveform.
(Insert a photo demonstrating that the student has simulated the circuit)
➢ Students view the results (Tool → Netlist Viewer → RTL Viewer) of the circuit.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 82
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
(Insert a photo proving that the student has uploaded the Kit)
EXPERIMENT 5
Objective: Design a sequential circuit has 1 input (X) and 1 output (Z). Output Z = 1 if the total
number of bit 1 received is divisible by 3 (0, 3, 6, 9, … are numbers divisible by 3 ) and the total
number of 0 bits received is an even number (greater than 0).
Note:
- Students design a sequential circuit according to Mealy or Moore type state machines.
- The clock signal is generated from the frequency divider from 50MHz to 1Hz.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 83
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students write the SystemVerilog code to perform the function's circuit as instructed
from Prelab with the pin assignment as follows:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 84
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students compile the above program. Then, students simulate the output waveform in all
cases of the input. Capture the output waveform.
(Insert a photo demonstrating that the student has simulated the circuit)
➢ Students view the results (Tool → Netlist Viewer → RTL Viewer) of the circuit.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 85
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
(Insert a photo proving that the student has uploaded the Kit)
EXPERIMENT 6
Objective: Describe FSM using SystemVerilog.
An automatic pet food and water supply system with 2 inputs are 2 push buttons RED, BLUE;
and 2 outputs are FOOD, WATER signals to activate the food and water
• RED button (R signal, pressing R=1, otherwise R=0): when the animal needs to eat,
press the RED button 3 times. Then signal F (FOOD) = 1 to activate the food supply
machine.
• BLUE button (signal B; pressing B=1, otherwise B=0): when the animal wants to
drink, press the BLUE button 2 times. Then signal W (WATER) = 1 to activate the
water supply machine.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 86
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
Note:
- Students design a sequential circuit according to Mealy or Moore type state machines.
- The clock signal is generated from the frequency divider from 50MHz to 1Hz
- When the signal F or W is equal to 1, if any button is pressed, the system will return to
the reset state.
➢ Students write the SystemVerilog code to perform the function's circuit as instructed
from Prelab with the pin assignment as follows:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 87
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students compile the above program. Then, students simulate the output waveform in all
cases of the input. Capture the output waveform.
(Insert a photo demonstrating that the student has simulated the circuit)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 88
Lab 4: Implementation of combinational circuit and sequential circuit on FPGA.
➢ Students view the results (Tool → Netlist Viewer → RTL Viewer) of the circuit.
(Insert a photo proving that the student has uploaded the Kit)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 89
Lab 5: Circuit implementation on breadboard and communication with FPGA.
A. PRELAB
Part I: Creating a 1 Hz Clock for the DE 2 Kit
Kit DE2 CLOCK_50 pin is connected to a source of 50 MHz clock on the PCB. If connect the
design to this pin, you get this clock speed (Oscillate 50 million times in 1 second). In more common
real world applications , sometimes we need changes at 1 time per second (Clock 1 Hz).
To generate 1 Hz Clock on Kit DE2, as studied in LAB 4, you need to load a register with a value
of 50 million, then decrease the register value each clock. Use a flag to compare the register value with
zero, we now know when the register oscillated for 50 million times (or 1 second in this scenario). The
flag is our 1 Hz clock.
Requirement: Write SystemVerilog code for 1 Hz Clock Generator module which blinks LEDR0
on Kit De2 every 1 second.
Example System Verilog code for this module :
// Ho Chi Minh University of Technology
// Department of Electronics
//
//
///////////////////////////////////////////////
module secgen (
input clk,
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 90
Lab 5: Circuit implementation on breadboard and communication with FPGA.
input rst,
output sec
);
///////////////////////////////////////////////
///////////////////////////////////////////////
wire tmpzr;
if (rst)
else if (tmpzr)
else
end
endmodule
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 91
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Part II: State machine for Traffic lights control manual mode
Draw the state machine for Traffic lights control manual mode. Read the requirement for
Experiment 1 Lab 5.
Requirements: Students should refer to the topic and draw the state machine for the main controller
of this system:
Part III: State machine for Traffic lights control Autonomous mode
Draw the state machine for Traffic lights control Autonomous mode. Read the requirement for
Experiment 2 Lab 5.
Requirements: Students should refer to the topic and draw the state machine for the main controller
of this system:
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 92
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Students refer to the DE2 Terrasic kit datasheet and learn the order of GPIO_0 and GPIO_1 pins,
how to install LEDs to GPIO_0 of the DE2 kit.
Requirements: Students draw how to connect the circuit with GPIO_0 of Kit DE2 to LED (note
the aesthetics) and resistors
Students refer to datasheet IC led 7 segment 5161BS (For Common Anode LED)
Requirements: Students draw how to connect the GPIO_0 of Kit DE2 to 7-segment LED (note the
aesthetics)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 93
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Students refer to datasheet IC decoding 7-segment led 74LS47 (For LED Common Anode)
Requirements: Students draw how to install the circuit connecting GPIO_0 of Kit DE2 to IC 74LS47
to 7-segment LED (note the aesthetics)
Students need to refer to the 16x2 LCD datasheet, most of which use the HD44780 control chip with
the following pinout:
LCD requires students to send Hex codes in the form of commands, which include the HEX
code to start and the HEX Code to write / erase content.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 94
Lab 5: Circuit implementation on breadboard and communication with FPGA.
The 16×2 LCD module has a preset command instruction set. Each command will make the module
perform a specific task. Commonly used commands and their functions are given in the table below
Command Function
0F LCD is on, pointer is on, pointer is
blinking on
01 Clear full screen
02 Return to home screen
04 Cursor reduction
06 Increment pointer
0E Screen on, cursor blinking off
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 95
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Initialize LCD
The steps that must be taken to initialize the LCD are given below and these steps are
common for most applications.
B1: Send 38H to 8-bit data line for initialization
B2: Send 0FH to turn on the LCD, the cursor is ON and the cursor is blinking ON.
B3: Send 06H to increase the cursor position.
B4: Send 01H to clear the screen and return the cursor.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 96
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Requirements: Students learn the meaning of LCD pins. Students write SystemVerilog
hardware code with the function of loading the LCD with the words "Chuan bi TN5"
Refer to the example LCD module:
///////////////////////////////////////////////
// Department of Electronics
//
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 97
Lab 5: Circuit implementation on breadboard and communication with FPGA.
//
///////////////////////////////////////////////
module lcddisp_ex(
input clk,
);
//////////////////////////////////////////////////////
integer j = 1;
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 98
Lab 5: Circuit implementation on breadboard and communication with FPGA.
end
///////////////////////////////////////////////////////////
integer i = 0; //
i = i + 1; lcd_e = 1;
data = Datas[j];
end
i = i + 1; lcd_e = 0;
end
j = j + 1; i = 0;
end
else i = 0;
//-- LCD_RS signal should be set to 0 for writing commands and to 1 for writing data
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 99
Lab 5: Circuit implementation on breadboard and communication with FPGA.
if (j <= 5 )
lcd_rs = 0;
lcd_rs = 1;
else if (j == 18)
lcd_rs = 0;
lcd_rs = 1;
j = 5;
end
else
lcd_rs = 1;
// lcd_rs = 1;
/// j = 5;
//end
end
endmodule
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 100
Lab 5: Circuit implementation on breadboard and communication with FPGA.
In addition, with the Contrast Voltage pin, students need to install a rheostat to adjust. Students
redraw the circuit diagram connecting GPIO to LCD.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 101
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 102
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 103
Lab 5: Circuit implementation on breadboard and communication with FPGA.
B. LAB MANUAL
I. OBJECTIVES:
- Apply theory to design in practice.
- Combines knowledge of hardware description languages and digital circuits.
II. LAB PREPARATION:
Request: Design a traffic light system for an intersection with the following parameters:
Input (input):
- Buttons include:
o 1 Switch to change the direction the vehicle is moved (Use SW1 button on
Kit De 2)
Output (output):
- Students use Expansion Header output on Kit De 2 (using GPIO_0) to connect to the
following components:
- Two luminaires (The other two facing each other are optional) including:
o 1 Red Led
o 1 Green Led
o 1 Yellow Led
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 104
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Operation Description:
- After RESET, the traffic light system automatically operates in the mode
- In control mode:
o The direction the vehicle was previously moved changes from green to
yellow, the countdown light shows 3 seconds and counts down to 0 and then
turns to red.
o The other direction keeps the red light until the previous direction turns red,
the countdown time from 3 seconds counts down to 0.
o At this time, the direction is changed to green light. All counter lights show 9
seconds and do not change value.
Test:
Students use the De 2 kit with the SystemVerilog hardware description language for the above
hardware description circuit, connecting from GPIO 0 to the breadboard to represent the light
system. The system of buttons, switches used on the kit as required for the topic.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 105
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 106
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 107
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 108
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 109
Lab 5: Circuit implementation on breadboard and communication with FPGA.
EXPERIMENT 2
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 110
Lab 5: Circuit implementation on breadboard and communication with FPGA.
The time in the request is for reference only, students use and apply the counting method so
that the system works properly.
Test:
Students use the De 2 kit with the SystemVerilog hardware description language for the
above hardware description circuit, connecting from GPIO 0 to the breadboard to represent
the light system. The system of buttons, switches used on the kit as required for the topic.
o Students redraw the block diagram of hardware design
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 111
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 112
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 113
Lab 5: Circuit implementation on breadboard and communication with FPGA.
EXPERIMENT 3
Target: Design an automatic, two-mode traffic light system as above using IC 74LS47 with
an LCD advertising board placed at the corner of the intersection.
Request:
- Students connect the 16 x 2 LCD module using GPIO_1 to the breadboard, display
the ad "Thi Nghiem 5 KTS" in row 1, "BM Dien Tu DHBK" in row 2.
Test:
Students use the De 2 kit with the SystemVerilog hardware description language for the
above hardware description circuit, connecting from GPIO 0 to the breadboard to represent
the light system. The system of buttons, switches used on the kit as required for the topic.
o Students redraw the block diagram of hardware design
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 114
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 115
Lab 5: Circuit implementation on breadboard and communication with FPGA.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 116
Appendix 1: Quartus and Ubuntu Installation on Windows.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 117
Appendix 1: Quartus and Ubuntu Installation on Windows.
Step 2: Open Windows Store Find and Install Ubuntu 22.04.1 LTS
Bước 3: Download the following file ([Link]) and save it in a folder named username set:
[Link]
ing
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 118
Appendix 1: Quartus and Ubuntu Installation on Windows.
Test: After completing the above steps, when booting Ubuntu ➔ type “ ls ” (list the files in
the directory) ➔ the [Link] file appears.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 119
Appendix 1: Quartus and Ubuntu Installation on Windows.
In the Ubuntu terminal, in front of the $ Displays the name of the current directory.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 120
Appendix 1: Quartus and Ubuntu Installation on Windows.
Micro : Alt+G for keyboard shortcuts, for example “^S Save” means to Save, press Ctrl+S..
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 121
Appendix 1: Quartus and Ubuntu Installation on Windows.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 122
Appendix 2: Sample lab.
A. DESIGN FLOW
1. RTL Coding: Algorithm design, FSM,... to solve the set requirements, the design
language here is SystemVerilog HDL.
2. Lint Check: Checks for syntax/syntax errors or coding practices that may cause errors
or bugs. Lint needs to be run after writing the code. Note, Lint Check is a static code
checking process - ie the code will not be run, so the correctness and operation of the
code will not be checked.
→ If Lint Check gives an error, need to read the error to know what is the error, in
which line → Correct the code
3. Verification: Check the operation of the code - based on the design requirements, for
this input, the code is expected to give the output. This is the process of checking the
correctness of the code.
→ If Verification has an error, need to read the code to know what is the error, in
which line → Correct the code → Lint Check
4. Implementation: The design after Verification is completed and meets the
requirements, it will be uploaded to the KIT (DE2 or DE10 or other FPGA KIT).
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 123
Appendix 2: Sample lab.
Operation:
sel result
0 0 0
0 1 data0 & data1
1 0 data0 | data1
1 1 data0 ^ data1
II. Design:
Create Project
At ~ ( cd ~ if necessary), create directory projects , in it create directory lab0 , in lab0
get the template on GitHub to use, name it ex01 .
gettemplate ex01
Type ls to see the files and directories in the current directory, or tree if you want to see the
directory tree.
$ tree
.
└── ex01
├── filelist
├── makefile
├── quartus
│ ├── de10_pin_assign.qsf
│ └── de2_pin_assign.qsf
└── test
├── [Link]
└── tb_top.cpp
3 directories, 6 files
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 124
Appendix 2: Sample lab.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 125
Appendix 2: Sample lab.
Code
Create a design file named design_1.sv and place it in src.
micro src/design_1.sv hoặc cd src rồi micro design_1.sv
src/design_1.sv
1 module design_1 (
2 // input
3 input logic [2:0] data0_i,
4 input logic [2:0] data1_i,
5 input logic [1:0] sel_i,
6
7 // output
8 output logic [2:0] result_o
9 );
10
11 // local declaration
12 logic [2:0] and_tmp; // temporary for and result
13 logic [1:0] or_tmp; // temporary for or result
14 logic [2:0] xor_tmp; // temporary for xor result
15
16 assign and_tmp = data0_i & data1_i;
17 assign or_tmp = data0_i | data1_i;
18 assign xor_tmp = data0_i ~^ data1_i;
19
20 always_comb begin : proc_mux
21 case (sel_i)
22 2'b00: result_o = '0;
23 2'b01: result_o = and_tnp;
24 2'b11: result_o = or_tmp;
25 2'b11: result_o = xor_tmp;
26 endcase
27 end
28
29 endmodule : design_1
At ex01, open and add the filename to the filelist . Enter micro filelist or if in src
then go to ex01 by typing cd ..
filelist
1 src/design_1.sv
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 126
Appendix 2: Sample lab.
Lint Check
Step 1: Run Lint Check to check for errors, type make lint.
$ make lint
------------------> LINT CHECK <------------------
%Error: src/design_1.sv:23:25: Can't find definition of variable: 'and_tnp'
: ... Suggested alternative: 'and_tmp'
23 | 2'b01: result_o = and_tnp;
| ^~~~~~~
%Error: Exiting due to 1 error(s)
make: *** [makefile:50: lint] Error 1
$
Bước 2: Analysis and debugging
After running Lint, the above code has a bug on line 23, and_tnp could not be found
because it was mistyped here and declared as and_tmp . Correct line 23, repeat Step 1 , make
lint.
$ make lint
------------------> LINT CHECK <------------------
%Warning-WIDTH: src/design_1.sv:17:18: Operator ASSIGNW expects 2 bits on the Assign
RHS, but Assign RHS's OR generates 3 bits.
: ... In instance design_1
17 | assign or_tmp = data0_i | data1_i;
| ^
... For warning description see
[Link]
... Use "/* verilator lint_off WIDTH */" and lint_on around source to
disable this message.
%Warning-WIDTH: src/design_1.sv:24:23: Operator ASSIGN expects 3 bits on the Assign
RHS, but Assign RHS's VARREF 'or_tmp' generates 2 bits.
: ... In instance design_1
24 | 2'b11: result_o = or_tmp;
| ^
%Warning-CASEOVERLAP: src/design_1.sv:25:7: Case values overlap (example pattern 0x3)
25 | 2'b11: result_o = xor_tmp;
| ^~~~~
%Warning-CASEINCOMPLETE: src/design_1.sv:21:5: Case values incompletely covered
(example pattern 0x2)
21 | case (sel_i)
| ^~~~
%Error: Exiting due to 4 warning(s)
make: *** [makefile:50: lint] Error 1
$
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 127
Appendix 2: Sample lab.
missing case comparison. This error is caused by the missing 2'b10 instance .
So error lines 21 and 25 are related, fix line 24 to 2'b10.
$ make lint
------------------> LINT CHECK <------------------
$
No errors, the next step is Verification.
Verification
Set Up: To verify the above design, it is necessary to create a driver to drive the input and set
the condition in the output corresponding to the specific input.
Input values, aka test transactions, are generated randomly, so we don't know exactly what
inputs are being fed into and pre-compute the outputs for comparison. In addition, manual
calculation that way, for large design with thousands of test samples, will be difficult for the
designer, so have to check the output automatically, here using assertions to check.
Bước 1: Create file [Link] in directory ex01 , call file design_1.sv.
1. Declare input and output as in design_1 , add clock. Each clock pulse is a test
transaction.
[Link]
1 module top (
2 // input
3 input logic clk_i,
4 input logic [2:0] data0_i,
5 input logic [2:0] data1_i,
6 input logic [1:0] sel_i ,
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 128
Appendix 2: Sample lab.
7 // output
8 output logic [2:0] result_o
9 );
10
2. Call the design_1 module. Note, after the dot is the port name of the design, in the
brackets is the signal/data name connected to that port.
[Link]
11 design_1 dut (
12 .data0_i (data0_i ),
13 .data1_i (data1_i ),
14 .sel_i (sel_i ),
15 .result_o(result_o)
16 );
17
3. Set the condition for the output. Use the assert keyword to constrain the output like
the code below as required by the design, for example, if sel = 2'b11 , then the result
must be equal to xor two data, otherwise the simulation will fail because the design is
not satisfactory. assertion case. Here there is a total of 4 conditions with 4 sel values.
[Link]
Step 2: Create driver to drive input randomly (easier to detect bugs than preset input and check
output, because output output only needs to be constrained to check correctness)
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 129
Appendix 2: Sample lab.
test/[Link]
1 #define MAX_SIM 20
2
3 void set_random(Vtop *dut, vluint64_t sim_unit) {
4 dut->data0_i = rand()%8;
5 dut->data1_i = rand()%8;
6 dut->sel_i = rand()%4;
7 }
2. Note 1: the input includes data0_i, data1_i, and sel_i, but needing to be in the form
dut->data0_i, … clk_i is always automatically given, so [Link] should always
have the logical input clk_i
3. Note 2: this is a C++ file, to generate random, use the function rand() , divide the
remainder by 4 because sel_i only has 2 bits, and data has 3 bits, so divide and divide
by 8. If you want to keep the value fixed, for example data0_i is 3'b101 , just assign
dut->data0_i = 0b101 (C++ assignment).
4. Note 3: MAX_SIM is the number of random samples generated.
Simulating:
Step 1: Run Simulating to check for errors, enter make sim.
$ make sim
-------------------> BUILD <----------------------
...
...
...
-----------------> SIMULATING <-------------------
[0] %Error: [Link]: Assertion failed in [Link].proc_assertions: 'assert' failed.
%Error: [Link]: Verilog $stop
Aborting...
make: *** [makefile:61: sim] Aborted (core dumped)
$
Read the error and see Assertion failed on line 26 of [Link] , check line 26 and see that
this assertion binds the output of sel = 2'b11 , which proves design_1.sv is false when
sel = 2'b11.
Step 2 : Open waveform to observe, enter make wave . Select top → Select all signals in the
lower cell → Select Insert . Output is 001 instead of 110.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 130
Appendix 2: Sample lab.
It is possible to open the menu and save the selection of this signal: File → Write Save File
src/design_1.sv
$ make sim
-------------------> BUILD <----------------------
...
...
...
-----------------> SIMULATING <-------------------
$
No error. Repeat Step 2 , observing the waveform: make wave.
$ make wave
-----------------> WAVEFORMS <--------------------
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 131
Appendix 2: Sample lab.
Step 5: Done.
Implementation
Set Up
Step 1: Create [Link] file.
The wrapper file will call design_1 like [Link] , but the input and output will be from the
following file:
[Link]
(download file DE2_UserManual_1.6 or DE2 Pin Table )
input has data0_i , data1_i , and sel_i , uses switches as input, pin name as shown in table
4.1 in above file. There are 8 bits in total, assign data0_i as SW 2, SW 1, and SW 0, data1_i
as SW 5, SW 4, and SW 3, and sel_i as SW 7 and SW 6. So input will be declared as line 3
and assigned as 3 lines 9, 10, 11.
Output has only result_o and has 3 bits, used as output, table 4.3 in the file above mentions
led. Select red LEDR 2, LEDR 1, and LEDR 0. So the output will be declared as line 5 and
assigned as line 12.
quartus/[Link]
1 module wrapper (
2 // input
3 input logic [7:0] SW,
4 // output
5 output logic [2:0] LEDR
6 );
7
8 design_1 dut (
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 132
Appendix 2: Sample lab.
9 .data0_i (SW[2:0] ),
10 .data1_i (SW[5:3] ),
11 .sel_i (SW[7:6] ),
12 .result_o(LEDR[2:0])
13 );
14
15 endmodule : wrapper
1. Open Quartus.
2. Choose File → New Project Wizard.
a. To directory quartus in ex01.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 133
Appendix 2: Sample lab.
b. Name the project wrapper . Since the actual project is the ex01 directory , it
needs to be named exactly like the file name of the file, [Link].
c. Next to continue.
3. Select … to get the source code
a. Point to directory [Link] which is quartus, select all files → Open →
Add .
b. Point to the directory containing the source code as src, select all files → Open
→ Add.
c. Make sure the Type column is SystemVerilog HDL File.
d. Next to continue.
4. For DE2
a. Device family selects Cyclone II .
b. Available devices select EP2C35F672C6 .
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 134
Appendix 2: Sample lab.
c. Finish to complete.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 135
Appendix 2: Sample lab.
Programmers
1. Connect the DE2 using the USB cord at the Blaster port
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 136
Appendix 2: Sample lab.
4. Select Start to start loading. Check in the box Progress is 100% (successful), ie
successfully loaded.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 137
Appendix 2: Sample lab.
I. Problem:
Design a circuit to count the number of button presses, if pressed and held, it is still counted as
a press, and a 7-segment LED display shows the number of presses..
II. Problem analysis:
The system receives input from a push button (when the button is pressed, the system receives
bit 1, otherwise, the system receives bit 0) and displays the output on a 7-segment LED (output
less than or equal to 9). In addition, the sequential system has clock and reset inputs (selective
active low reset). When the push button is pressed, the sequencer receives signal 1 for only 1
cycle.
The circuit includes a counter, the state of the counter increments by 1 when receiving an input
signal of 1. In addition, the system needs a circuit that converts BCD to 7-segment LED,
displays the status of the counter on LED 7. paragraph.
The button block is an FSM (Finite State Machine) with 3 states: IDLE (waiting to receive),
PRESS (when the button is pressed in the first cycle), HOLD (the state is holding the button).
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 138
Appendix 2: Sample lab.
III. Design:
Create Project
Source template from GitHub to use, name it ex02
gettemplate ex02
Code
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 139
Appendix 2: Sample lab.
src/[Link]
1 module button (
2 // input
3 input logic clk_i,
4 input logic rst_ni,
5
6 input logic button_i,
7
8 // output
9 output logic stable_o
10 );
11
12 // local declaration
13 typedef enum logic [1:0] {
14 IDLE,
15 PRESS,
16 HOLD
17 } state_e;
18
19 state_e state_d;
20 state_e state_q;
21
22 always_comb begin : proc_next_state
23 case (state_q)
24 IDLE: state_d = button_i ? PRESS : IDLE;
25 PRESS: state_d = button_i ? PRESS : IDLE;
26 HOLD: state_d = button_i ? HOLD : IDLE;
27 default: state_d = IDLE;
28 endcase
29 end
30
31 always_ff @(posedge clk_i) begin : proc_state_register
32 if (!rst_ni)
33 state_q <= IDLE;
34 else
35 state_q <= state_d;
36 end
37
38 // output combinational logic
39 assign stable_o = (state_q == PRESS) ? 1'b1 : 1'b0;
40
41 endmodule : button
1 module counter (
2 // input
3 input logic clk_i,
4 input logic rst_ni,
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 140
Appendix 2: Sample lab.
5
6 input logic inc_i,
7
8 // output
9 output logic [3:0] counter_o
10 );
11
12 always_ff @(posedge clk_i) begin : proc_counter
13 if (!rst_ni)
14 counter_o <= '0;
15 else begin
16 if ((counter_o < 4'h9) && inc_i)
17 counter_o <= counter_o + 4'h1;
18 end
19 end
20
21 endmodule : counter
1 module hexled (
2 // input
3 input logic [3:0] data_i,
4
5 // output
6 output logic [6:0] hex_o
7 );
8
9 always_comb begin : proc_7seg_decoder
10 case (data_i)
11 4'h0: hex_o = 7'b100_0000;
12 4'h1: hex_o = 7'b111_1001;
13 4'h2: hex_o = 7'b010_0100;
14 4'h3: hex_o = 7'b011_0000;
15 4'h4: hex_o = 7'b001_1001;
16 4'h5: hex_o = 7'b001_0010;
17 4'h6: hex_o = 7'b000_0010;
18 4'h7: hex_o = 7'b101_1000;
19 4'h8: hex_o = 7'b000_0000;
20 4'h9: hex_o = 7'b001_1000;
21 4'ha: hex_o = 7'b000_1000;
22 4'hb: hex_o = 7'b000_0011;
23 4'hc: hex_o = 7'b100_0110;
24 4'hd: hex_o = 7'b010_0001;
25 4'he: hex_o = 7'b000_0110;
26 4'hf: hex_o = 7'b000_1110;
27 endcase
28 end
29
30 endmodule : hexled
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 141
Appendix 2: Sample lab.
1 module design_2 (
2 // input
3 input logic clk_i,
4 input logic rst_ni,
5
6 input logic button_i,
7
8 // output
9 output logic [6:0] led_o
10 );
11
12 // local declaration
13 logic inc;
14 logic [3:0] counter;
15
16 button button0 (
17 .clk_i (clk_i ),
18 .rst_ni (rst_ni ),
19 .button_i(button_i),
20 .stable_o(inc )
21 );
22
23 counter counter0 (
24 .clk_i (clk_i ),
25 .rst_ni (rst_ni ),
26 .inc_i (inc ),
27 .counter_o(counter)
28 );
29
30 hexled hexled0 (
31 .data_i(counter),
32 .hex_o (led_o)
33 );
34
35 `ifdef VERILATOR
36 /*verilator lint_off UNUSED*/
37 logic pastvld;
38 always @(posedge clk_i) begin
39 pastvld <= 1'b1;
40
41 if (pastvld && $past(inc))
42 assert(!inc);
43
44 assert(counter <= 4'h9);
45 end
46 /*verilator lint_on UNUSED*/
47 `endif
48
49 endmodule : design_2
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 142
Appendix 2: Sample lab.
Note: in the previous post because the circuit does not have a clock, but the assertion requires a
clock, so you must create assertions in the file [Link] . As for this example, there is clock and
binding outputs including outputs of button and counter , so assertions need to be placed in
design_2.sv , so can set binding for button output - with 1 click driving only output up 1
in 1 cycle, which means the button's output cannot be equal to 1 in 2 consecutive cycles (line
42) – and counter – only counts from 0 to 9 (line 44).
There is an extra signal pastvld, because in order to use $past to get the value at the previous
cycle, that value needs to be valid.
Since the pastvld is the signal for verification, and the asserts too, need to be ignored when
pouring into the KIT, put those lines in the following block:
35 `ifdef VERILATOR
36 /*verilator lint_off UNUSED*/
.. ...
1 src/[Link]
2 src/[Link]
3 src/[Link]
4 src/design_2.sv
1 module top (
2 // input
3 input logic clk_i,
4 input logic rst_ni,
5
6 input logic button_i,
7
8 // output
9 output logic [6:0] led_o
10 );
11
12 design_2 dut (
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 143
Appendix 2: Sample lab.
13 .clk_i (clk_i ),
14 .rst_ni (rst_ni ),
15 .button_i(button_i),
16 .led_o (led_o )
17 );
18
19 endmodule : top
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 144
Appendix 2: Sample lab.
quartus/[Link]
1 module wrapper (
2 // input
3 input logic CLOCK_50,
4 input logic [2:0] KEY,
5
6 // output
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 145
Appendix 2: Sample lab.
Electronics Department
Ho Chi Minh City University of Technology, Vietnam 146