Quartus II Introduction Using Verilog Design
Quartus II Introduction Using Verilog Design
This tutorial presents an introduction to the Quartus R II CAD system. It gives a general overview of a typi-
cal CAD flow for designing circuits that are implemented by using FPGA devices, and shows how this flow is
realized in the Quartus II software. The design process is illustrated by giving step-by-step instructions for using
the Quartus II software to implement a very simple circuit in an Altera FPGA device.
The Quartus II system includes full support for all of the popular methods of entering a description of the
desired circuit into a CAD system. This tutorial makes use of the Verilog design entry method, in which the user
specifies the desired circuit in the Verilog hardware description language. Two other versions of this tutorial are
also available; one uses the VHDL hardware description language and the other is based on defining the desired
circuit in the form of a schematic diagram.
The last step in the design process involves configuring the designed circuit in an actual FPGA device. To
show how this is done, it is assumed that the user has access to the Altera DE2 Development and Education board
connected to a computer that has Quartus II software installed. A reader who does not have access to the DE2
board will still find the tutorial useful to learn how the FPGA programming and configuration task is performed.
The screen captures in the tutorial were obtained using the Quartus II version 5.0; if other versions of the
software are used, some of the images may be slightly different.
Contents:
Typical CAD flow
Getting started
Starting a New Project
Verilog Design Entry
Compiling the Design
Pin Assignment
Simulating the Designed Circuit
Programming and Configuring the FPGA Device
Testing the Designed Circuit
1
Computer Aided Design (CAD) software makes it easy to implement a desired logic circuit by using a pro-
grammable logic device, such as a field-programmable gate array (FPGA) chip. A typical FPGA CAD flow is
illustrated in Figure 1.
Design Entry
Synthesis
Functional Simulation
No
Design correct?
Yes
Fitting
No
Timing requirements met?
Yes
2
• Fitting – the CAD Fitter tool determines the placement of the LEs defined in the netlist into the LEs in
an actual FPGA chip; it also chooses routing wires in the chip to make the required connections between
specific LEs
• Timing Analysis – propagation delays along the various paths in the fitted circuit are analyzed to provide
an indication of the expected performance of the circuit
• Timing Simulation – the fitted circuit is tested to verify both its functional correctness and timing
• Programming and Configuration – the designed circuit is implemented in a physical FPGA chip by pro-
gramming the configuration switches that configure the LEs and establish the required wiring connections
This tutorial introduces the basic features of the Quartus II software. It shows how the software can be used to
design and implement a circuit specified by using the Verilog hardware description language. It makes use of the
graphical user interface to invoke the Quartus II commands. Doing this tutorial, the reader will learn about:
• Creating a project
• Design entry using Verilog code
• Synthesizing a circuit specified in Verilog code
• Fitting a synthesized circuit into an Altera FPGA
• Assigning the circuit inputs and outputs to specific pins on the FPGA
• Simulating the designed circuit
• Programming and configuring the FPGA chip on Altera’s DE2 board
1 Getting Started
Each logic circuit, or subcircuit, being designed with Quartus II software is called a project. The software works
on one project at a time and keeps all information for that project in a single directory (folder) in the file system.
To begin a new logic circuit design, the first step is to create a directory to hold its files. To hold the design files
for this tutorial, we will use a directory introtutorial. The running example for this tutorial is a simple circuit for
two-way light control.
Start the Quartus II software. You should see a display similar to the one in Figure 2. This display consists
of several windows that provide access to all the features of Quartus II software, which the user selects with the
computer mouse. Most of the commands provided by Quartus II software can be accessed by using a set of menus
that are located below the title bar. For example, in Figure 2 clicking the left mouse button on the menu named
File opens the menu shown in Figure 3. Clicking the left mouse button on the entry Exit exits from Quartus II
software. In general, whenever the mouse is used to select something, the left button is used. Hence we will not
normally specify which button to press. In the few cases when it is necessary to use the right mouse button, it will
be specified explicitly.
3
Figure 2. The main Quartus II display.
4
For some commands it is necessary to access two or more menus in sequence. We use the convention Menu1
> Menu2 > Item to indicate that to select the desired command the user should first click the left mouse button
on Menu1, then within this menu click on Menu2, and then within Menu2 click on Item. For example, File >
Exit uses the mouse to exit from the system. Many commands can be invoked by clicking on an icon displayed in
one of the toolbars. To see the command associated with an icon, position the mouse over the icon and a tooltip
will appear that displays the command name.
5
Figure 5. Creation of a new project.
2. Set the working directory to be introtutorial; of course, you can use some other directory name of your
choice if you prefer. The project must have a name, which is usually the same as the top-level design entity
that will be included in the project. Choose light as the name for both the project and the top-level entity, as
shown in Figure 5. Press Next. Since we have not yet created the directory introtutorial, Quartus II software
displays the pop-up box in Figure 6 asking if it should create the desired directory. Click Yes, which leads
to the window in Figure 7.
Figure 6. Quartus II software can create a new directory for the project.
6
Figure 7. The wizard can include user-specified design files.
3. The wizard makes it easy to specify which existing files (if any) should be included in the project. Assuming
that we do not have any existing files, click Next, which leads to the window in Figure 8.
7
4. We have to specify the type of device in which the designed circuit will be implemented. Choose CycloneTM
II as the target device family. We can let Quartus II software select a specific device in the family, or we can
choose the device explicitly. We will take the latter approach. From the list of available devices, choose the
device called EP2C35F672C6 which is the FPGA used on Altera’s DE2 board. Press Next, which opens the
window in Figure 9.
5. The user can specify any third-party tools that should be used. A commonly used term for CAD software
for electronic circuits is EDA tools, where the acronym stands for Electronic Design Automation. This term
is used in Quartus II messages that refer to third-party tools, which are the tools developed and marketed
by companies other than Altera. Since we will rely solely on Quartus II tools, we will not choose any other
tools. Press Next.
6. A summary of the chosen settings appears in the screen shown in Figure 10. Press Finish, which returns to
the main Quartus II window, but with light specified as the new project, in the display title bar, as indicated
in Figure 11.
8
Figure 10. Summary of the project settings.
9
3 Design Entry Using Verilog Code
As a design example, we will use the two-way light controller circuit shown in Figure 12. The circuit can be used
to control a single light from either of the two switches, x1 and x2 , where a closed switch corresponds to the logic
value 1. The truth table for the circuit is also given in the figure. Note that this is just the Exclusive-OR function
of the inputs x1 and x2 , but we will specify it using the gates shown.
x1
x1 x2 f
0 0 0
f 0 1 1
1 0 1
1 1 0
x2
The required circuit is described by the Verilog code in Figure 13. Note that the Verilog module is called
light to match the name given in Figure 5, which was specified when the project was created. This code can be
typed into a file by using any text editor that stores ASCII files, or by using the Quartus II text editing facilities.
While the file can be given any name, it is a common designers’ practice to use the same name as the name of the
top-level Verilog module. The file name must include the extension v, which indicates a Verilog file. So, we will
use the name light.v.
10
Figure 14. Choose to prepare a Verilog file.
11
3.1.1 Using Verilog Templates
The syntax of Verilog code is sometimes difficult for a designer to remember. To help with this issue, the Text
Editor provides a collection of Verilog templates. The templates provide examples of various types of Verilog
statements, such as a module declaration, an always block, and assignment statements. It is worthwhile to browse
through the templates by selecting Edit > Insert Template > Verilog HDL to become familiar with this resource.
12
Figure 18. Select the file.
13
When the compilation is finished, a compilation report is produced. A window showing this report is opened
automatically, as seen in Figure 19. The window can be resized, maximized, or closed in the normal way, and it
can be opened at any time either by selecting Processing > Compilation Report or by clicking on the icon .
The report includes a number of sections listed on the left side of its window. Figure 19 displays the Compiler
Flow Summary section, which indicates that only one logic element and three pins are needed to implement this
tiny circuit on the selected FPGA chip. Another section is shown in Figure 20. It is reached by selecting Analysis
& Synthesis > Equations on the left side of the compilation report. Here we see the logic expressions produced
by the Compiler when synthesizing the designed circuit. Observe that f is the output derived as
f = x2 $ x1
where the $ sign is used to represent the Exclusive-OR operation. Obviously, the Compiler recognized that the
logic expression in our design file is equivalent to this expression.
4.1 Errors
Quartus II software displays messages produced during compilation in the Messages window. If the Verilog design
file is correct, one of the messages will state that the compilation was successful and that there are no errors.
If the Compiler does not report zero errors, then there is at least one mistake in the Verilog code. In this case
a message corresponding to each error found will be displayed in the Messages window. Double-clicking on an
error message will highlight the offending statement in the Verilog code in the Text Editor window. Similarly, the
Compiler may display some warning messages. Their details can be explored in the same way as in the case of
error messages. The user can obtain more information about a specific error or warning message by selecting the
message and pressing the F1 function key.
To see the effect of an error, open the file light.v. Remove the semicolon in the assign statement, illustrating a
typographical error that is easily made. Compile the erroneous design file by clicking on the icon. A pop-up
box will ask if the changes made to the light.v file should be saved; click Yes. After trying to compile the circuit,
Quartus II software will display a pop-up box indicating that the compilation was not successful. Acknowledge it
by clicking OK. The compilation report summary, given in Figure 21, now confirms the failed result. Expand the
Analysis & Synthesis part of the report and then select Messages to have the messages displayed as shown in
Figure 22. Double-click on the first error message. Quartus II software responds by opening the light.v file and
highlighting the statement which is affected by the error, as shown in Figure 23. Correct the error and recompile
14
the design.
5 Pin Assignment
During the compilation above, the Quartus II Compiler was free to choose any pins on the selected FPGA to serve
as inputs and outputs. However, the DE2 board has hardwired connections between the FPGA pins and the other
components on the board. We will use two toggle switches, labeled SW1 and SW0 , to provide the external inputs,
x1 and x2 , to our example circuit. These switches are connected to the FPGA pins N26 and N25, respectively. We
will connect the output f to the green light-emitting diode labeled LEDG0 , which is hardwired to the FPGA pin
AE22.
15
Figure 24. The Assignment Editor window.
Pin assignments are made by using the Assignment Editor. Select Assignments > Pins to reach the window
in Figure 24. Under Category select Pin. Double-click on the entry <<new>> which is highlighted in blue in
the column labeled To. The drop-down menu in Figure 25 will appear. Click on x1 as the first pin to be assigned;
this will enter x1 in the displayed table. Follow this by double-clicking on the box to the right of this new x1
entry, in the column labeled Location. Now, the drop-down menu in Figure 26 appears. Scroll down and select
Pin N26. Instead of scrolling down the menu to find the desired pin, you can just type the name of the pin in the
Location box. Use the same procedure to assign input x2 to pin N25 and output f to pin AE22, which results
in the image in Figure 27. To save the assignments made, choose File > Save. You can also simply close the
Assignment Editor window, in which case a pop-up box will ask if you want to save the changes to assignments;
click Yes. Recompile the circuit, so that it will be compiled with the correct pin assignments.
Figure 25. The drop-down menu displays the input and output names.
16
Figure 27. The complete assignment.
The DE2 board has fixed pin assignments. Having finished one design, the user will want to use the same
pin assignment for subsequent designs. Going through the procedure described above becomes tedious if there
are many pins used in the design. A useful Quartus II feature allows the user to both export and import the pin
assignments from a special file format, rather than creating them manually using the Assignment Editor. A simple
file format that can be used for this purpose is the comma separated value (CSV) format, which is a common text
file format that contains comma-delimited values. This file format is often used in conjunction with the Microsoft
Excel spreadsheet program, but the file can also be created by hand using any plain ASCII text editor. The format
for the file for our simple project is
To, Location
x1, PIN N26
x2, PIN N25
f, PIN AE22
By adding lines to the file, any number of pin assignments can be created. Such csv files can be imported into any
design project.
If you created a pin assignment for a particular project, you can export it for use in a different project. To see
how this is done, open again the Assignment Editor to reach the window in Figure 27. Now, select File > Export
which leads to the window in Figure 28. Here, the file light.csv is available for export. Click on Export. If you
now look in the directory introtutorial, you will see that the file light.csv has been created.
17
You can import a pin assignment by choosing Assignments > Import Assignments. This opens the dialogue
in Figure 29 to select the file to import. Type the name of the file, including the csv extension and the full path to the
directory that holds the file, in the File Name box and press OK. Of course, you can also browse to find the desired
file. For convenience, all relevant pin assignments for the DE2 board are given in the file called DE2 pinout.csv,
which is included with the laboratory material provided by Altera.
18
Figure 30. Need to prepare a new file.
19
Figure 33. The augmented Waveform Editor window.
3. Next, we want to include the input and output nodes of the circuit to be simulated. Click Edit > Insert
Node or Bus to open the window in Figure 34. It is possible to type the name of a signal (pin) into the
Name box, but it is easier to click on the button labeled Node Finder to open the window in Figure 35. The
Node Finder utility has a filter used to indicate what type of nodes are to be found. Since we are interested
in input and output pins, set the filter to Pins: all. Click the List button to find the input and output nodes as
indicated on the left side of the figure.
20
Click on the x1 signal in the Nodes Found box in Figure 35, and then click the > sign to add it to the Selected
Nodes box on the right side of the figure. Do the same for x2 and f. Click OK to close the Node Finder
window, and then click OK in the window of Figure 34. This leaves a fully displayed Waveform Editor
window, as shown in Figure 36. If you did not select the nodes in the same order as displayed in Figure 36,
it is possible to rearrange them. To move a waveform up or down in the Waveform Editor window, click on
the node name (in the Name column) and release the mouse button. The waveform is now highlighted to
show the selection. Click again on the waveform and drag it up or down in the Waveform Editor.
4. We will now specify the logic values to be used for the input signals x1 and x2 during simulation. The logic
values at the output f will be generated automatically by the simulator. To make it easy to draw the desired
waveforms, the Waveform Editor displays (by default) vertical guidelines and provides a drawing feature
that snaps on these lines (which can otherwise be invoked by choosing View > Snap to Grid). Observe also
a solid vertical line, which can be moved by pointing to its top and dragging it horizontally. This reference
line is used in analyzing the timing of a circuit; move it to the time = 0 position. The waveforms can be
drawn using the Selection Tool, which is activated by selecting the icon in the toolbar, or the Waveform
Editing Tool, which is activated by the icon .
To simulate the behavior of a large circuit, it is necessary to apply a sufficient number of input valuations and
observe the expected values of the outputs. In a large circuit the number of possible input valuations may
be huge, so in practice we choose a relatively small (but representative) sample of these input valuations.
However, for our tiny circuit we can simulate all four input valuations given in Figure 12. We will use four
50-ns time intervals to apply the four test vectors.
We can generate the desired input waveforms as follows. Click on the waveform name for the x1 node.
Once a waveform is selected, the editing commands in the Waveform Editor can be used to draw the desired
waveforms. Commands are available for setting a selected signal to 0, 1, unknown (X), high impedance (Z),
don’t care (DC), inverting its existing value (INV), or defining a clock waveform. Each command can be
activated by using the Edit > Value command, or via the toolbar for the Waveform Editor. The Edit menu
can also be opened by right-clicking on a waveform name.
Set x1 to 0 in the time interval 0 to 100 ns, which is probably already set by default. Next, set x1 to 1 in the
time interval 100 to 200 ns. Do this by pressing the mouse at the start of the interval and dragging it to its
end, which highlights the selected interval, and choosing the logic value 1 in the toolbar. Make x2 = 1 from
50 to 100 ns and also from 150 to 200 ns, which corresponds to the truth table in Figure 12. This should
21
produce the image in Figure 37. Observe that the output f is displayed as having an unknown value at this
time, which is indicated by a hashed pattern; its value will be determined during simulation. Save the file.
22
Figure 38. Specifying the simulation mode.
23
Figure 40. The result of timing simulation.
24
Observe that the configuration file light.sof is listed in the window in Figure 41. If the file is not already listed,
then click Add File and select it. This is a binary file produced by the Compiler’s Assembler module, which
contains the data needed to configure the FPGA device. The extension .sof stands for SRAM Object File. Note
also that the device selected is EP2C35F672, which is the FPGA device used on the DE2 board. Click on the
Program/Configure check box, as shown in Figure 43.
Now, press Start in the window in Figure 43. An LED on the board will light up when the configuration data
has been downloaded successfully. If you see an error reported by Quartus II software indicating that programming
failed, then check to ensure that the board is properly powered on.
25
Figure 44. The Device Settings window.
26
Figure 46. Specifying the configuration device.
The rest of the procedure is similar to the one described above for the JTAG mode. Select Tools > Program-
mer to reach the window in Figure 41. In the Mode box select Active Serial Programming. If you are changing
the mode from the previously used JTAG mode, the pop-up box in Figure 47 will appear, asking if you want to
clear all devices. Click Yes. Now, the Programmer window shown in Figure 48 will appear. Make sure that the
Hardware Setup indicates the USB-Blaster. If the configuration file is not already listed in the window, press Add
File. The pop-up box in Figure 49 will appear. Select the file light.pof in the directory introtutorial and click
Open. As a result, the configuration file light.pof will be listed in the window. This is a binary file produced by
the Compiler’s Assembler module, which contains the data to be loaded into the EPCS16 configuration device.
The extension .pof stands for Programmer Object File. Upon returning to the Programmer window, click on the
Program/Configure check box, as shown in Figure 50.
27
Figure 48. The Programmer window with Active Serial Programming selected.
Flip the RUN/PROG switch on the DE2 board to the PROG position. Press Start in the window in Figure
50. An LED on the board will light up when the configuration data has been downloaded successfully. Also, the
28
Progress box in Figure 50 will indicate when the configuration and programming process is completed, as shown
in Figure 51.
Copyright c 2005 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company, the
stylized Altera logo, specific device designations, and all other words and logos that are identified as trademarks
and/or service marks are, unless noted otherwise, the trademarks and service marks of Altera Corporation in
the U.S. and other countries. All other product or service names are the property of their respective holders.
Altera products are protected under numerous U.S. and foreign patents and pending applications, mask work
rights, and copyrights. Altera warrants performance of its semiconductor products to current specifications in
accordance with Altera’s standard warranty, but reserves the right to make changes to any products and services at
any time without notice. Altera assumes no responsibility or liability arising out of the application or use of any
information, product, or service described herein except as expressly agreed to in writing by Altera Corporation.
Altera customers are advised to obtain the latest version of device specifications before relying on any published
information and before placing orders for products or services.
This document is being provided on an “as-is” basis and as an accommodation and therefore all warranties, rep-
resentations or guarantees of any kind (whether express, implied or statutory) including, without limitation, war-
ranties of merchantability, non-infringement, or fitness for a particular purpose, are specifically disclaimed.
29