Académique Documents
Professionnel Documents
Culture Documents
Lab Manual
Table of Contents
ABOUT THE LAB MANUAL .................................................................................................................................... 1
ABOUT THE LAB EXERCISES ............................................................................................................................... 3
CONVENTIONS .......................................................................................................................................................... 5
LAB 5A – HANDS ON FPGA ..................................................................................................................................... 7
Objectives ................................................................................................................................................................. 7
Introduction .............................................................................................................................................................. 8
i. Procedural Statements .................................................................................................................................. 8
ii. Clock Signal .................................................................................................................................................. 8
iii. Design Task................................................................................................................................................... 9
iv. Testbench ...................................................................................................................................................... 9
Concept Check .................................................................................................................................................. 10
a. Setting up ISE Project Navigator ...................................................................................................................... 11
b. I/O Pin Planning in PlanAhead ......................................................................................................................... 14
c. Clock Divider .................................................................................................................................................... 17
d. Synthesis and Implementation........................................................................................................................... 20
e. Device Configuration ........................................................................................................................................ 21
LAB 5B – INTERACTIVE TESTING USING EXTERNAL SOFTWARE ........................................................ 24
Objectives ............................................................................................................................................................... 24
a. Introduction ....................................................................................................................................................... 25
i. Concatenation operator .............................................................................................................................. 25
b. Setting up the Hardware .................................................................................................................................... 26
i. Integration of UART and counter modules ................................................................................................. 26
ii. Synthesis and Implementation .................................................................................................................... 27
iii. Chip-Desktop Connection ........................................................................................................................... 27
c. Testing hardware with HU-DLDLabs-FPGA App ........................................................................................... 28
Exercise .................................................................................................................................................................. 30
REFERENCES ........................................................................................................................................................... 31
About the lab manual
This lab manual has been created with the help of practical experiments, several supporting
documents and presentations listed in the Bibliography section.
The creation process of this manual was started during the summer 2019 by Dr. Hasan Baig, and
it is continuously being updated during the Fall 2019. The Research Assistants, Hassan Shah,
Hafsa Amanullah, and Saad Rashid, are involved in the continuous improvement of its contents.
For questions, comments, suggestions, advices or corrections in this lab manual, please contact
Dr. Hasan Baig at the following email address: hasan.baig@sse.habib.edu.pk.
Page | 1
2
About the lab exercises
A brief overview of each lab will go here.
In Lab 1, you will be practicing the conversion of a signed number in decimal, binary, octal and
hexadecimal formats.
In Lab 2, you will verify the behavior of Logic Gates using Truth Table (AND, OR, NOT and NOR)
and familiarization with Digital Integrated Circuits by reading its datasheet and the internal IC gate
level structure of the respective IC.
In Lab 2(b), you will verify the behavior of Logic Gates using Truth Table (XOR) and
familiarization with Digital Integrated Circuits by reading the datasheet and the internal IC gate
level structure of the respective IC, you will also implement XOR and XNOR Logic using AND
OR and NOT Gates.
In Lab 3, you will be introduced to the programmable logic and the Verilog HDL. Furthermore, you will
learn how to design a simple hardware and verify its functional behavior using a professional simulation
tool, named ModelSim®.
In Lab 4, you will implement a 2-bit adder using combinational gates and display its result on 7-segment
display.
Lab 5 is divided into two parts. In part (a), a hardware synthesis flow is discussed targeting the Xilinx
FPGA technology. Furthermore, you will get to run your designed hardware on actual FPGA chip. In part
(b), you will learn how to integrate the ready-made UART module with your custom design for
communication with external devices. Also, in this session, you will use a desktop-based software, designed
specifically for this course, to observe the output of on-chip hardware. The lab has been developed with a
help of several different references which are listed down at the end of this manual.
Page | 3
4
Conventions
The following conventions appear in this lab manual.
This icon indicates the expected time (in minutes) to complete the specific
exercise.
bold and italic Bold and italic text denotes the name of a file.
Page | 5
6
Lab 5a – Hands on FPGA
Objectives
In this lab, you will learn how to synthesize and implement the HDL code into the Xilinx-Specific
Technology FPGAs, and then configure the FPGA device with a bitstream. Xilinx Spartan-6 LX9
microboard is used in the labs. The FPGA mounted on this board is XC6SLX9-2CSG324C.
Section
Introduction
The basic concepts are introduced which will be required to complete this lab.
Furthermore, you are required to design a module of a 4-bit counter before coming 20
to a lab which will help you to complete the lab on time.
c) Clock Divider
In this section, you will learn how to slow down the clock speed and why do we 25
need to do this.
e) Device Configuration
Finally, you will use the iMPACT tool for downloading the bitstream file into an 05
FPGA.
7
Lab 5a – Hands on FPGA
Introduction
Introduction
In lab 03, you learnt how to develop Verilog HDL modules of basic logic gates using a continuous
assignment (assign) statement to define the behavior of a circuit. The assign statement runs
continuously without passing through any procedure.
i. Procedural Statements
In order to design a circuit which should execute for specific scenarios, there are other behavioral
statements, categorized in Verilog as the structured procedural statements, called initial block
and always block. These statements are the two most basic statements in behavioral modeling.
All other behavioral statements can appear only inside these structured procedural blocks. We have
previously used the initial block to declare predefined input sequences in testbench. As
opposed to the initial block which runs only once at the beginning of simulation, always
block runs continuously in a looping fashion. The following code exemplifies the behavioral
modeling in Verilog.
else
begin
// This block will be executed only when the clock signal
// is high (logic-1) and reset is also high (logic-1).
The code written inside the always block will run only when either the clock signal transitions
from 0 to 1 (positive edge) or when the reset signal transitions from 1 to 0 (negative edge). Once
the always block is activated, the if-else structure execute either if or else branch
depending on the value of reset signal. The statements enclosed inside the begin and end
keywords run in the order they are specified.
8
Lab 5a – Hands on FPGA
Introduction
two consecutive positive edges or two consecutive negative edges is called a Time Period and is
denoted with T. Therefore, the frequency at which the digital circuit operates is defined by f = 1/T.
iv. Testbench
Use the following testbench to verify the functionality of your designed counter module. Try to
understand it completely.
Page | 9
Lab 5a – Hands on FPGA
Introduction
Concept Check
Assuming that a time unit, in above mentioned testbench, is defined in nano seconds; what is the
frequency at which the designed counter module would operate?
Answer: ______________________________________________.
Page | 10
Lab 5a – Hands on FPGA
Setting up ISE Project Navigator
Xilinx ISE Project Navigator is an Integrated Development Environment for digital logic design
projects with Xilinx FPGAs and CPLDs. Project Navigator provides a simple way to centrally
manage the files in your project as well as automatically invoking all of the other CAD tools.
Follow the steps given below to create a project in the Xilinx ISE navigator.
2. Create a Project
Go to File > New Project and enter the details as shown in the figure below and press Next.
11
Lab 5a – Hands on FPGA
Setting up ISE Project Navigator
3. Project Settings
Match the project settings with those shown in the figure below:
Make sure the Design tab is selected (shown in red circle), in the following figure. Right click
on the project name, counter, and select Add Source…, as shown in the image below.
Page | 12
Lab 5a – Hands on FPGA
Setting up ISE Project Navigator
You can also click on the icon (shown in green circle) to add your existing
source HDL.
Now browse to C:\DLD_Labs\Lab05\design and add counter.v file. After adding, the project
navigator window will now look like the figure shown below.
Also, the Design tab display several different Processes available for the counter module, as
shown in the image below.
Page | 13
Lab 5a – Hands on FPGA
I/O Pin Planning in PlanAhead
In the Design tab, drop down the User Constraints menu and double click on I/O Pin Planning
(PlanAhead) – Pre-Synthesis, as shown in the figure below:
Page | 14
Lab 5a – Hands on FPGA
I/O Pin Planning in PlanAhead
The process will initialize the Xilinx PlanAhead tool and the following window will appear
showing the floorplan of XC6SLX9-2CSG324C FPGA.
We can now connect the I/O ports of the counter module with the physical pins of FPGA. There
are 6 I/O ports in our design of counter – 4-ports for 4-bit output count, 1 input port for clk and
1 for reset.
The motivation of this lab is to let the student observe the counter running on board. There are four
user LEDs available on LX9 Microboard, which we can use to observe the counter output.
Page | 15
Lab 5a – Hands on FPGA
I/O Pin Planning in PlanAhead
Furthermore, we have to connect the reset port either to one of the push buttons or to any of the
DIP switches available on the board.
In this experiment, we will connect the output port count with the four user LEDs and the reset
port with one of the DIP switches. The four user LEDs and the DIP switches are shown in the
image below.
The pin information can be obtained from the user guide of LX9 Microboard [1]. Table I describes
the connections between the I/O ports of our design, counter, and the specific FPGA pins which
are connected to the user LEDs and DIP switches.
Several options are available for clock in LX9 Microboard [1], among which we will use the 40
MHz clock.
In the I/O Ports tab in PlanAhead tool, drop down count and Scalar ports and specify pin names
(shown in Table 1) in the Site column for each specific pin. After assigning pin names, the I/O
Ports tab should look like the following image.
Page | 16
Lab 5a – Hands on FPGA
Clock Divider
When you assign the pin name to each port, you will notice that it is marked fixed automatically.
You can also right-click on selected port and click Place I/O Ports in an I/O Bank option. Now
you can zoom-in the Package window and click on the FPGA pin you wish to connect to the
selected port. This is shown in the figure below for the port count[0].
When all the ports are connected to FPGA pins, we should now export this I/O Ports file, called
user constraints file (UCF), to use with the ISE project navigator.
Go to File > Export I/O Ports… > Check UCF > Click .
c. Clock Divider
We are using a 40 MHz clock (Time period = 1/(40x10^6) = 25ns) and the counter output is
supposed to be updated at every positive edge of clock. Therefore, it is impossible for us to observe
Page | 17
Lab 5a – Hands on FPGA
Clock Divider
the output on user LEDs because the output will be updated every 25ns. We therefore need to slow
down the process by dividing the clock. In order to observe the output, we will run the counter at
0.5 Hz (2 seconds). The high-level diagram for this scenario is shown below:
Write down the clock divider module shown in the following figure. This module has two inputs
clock_n and reset_p, and one output div_clk. In this experiment, the clock_n input will
take the original clock (of 40 MHz).
Verilog allows a user to define a constant value with a help of a keyword parameter, as shown
in line 7. A 32-bit register is defined with the name counter, which counts to a value of
max_count = 40000000. The value of one-bit output div_clk is toggled every time when
the counter becomes equal to max_count. It will take exactly one second to count a value of
40x10^6 by a clock of 40x10^6 Hz. Therefore, the output div_clk signal will toggle after every
Page | 18
Lab 5a – Hands on FPGA
Clock Divider
one second and the time period of div_clk becomes 2 seconds. Now, running counter module
at this frequency will help us to observe the output on FPGA board. Save the clock_divider.v file
in C:\DLD_Labs\Lab05\design\.
Now create a top module named top_counter.v having inputs clk and reset, and a 4-bit
output count. Now instantiate the clock_divider and counter modules in it. Make the
internal connections as shown in the figure below. That is, connect the output, div_clk, of the
clock_divider module with the input clock signal, clk, of the counter module i.e. with a
help of a wire clk_count (line 6, 12, and 17).
Add top_counter.v file in the project as same as we did before for adding the counter.v file.
You may notice that an instantiated clock_divider module appears to be missing in the ISE Project
navigator, as shown in the image below.
Page | 19
Lab 5a – Hands on FPGA
Synthesis and Implementation
Right click on clk_divider - clock_divider (), Add Source… and provide the clock_divider.v
file from the location C:\DLD_Labs\Lab05\design\.
At this point, we are now ready to synthesize our design and generate its implementation files.
1. Synthesis
Synthesis is the process of constructing a gate level netlist from a register-transfer level model
of a circuit described in Verilog HDL. Xilinx Synthesis Technology (XST) is a Xilinx®
application that synthesizes Hardware Description Language (HDL) designs to create Xilinx
specific netlist files called NGC files. The NGC file is a netlist that contains both logical design
data and constraints.
Double Click on Synthesize – XST in the Processes: top_counter window to synthesize the
top module design, top_counter.
2. Implementation
Implementation process comprises of the following sub-processes
• Translate – The Translate process merges all of the input netlists and design constraint
information and generates a Xilinx® Native Generic Database (NGD) file. The output
NGD file can then be mapped to the targeted device family.
• Map – This process takes the Xilinx® Native Generic Database (NGD) file created during
translation, runs a design rule check, and maps the logic design to a Xilinx FPGA. It
generates a Native Circuit Description (NCD) file, which is used for placing and routing.
• Place and route – This step take a mapped NCD file, places and routes the design, and
produces an NCD file to be used by the programming file generator, BitGen.
Double Click on Implement Design in the Processes: top_counter window to implement the
top module design, top_counter. After implementing the design, we can generate the
programming (.bit) file, that will be used to configure the targeted FPGA device.
When you are done successfully with all of the previous processes, you will see the green
checked marks in front of each of the process options as shown in the image below.
Page | 20
Lab 5a – Hands on FPGA
Device Configuration
e. Device Configuration
To Configure the target device, double click on the option, Manage Configuration Project
(iMPACT), shown high-lighted in the figure above. This will initialize another standalone tool
named iMPACT, which will look like the following image.
Page | 21
Lab 5a – Hands on FPGA
Device Configuration
iMPACT, a tool featuring batch and GUI operations, allows you to perform Device Configuration
and File Generation. Operating in Boundary-Scan mode, iMPACT can configure or program
Xilinx FPGAs, CPLDs, and PROMs.
Boundary scan is a method for testing interconnects (wire lines) on printed circuit boards or sub-
blocks inside an integrated circuit. It is the most popular configuration mode due to its
standardization and ability to program FPGAs, CPLDs, and PROMs through the same four JTAG
pins. Boundary-Scan (IEEE Std 1149.1, JTAG) configuration mode enables you to perform
Boundary-Scan-based configuration operations on any chain of IEEE standard 1149.1 compliant
devices. The chain can consist of both Xilinx® and non-Xilinx devices, but only the BYPASS and
HIGHZ operations are available for non-Xilinx devices.
Double click on Boundary Scan in “iMPACT Flows” window. Right click in the white area
inside the Boundary Scan tab and click on “Initialize Chain” option as shown below:
Before executing the “initializing chain” operation, make sure that the FPGA
board is connected to your computer.
Once the boundary scan is completed, all the devices present on board will be displayed. The LX9
Microboard contains only an FPGA so you will see the following image containing only a single
device (xc6slx9) detected., with a display message “Identify Succeeded”.
Page | 22
Lab 5a – Hands on FPGA
Device Configuration
Right Click on the device icon (shown in green in above image), select Assign New
Configuration File…, and assign top_counter.bit file from the following location:
C:\DLD_Labs\Lab05\synthesis\counter\.
Right Click on the device icon again and select Program. A new window will appear, press OK,
and it will begin downloading the .bit file on FPGA. The counter will begin executing on FPGA
board, when you see the message “Program Succeeded” in the Boundary Scan window.
Observe the counter behavior. Reset the circuit and see if it follows the designed functionality.
Page | 23
Lab 5b – Interactive Testing
using External Software
Objectives
In this lab, we will use a desktop-based application, named HU-DLDLabs-FPGA, to observe the
counter output more intuitively. To do this, we will create a setup in hardware to transmit the on-
chip counter data to a desktop computer using a serial interface.
Section
a) Introduction
In this section, you will get an idea of how we are going to enhance our 10
experimental setup to make it user-friendly.
Exercise
Small exercise to practice either at home or in the lab. However, you will need to test 30
the functionality on FPGA board which requires you to be in lab.
24
Lab 5b – Interactive Testing using External Software
Introduction
a. Introduction
In previous lab, it was a little difficult to observe the counter output due to unavailability of enough
resources, for example 7-segment display. In this lab, we will be using a desktop-based application,
named HU-DLDLabs-FPGA, which is developed to help students in testing on-chip hardware in
a user-friendly manner.
The following figure shows the conceptual diagram for testing the counter module. Instead of
observing the counter output on on-board LEDs, the following setup transmits the counter data to
a computer via UART (Universal Asynchronous Receiver Transmitter) interface [6]. This data is
then received by HU-DLDLabs-FPGA application which then displays the integer value of a
counter.
Figure 5b.1. Conceptual diagram showing the integrated experimental setup with HU-DLDLabs-FPGA App.
Studying UART protocols is out of the scope of this lab. If interested, you can
study more about UART from the reference [6].
In order to complete this lab, you will be required to use the assignment (assign) statement and
the concatenation ({}) operators. You have already studied and used the assign operator in Lab
03 before. The concatenation operation is ({}) briefly described below.
i. Concatenation operator
Concatenations are expressed as operands within braces, with commas separating the operands.
Operands can be scalar nets or registers, vector nets or registers, bit-select, part-select, or sized
constants. Following examples shows the usage of concatenation operator.
25
Lab 5b – Interactive Testing using External Software
Setting up the Hardware
Also, copy the design files clock_divider.v, counter.v, and top_counter.v from the location
C:\DLD_Labs\Lab05\design\ into C:\DLD_Labs\Lab5b\design\counter\ directory.
All we need to do now is to tie up the UART’s interface with our top design module i.e.
top_counter.
Figure 5b.2. The internal connections inside the top module containing the uart_top and top_counter
modules.
Page | 26
Lab 5b – Interactive Testing using External Software
Setting up the Hardware
The figure shown above tells us that the top module should have three input and 2 output ports,
named clk, reset, rx, and count, and tx, respectively. The 4-bit output count of
top_counter module is not only connected to the 4-bit output port, count, of the top module
but it is also connected to the 8-bit input port, data_to_tx, of uart_top module through an
8-bit internal wire, counter_data.
Once the connections are made, we can proceed to the next step of synthesizing the complete
hardware (top.v) of counter integrated with UART.
While making the I/O port connections using PlanAhead (as described in section b of lab session
5a), follow the port connections as shown in Table I. There are two additional ports i.e. tx and
rx, which should be connected to the pins as shown in Table II below.
Once the I/O connections are made (the .ucf file is generated), proceed ahead to execute the
processes of Synthesize – XST, Implement Design, and Generate Programming File.
You may see a warning sign appeared after running the processes of
Synthesize and Implement Design. Ignore it.
Page | 27
Lab 5b – Interactive Testing using External Software
Testing hardware with HU-DLDLabs-FPGA App
Now connect the FPGA board with your PC using the micro-USB cable (black in color). Check if
the serial connection with FPGA board is established with your PC by Right Clicking on My
Computer → Manage → Device Manager → Ports (COM & LPT) and verify if the Silicon
Labs CP210x USB to UART Bridge (COMx) is listed as shown in the Figure below:
Figure 5b.3. Device manager showing the Silicon Labs USB to UART bridge is assigned a COM3 port.
1. Launch HU-DLDLabs-FPGA
Launch HU-DLDLabs-FPGA application by double clicking on the following HU-DLDLabs-
FPGA icon on your desktop, as shown in the image below.
Page | 28
Lab 5b – Interactive Testing using External Software
Testing hardware with HU-DLDLabs-FPGA App
If the icon is not found on the desktop, search the App in Windows Program menu.
Figure 5b.4. HU-DLDLabs-FPGA software application for testing the hardware on chip.
2. Connection Settings
Drop down the COM Port menu and select COM5.
Every PC may have a different COM port assigned to your FPGA board. You
should select that COM port which appears in the Device Manager. In this
case, it is COM5 as shown in Figure 5b.3.
Next, drop down the Baud Rate menu and select 38400.
Now press the Connect button to start observing the output of a counter running on an FPGA
chip.
To disconnect the HU-DLDLabs-FPGA software with the FPGA board, press and hold
Disconnect button for 2 seconds.
Page | 29
Lab 5b – Interactive Testing using External Software
Exercise
Exercise
Create a folder named Exercise under ..\Lab5b\ path and copy the design folder of Lab5b in it.
Now following the Lab5a tutorial, create a new project and use the copied files in it. Update these
files to incorporate the following requirements.
Now download the bitstream of updated hardware on FPGA and verify the functionality on HU-
DLDLabs-FPGA App.
30
References
[1]. Avnet, “Xilinx Spartan-6 LX9 Microboard User Guide”, RevD, April 2015.
[2]. XILINX, ISE Design Suite Overview, ISE Help (v 12.2), 2010.
[3]. XILINX, XST User Guide, UG627 (v 11.3), 2009.
[4]. XILINX, PlanAhead User Guide, UG632 (v12.2), 2010.
[5]. Hasan Baig, “Jump-start to FPGA based Digital Designing and CAD Tools”, workshop presentation, 2010.
[6]. UART, https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter.
31
Digital Logic and Design
(EE-172 / CS-130)
Habib University
# Assessment Elements (0<Level 1<=4) (4< Level 2<=6) (6< Level 3<=8) (8< Level 4<=10)
Components are wired and Components are wired with Complete components are
Few but not all Components
Neat and Clean Circuit didn’t show neat and clean untidy connection and wired with neat and clean
LR1 are wired with neat and
layout connections and minimal efforts didn’t show neat and clean tight connections and task
clean connections
shown connections completed in due time
Program/code/simulation
Program/code/simulation Program/code/simulation
model/network model (i.e. Program/code/simulation
model/network model is not model/network model is
with some comments but model/network model is
well-documented (i.e. with no well-documented (with
Program/code/simulation has improper variable well-documented (i.e. with
LR2 comments and proper variable comments and proper
model/network model names or vice versa) and is comments and proper
names) and not efficiently variable names) and task
implemented by variable names) but not
implemented and minimal efficiently implemented in
computationally complex implemented efficiently
efforts shown due time
routine
Figures, graphs, tables contain Most figures, graphs, tables All figures, graphs, tables
All figures, graphs, tables
errors or are poorly constructed, OK, some still missing are correctly drawn, but
LR5 Results & Plots are correctly drawn and
have missing titles, captions, some important or required some have minor problems
contain titles/captions
units missing or incorrect, etc. features or could still be improved
Response shows a complete Response shows some Response shows substantial Response shows complete
LR7 Viva lack of understanding of understanding of subjected understanding of subjected understanding of subjected
subjected task task task task
No participation towards the Slight participation towards Substantial participation Outstanding participation
LR8 Contribution
group tasks the group tasks towards the group tasks towards the group tasks