Experiment Sheet - FPGA design Part 1 v1...
Transcript of Experiment Sheet - FPGA design Part 1 v1...
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 1
Department of Electrical & Electronic Engineering
Imperial College London
2nd Year Laboratory
Experiment: FPGA Design with Verilog
Objectives
By the end of this experiment, you should know:
• How to design digital circuits using Altera’s Quartus II Design Suite; • How to design digital circuits targeting Altera’s Cyclone III FPGA using a Terasic’s DE0
Board; • How to design digital circuits in efficient Verilog HDL; • How to evaluate your design in terms of resource utilization and clock speed; • How to use DE0 FPGA board with its custom daughter board for I/O functions such
as ADC and DAC; • Have designed something yourself for the Cyclone III FPGA.
Both the experimental board and a PC would be made available to you during your allotted period in the second year laboratory. In addition, you may also borrow a DE0 board to take home to use for the rest of the second year. This instruction sheet is divided into four part, one for each week. It also provides you with information required to install Altera’s Quartus II Design Suite (web free-‐version) on your own personal computer (PC or Mac).
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 2
PART I
1.0 Introduction
This experiment is designed to support the second year course on digital electronics as part of the second year electronics lab. Due to the limitation of scheduling, this experiment will NOT be synchronized with the lectures or tutorial problem sheets. However, you are encouraged to borrow a DE0 Board from the stores and conduct this experiment at home in your own time if you so choose.
All materials relating to this experiment can be found on the following experiment webpage: http://www.ee.ic.ac.uk/pcheung/teaching/E2_experiment/
1.1 Background Reading
You should have done some background reading before attending the laboratory session as suggested at the Lecture.
1.2 FPGAs
FPGAs is a type of programmable logic devices introduced by Xilinx in 1985. It is now the predominant technology for implementing digital logic in low to moderate volume production. The basic structure of an FPGA is shown below. It consists of three main types of resources: 1) Logic Blocks (or Elements); 2) Routing Resources; 3) I/O Pad. For more information about FPGA, see Lecture 2 notes available on the E2 Digital Electronics course webpage.
1.3 Quartus II Design Suite
Quartus II provides a complete environment for you to implement your design on an Altera FPGA. It supports all aspects of the design flow, which is typically following the flow diagram shown here. The best way to learn Quartus is to go through this experiment step-‐by-‐step. After you have learned the basics, you can start to explore other aspects of the Quartus system.
1.3 DE0 Board
DE0 Board is designed and made by Terasic. It is based around a Cyclone III FPGA from Altera. Include on the DE0 board are various I/O devices such as 7-‐segment LED displays, LED, switches, VGA port, RS232 port, SD card slot etc. A block diagram of the DE0 board is shown below.
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 3
1.4 Verilog Hardware Description Language
One of the key purposes of this lab experiment is to encourage you to learn the Verilog Hardware Description Language (HDL), which is the preferred and common means of specifying a FPGA design. You are expected to have learned the basics of the Verilog language before doing this experiment. If you happen to be schedule to do this experiment at the beginning of the term, you would need to teach yourself Verilog by reading my Lecture notes 3A and 3B and/or online tutorials. An excellent tutorial can be found on: http://www.asic-‐world.com/verilog/veritut.html. A Verilog Syntax Summary sheet is provided in Appendix A.
1.5 Using Quartus II software and DE0 at home
You are encourage to install a copy of the Quartus II software on your own computer and borrow a DE0 board (from EEE Stores with your ID card), so that you are not restricted to working in the Level 1 Lab. The version that comes with the DE0 board is version 9.0, which is already a few years old. You should go to Altera’s website to register yourself, then download the free Web Edition from: http://dl.altera.com/?edition=web. Note that Quartus II and DE0 board will work with Windows XP/Windows 7/Windows 8, or Linux. If you are a Mac user, you would need to run a virtual machine (e.g. VirtualBox, Parallels or VMware), load a version of Windows or Linux, and then run Quartus under that environment.
Plug the DE0 board to a USB port on your computer and turn it ON (red button). It will ask you for a device driver, which can be found in the Quartus software directory ….\drivers. See “Getting Started with Altera DE0 board” manual.
Copy from the DVD the directory \DE0\Contro_panel to your computer (best at the same directory as the Quartus software).
Run DE0_ControlPanel.exe and check that the DE0 board is working properly1. It allows you to test most of the functions on DE0 with an easy-‐to-‐use interface.
PART I
Experiment 1: Schematic capture using Quartus II – 7-‐Segment Display
Part I of the experiment should take no more than ONE 3-‐hour session. It will lead you through the entire design of a 7-‐segment decoder using schematic entry method. It will use switches 3-‐0 on the DE0 board as input, and display the 4-‐bit binary number as a hexadecimal digit on the right-‐most 7-‐segment display (HEX0).
Step 1: See what you are aiming for
Go to the Experiment webpage (see above) and download a copy of the solution for Experiment 1: “My7Seg.sof” onto your home directory (wherever that is). Now turn ON the DE0 board.
1 You needed to add "C:\altera\13.1\quartus\bin" to your search path – a known problem.
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 4
Step 2: Programme the FPGA
Start up Quartus II software on your computer. Click command: Tools > Programmer. In the popup window, click: Hardware Setup …. You should see something like the diagram below. Then select: USB-‐Blaster. This is to tell Quartus software that you are using the DE0 USB interface to program (or blast) the FPGA. Then click Add File …. specify the .sof file you have downloaded from your home directory. Click: Start. This shows you what you are aiming for: use the lower 4-‐bit of the slide switches to specify a 4-‐bit hex number, which is decoded to drive a 7-‐segment LED display.
Step 3: Paper Design
Designed a 7-‐segment decoder on paper. The overall block diagram for the decoder is shown below. The decoder outputs out[6..0] drive the seven segments [6..0] respectively. Note that the LED segments are low active, meaning that the LED will light up if the corresponding input is drive by a logical 0.
The truth-‐table for the decoder is:
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 5
Your design should be in the form of 7 Boolean equations in sum-‐of-‐product form. Simplify where possible.
Step 4: Create the project “My7Seg”
• Create in your home directory the folder Ex1a. • Click file>New Project Wizard, complete the form. Use the same project name and
top-‐design name. • Select the FPGA device as Cyclone III EP3C16F484C6. Then click Finish. • Create the top-‐level module “My7Seg” by: • Click File > New ….. There will be an empty schematic window. • Click File > Save As… enter the name “My7Seg”.
Step 5: Specify the 7-‐segment decoder as schematic
• In order to save time in the Lab, you are provided with an incomplete version of the 7-‐segment display decoder. Go to the Experiment webpage and download: 7_Segment_Decoder_incompete.bdf. Rename it to 7_Segment_Decoder.bdf.
• This partially completed design has the logic that drives out[4] missing. You job is to design and enter the schematic to drive out[4] from in[3:0]. The diagram here shows one possible implementation. Your design may be different.
• The Graphic Editor provides a number of libraries which include circuit elements that can be imported into a schematic. Double-‐click on the blank space in the Graphic
Editor window, or click on the icon in the toolbar that looks like an AND gate. A pop-‐up box will appear. Expand the hierarchy in the Libraries box as shown in the figure. First expand libraries, then expand the library primitives, followed by expanding the library logic which comprises the logic gates. Select “and2”, which is a two-‐input AND gate, and click OK. Now, the AND symbol will appear in the Graphic Editor window. Using the mouse, move the symbol to a desirable location and click to place it there.
• Repeat and place two “and3” and one “or3” gates on the schematic. Change the names of all the input and output nodes accordingly. (It is quickest to put down all the gates first before wiring them up later.)
• Having entered the logic-‐gate symbols, it is now necessary to enter the symbols that represent the input and output ports of the circuit. Use the same procedure as for importing the gates, but choose the port symbols from the library primitives/pin. Import one instance of the input port and one instance of the output port. Label the input port as in[3:0] and output port as out[6:0]. Grouping input and output ports as busses will make wiring much easier.
• Assign names to the input and output symbols as follows. Make sure nothing is selected by clicking on an empty spot in the Graphic Editor window. Point to the word pin_name on the top input symbol and double-‐click the mouse. The dialog box will appear. Type the pin name, in[0], and click OK. Similarly, assign the names in[3..1] to the other input ports and out[4] to the output port. Alternatively, it is
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 6
possible to change the name of an element by selecting it first, and then double-‐clicking on the name and typing a new one directly.
• You are now ready to wire up the gates. Click on the icon in the toolbar to activate the Orthogonal Node Tool. Position the mouse pointer over the right edge of the input pin. Click and hold the mouse button and drag the mouse to the right until the drawn line reaches the pinstub of the gate. Release the mouse button, which leaves the line connecting the two pinstubs. Note that a dot will appear indicating a connection between the two wires. All nodes with the same name will be connected.
• Having completed the circuit for out[4], you now need to do the same for the other six outputs.
Checkpoint: You should get to this point at after 1 to 1.5 hours.
Step 6: Include this file in project
Every time you create a new entity or module as part of your design, you must include the file in the project.
• Click: Project > Add Current Files to Project ….,
Step 7: Make a symbol for the decoder
It is often convenient to encapsulate a circuit into a module, which is then used multiple times in a design. This is called an “entity”. For us to do so, we need to create a symbol for it. (This will create a 7_Segment_Decoder.bsf file.)
Click File > Creat/Update > Create Symbol …
Step 8: Use this module at the top-‐level design schematic
• Open “My7Seg”, the empty top-‐level design entry file.
• Use the button to place the 7_Segment_Decoder module, input port and output port on the schematic.
• Double click the port symbol to edit the Pin Property, and enter the input and output names as SW[3..0] and HEX0_D[6..0] respectively.
• Use the bus wiring
tool to wire up the ports to the module as two busses as shown below.
• Save this file.
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 7
Step 9: Pin assignment & Compilation
You need to associate your design with the physical pins of the Cyclone III FPGA on the DE0 board.
• First specify the device by clicking: Assignments > Device … • Select Cyclone III EP3C16F484C6 (check that this is indeed the chip on the DE0
board). • Click: Processing > Start > Start Analysis and Elaboration. This will work out the
input/output port names for your design. This should complete without error. Otherwise, fix all errors and re-‐analyse.
• Click Assignment > Pin Planner and a new window with the chip package diagram. You should also see the top-‐level input/output ports shown as a list.
• Click on the appropriate pins one by one, and select the corresponding port (node name) according to the list shown below. The I/O standard (i.e. interface voltages) should be “3.3V LVTTL”.
• Click: Processing > Start Compilation, to build the entire design, and to generate all the necessary files. There should be NO error, but some warnings.
Step 10: Program the FPGA on the DE0 Board
• Program the DE0 board with your version of My7seg.sof and test that it is working properly.
Congratulations! You have now completed your first FPGA design!
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 8
Step 11: Propagation Delay from inputs to outputs
• Click: Tools > TimeQuest Timing Analyzer to invoke the built in timing analyzer of Quartus II. A new TimeQuest window will appear.
• Click: Netlist > Create Timing Netlist. Then select post-‐fit and slow-‐corner, then OK. • Now click: Netlist > Set Operating Conditions … Then choose the slow model at 0°. • Now click: Netlist > Update Timing Netlist … This will use the specified timing model
and condition to produce a set of timing data. • Click: Report > Datasheet > Report Datasheet. This will produce a table showing the
input-‐to-‐output propagation delay for various combination of rise and fall times (RR, RF, FR and FF).
• Explore this to find out the worst-‐case propagation delay for your circuit. • Then delete this timing netlist, and redo it again choosing 80° as the operating
temperature. What is the delay difference at these two temperature extremes?
Step 12: Examine the resources used
• We now examine how Quartus has compiled your specification (from schematic) to actual FPGA hardware.
• In the Compilation Report window, you should have seen that your design used 7 logic elements. Let us make sure that the FPGA implementation of out[4] is identical to your specification.
• Click: Tools > Netlist Viewers > Technology Map Viewer (Post-‐fitting). Then push down into the 7_Segment_Decorder module. You should see 7 instances of the logic element.
• Identify which Logic Element (LE) provides out[4]. Hover the mouse pointer to this LE (corresponding to out[4]), you should see a pop-‐up window with the Boolean equation of the FPGA implementation. (Note that in Quartus, & = AND, # = OR, $ = XOR, ! = NOT.)
• Right click the symbol and select properties in the pop-‐up window. You will see the schematic equivalent of the Boolean equation:
• Check that this performs the same logic function as that specified in your schematic out[4]. (Don’t trace for any other outputs.) In general, you do no need to worry about exactly how Quartus implements your logic. The synthesis software should provide a design that exactly matches your specification.
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 9
Experiment 2: 7-‐Segment decoder in Verilog HDL
I hope you now appreciate how limiting and slow it is to enter a design as a schematic diagram. Modern digital designs DO NOT USE schematic as a method of entry any more. Instead a designer would either use Verilog or VHDL hardware description language to specify the design. By the end of this laboratory session, you should be convinced about the superiority of using a HDL over schematic capture.
Step 1: hex_to_7seg.v
• Create a new project Ex2a as before, with a top-‐level schematic module as before. You may call it Ex2a_Decoder.
• In Quartus II, create a design file in Verilog HDL known as hex_to_7seg.v. The actual code is given to you in Lecture 3A slide 18 and is repeated here.
• A full compilation can take a long time. A far more efficient way to check the syntax of your code by clicking: Process > Analyze current file. After you verify that the current file has no syntax error, you may then check that it is consistent with other files in your design by clicking: Process > Start > Start analysis & elaboration.
Step 2: Create a SYMBOL for this Verilog module
• Click: File > Create/Update > Create Symbol file ….
Step 3: Create the top-‐level schematic file
• Similar to last exercise, insert the symbol for the module hex_to_7seg in your new schematic file “Ex2a_Decoder.bdf”.
• Add input ports SW[3..0] and output ports HEX0_D[6..0], and connect to your decoder module.
• Beware of the difference in Quartus’ method in specifying a bus. It uses SW[3..0], which is different from Verilog using SW[3:0].
• Compile the whole design. You should find that this design works as before.
Experiment VERI: Department of EEE FPGA and Verilog Imperial College London
v1.2 -‐ PYK Cheung, 20 Jan 2014 10
Step 4: Pin Assignment – the quick way
• Earlier you used the pin assignment editor to associate pins on the package to your signals. This is a tedious process. In Ex1, if you have correctly completed the design, the pin assignment would have been stored in a file: “My7Seg.qsf” file.
• Open this file, either using Quartus’ built-‐in editor by clicking: File > Open file… or use your own favourite edit on your PC.
• You will find lines of statement such as:
• The first line defines the voltage standard used by the SW[3] signal. • The second line defines the pin location of SW[3] is PIN G4. • Now open the .qsf file for your current design, and copy & paste the assignments
from Ex1 across. You will find that this is the easiest way to deal with PIN assignment with minimal chance of introducing an error.
Step 5: Test your design
• Recompile your design, load your configuration to the DE0 board using: Tool > Programmer command.
• Test your design on the DE0 board.
Step 6: Do everything in Verilog – including Top-‐Level Specification
• It is in fact much easier to eliminate all needs for schematic capture. You can replace the top level schematic file “Ex2a_Decoder.bdf” with “Ex2a_Decoder.v”.
• Create this top level Verilog file as shown here.
• Click: Project > Add/Remove Files, and remove the .bdf file as part of this project.
• This allows you to remove the .bdf file and replace it with the .v file for the top-‐level specification.
• Compile and test.
Step 7: Do this yourself
Now complete this exercise but including the remaining switches and three of the four 7-‐segment LED display. You should find that doing so is much easier in Verilog than using schematics. You can find the pin assignment given in the file “pin_assignment.txt” (downloadable from the experiment webpage). Adding this to the .qsf file using a text editor is much easier than editing each pin one at a time.
Checkpoint: You should get to this point by the end of the Lab Session.