cse141L
Lab
1:
Be a Hardware Hacker!
Changelog
| April 01 |
Added a link to our google site with tips and tricks for using the tools. It'll be updated throughout the quarter. It's here. The page includes the course coding standards.
|
| April 02 |
Complete this form with a "code-name" of your choice to be used instead of your personal info for the Grade-sheet (your code-name should not under any circumstances reveal your identity).
|
| April 03 |
Added clarification about LUTs. See Question 3 for details.
|
Part 1: Log into the discussion boardDue: April 08
There is a link to the course's discussion and announcement board on the course homepage.
Sign up for them.
Take some time to explore the discussion boards features.
Reading the blackboard is mandatory. It is the only place that all
announcement related to class will be posted.
| Deliverable |
Post a reply under the "Welcome" message in the forum.
You don't need to hand anything in.
|
Due: April 08 |
Part 2: Due: April 08
Lab 1 is a preparation stage for future labs, and consists of two parts - Altera Quartus and Verilog. In Lab 1, you will install the Altera tools and follow a step-by-step tutorial to learn essential concepts and working flow in hardware designs. For those who used Altera Quartus in 140L, this lab should be very easy. Otherwise, you should START NOW - there might be many unexpected problems. If you have any question regarding this lab, please post it on the blackboard.
Remember to follow the coures coding standards for verilog. They are here.
Tools:
The main verilog development tools we use in this class are Altera's Quartus II Web Edition (version 12.0sp2) and ModelSim-Altera Starter. Both of these tools should already be on the lab machine. If you would like to install them for personal use (laptops, home desktops, etc.) here some instructions for downloading the tools:
-
Get Altera Quartus II Web Edition 12.0sp2. Note: It should already be installed in the labs. Please let use know if you find machines that do not have the software, or have older versions.
- Go to this link.
- Select the Windows link (Linux tools are available but we will not be supporting them in this class).
- If you already have an account with Altera, put your username and password. Otherwise, use the One-Time Access option.
- Altera uses a download manager to speed up the download, you can use that, or click on the download your file now link at the bottom. The download is ~3 GB and will take a while to download.
- Run the downloaded file to install the web edition tools. Click through the installation with all of the default options. You do not need to get a Quartus II subscription license, so uncheck the box on the last screen of the installer.
-
Get ModelSim-Altera Starter 10.0 sp2. This also should be installed on the lab machines.
- Go to this link.
- Select the "Individual Files" tab.
- To be consistent with the version present in the CSE basement, you will need to download the two files listed below. However, you can probably complete the first lab with just the first file.
- "v10.0d Software Download for Quartus II v12.0"
- "v10.0d Service Pack 2 for Quartus II v12.0"
- Run the downloaded files in the order above (regular and then SP2) to install the tool. Click through the installation with all of the default options.
Altera Quick Tutorial
Altera provides a good step-by-step tutorial. With this tutorial, you will be able to learn how to perform various activities in the hardware design process. It should take less than two hours to follow the tutorial.
- Open the Altera quick tutorial .
- Follow instructions in the tutorial, up to and including Section 6.1. You will design and compile a simple light controller circuit in Verilog. When creating your project, target the DE1 board with the 'Cyclone II EP2C20F484C7' FPGA.
- Try to understand the Verilog source file used in the tutorial.
- Also work through the first three chapters of the ModelSim tutorial. You can get a copy of the example files for this tutorial here.
- A consolidated tutorial on Modelsim simulation can be found here.
A Simple 8 bit Adder
Now that you know how to use Altera Quartus II, we will examine a few aspects of hardware design.
- Suppose that you got a job from 'San Diego Chip Factory'. Your boss gave you an adder design written in Verilog - adder.v to implement it in an Altera FPGA 'Cyclone II EP2C20F484C7'. Your first assigned task is to understand the source file thoroughly, and make a project in Altera Quartus II.
Question 1: Draw a schematic for adder.v. In your schematic, you should clearly show the function of the design by using flip-flops, various gates, a comparator, an adder, and wires. Try to infer a schematic from the Verilog source, but it is fine to use a generated schematic from Quartus as long as it is detailed enough.
- To see what is really going on, perform a behavioral simulation in Modelsim. You should use this as a starting point: test_adder.v.
- You need to modify the Testbench to give the proper stimulus and make sure the clock will run at 500MHz (Hint : t=[1/f] and clock toggles every t/2).
- Simulate for the following sets of inputs:
- One input is consecutive 8 bit odd numbers and other is consecutive 8 bit even numbers. For example, 1 + 2, 3 + 4, 5 + 6 etc. Your testbench should generate a new pair of inputs for every clock cycle.
- Try a pattern which can give you both even and odd numbers as the sum. Does your adder behave as you expected?
- You might have noticed that output isOdd is updated one cycle later than out. Modify the adder verilog file so that isOdd is simultaneously updated with out. Perform the same behavioral simulation you did in the previous step again.
Question 2. Draw a schematic for your modified adder.
- After you checked your adder is functionally correct, it is time to synthesize. In the synthesize stage, Altera Quartus translates your Verilog design to what its backend stage (implementation stage) can understand. To synthesize a design, just double-click "Analysis and Synthesis" in the Tasks pane. Skim through the generated synthesis report.
- Now you'll want to see how your design maps onto the FPGA. The stage where the design tools find a good layout on the device is called "Place and Route". Run this stage by double clicking on "Fitter" in the Tasks pane. Skim through the generated reports.
Question 3. How many flip flops (a.k.a. registers) are used for the design?
How many LUTs does the Cyclone II EP2C20F484C7 have, and how many LUTs does your design use?
How many IO Pins are used? (Note: The number of LUTs in your design is not necessarily equivalent to the number of logic elements. Check out the schematic for a Cyclone II logic element
here. You'll notice that a logic element contains a variety of things that may or may not be used, including a LUT, a register, some MUXes, and a carry chain. To see what the number of LUTs that you are actually using in your design are, go to "Fitter"->"Resource Selection"->"Resource Usage Summary" and add up the number of 4-input, 3-input, and <= 2-input LUTs.)
- Now that the design tools have mapped your design to an FPGA, you can estimate timing and figure out how fast your adder will operate. Run the design through the whole compilation chain, which includes a timing analysis: go to the "Processing" menu, click "Start Compilation." Look over the reports in the "TimeQuest Timing Analyzer" section. The Fmax number in "Slow Model" Report is the maximum clock frequency at which your adder will run. The "Slack" and "TNS" indicate how well the design meets the timing constraints in the clock domain. These can be seen in each of the "Setup Summary" reports. For more information on timing analysis in Quartus II, see the tutorial on timing.
Question 4. What is the minimum achievable cycle time and maximum frequency?
What is the slack?
Since we didn't specify a target clock cycle, what period and frequency did the tools use as a default target?
- To show your boss that your adder would work at a certain frequency, you need to do a post-route simulation with the same testbench in Question 2. Sometimes, post-route simulation is also used to verify the validity of your implementation. (The result of post-route simulation should tally with that of the behavioral simulation.) Running a post-route simulation is very similar to running a behavioral simulation. Since the tutorials do not cover how to run a timing simulation using ModelSim and a Verilog testbench, here are the instructions you'll need to get started:
- Make sure you have the simulation tool settings set to Modelsim in Quartus II. To do this
- Open settings from EDA Netlist writer -> Edit Settings
- Navigate to EDA Tools Settings -> Simulation and select "ModelSim-Altera" under "Tool Name"
- Click on "OK" to apply the settings
- Make sure to run the entire compilation process in Quartus II (including "EDA Netlist Writer")
- Open ModelSim
- Select "File" - "Change Directory..." and navigate to the "simulation" and then "modelsim" subdirectories under your adder project directory. If you forget to do this you will likely end up with the error "SDF file was not found" when you run your simulation.
- Select "File" - "New" - "Library..." and select "a new library and a logical mapping to it." Name the library "work" and enter "work" for the library physical name as well. You should then see the work library at the top of the library list.
- Select the work library and select "Compile" - "Compile..." Select adder.vo (assuming your project name in Quartus was set to "adder") and then click "Compile." Then navigate to test_adder.v (the same testbench as before), which should be a couple directories up. Click "Compile" with test_adder.v selected. THen click "Done". Now, in the library list, if you expand the "work" library, you should see "adder" and "test_addr". In the future, if you make any changes to adder or testbench Verilog source, you'll need to recompile the "work" library before re-simulating.
- Select "Simulate" - "Start Simulation" and do the following:
- In the "Design" tab, expand the "work" library and highlight "test_adder". Select "ns" in the "Resolution" drop-down field.
- In the "Libraries" tab, in the "Search Libraries" area, select "Add" and add the "cycloneii_ver" library.
- In the "SDF" tab, select "Add". Add adder_v.sdo and apply it to the region /test_adder/dut.
- Finally, click on "OK" to start the simulation. After this, use ModelSim to run the timing simulation in the same manner you used it to run the functional simulation.
Question 5. Put two simulation results(behavioral and post-route) in your report.
Are they the same? If not, why are they different?
Modify the test bench file, and make sure post-route simulation works correctly. (Hint: Behavioral simulations do not have a sense of frequency while post-route simulations do.)
32 bit Adder
- Now that your adder works fine, your boss wants you to extend your adder to support 32bit additions. Modify your verilog source file, synthesize it, and implement it. (Hint: You can very easily extend the existing 8bit adder to 32bit.)
- Generally, the more complex and the bigger a design is, the slower it is. Two important causes are: (1) more complex logics usually use more LUTs, thereby increasing their logic delays, (2) as a design gets bigger, it is increasingly difficult to place and route LUTs in their optimal places.
Question 6. After you reported to your boss that bigger designs tend to be slower and use more resources, he is concerned about your adder's resource usage and the maximum operational frequency. To relieve his worries, fill out the following table. To impress him even more, include 16bit and 64bit adders, too.
| Width |
Max Freq (synthesis report) |
Max Freq (post P and R report) |
# of used 3 input LUTs |
# of used IO Pins |
| 8 bit |
|
| |
|
| 16 bit |
|
| |
|
| 32 bit |
|
| |
|
| 64 bit |
|
| |
|
Multiplier
- Your next assigned task is to design a multiplier. You can easily make one by modifying your adder. First try a 32bit multiplier. For multipliers, the width of output should be (2 * the width of input), and they have to have 'isOdd' output.
- After synthesis, skim through the generated synthesis report. You should notice Embedded Multipliers, which you have not seen before, are used for your design. Since multipliers are frequently used in digital designs, most FPGAs include a few highly optimized multipliers.
Question 7. Fill out the following table for 8bit, 16bit, 32bit, 48bit, and 64bit multipliers. Note that some multipliers might not fit in the Cyclone II due to their demands on resources. In such cases, explain the reason.
| Width |
Max Freq (synthesis report) |
Max Freq (post P and R report) |
# of multipliers used |
# of used IO Pins |
| 8 bit |
|
| |
|
| 16 bit |
|
| |
|
| 32 bit |
|
| |
|
| 48 bit |
|
| |
|
| 64 bit |
|
| |
|
Question 8. Draw two graphs for adders and multipliers with bit width as x axis and frequency(MHz) as y axis.
Free Form Experiment
Question 9. Now that you have gotten your feet wet with the tool, it's time for some free exploration. Design an experiment that answers some kind of question you have about the tool, and report on the results.
Useful Resources
| Deliverable |
- No lab interview for lab 1. In future labs, you will have
interview sessions with a TA to show your results.
- Submit your report as a single pdf file at ted.ucsd.edu. The link to upload the file is available under "Assignments"->"Lab 1: Be a hardware hacker". The deadline for submitting your report is Monday 8th 3PM . Do not send softcopies to TAs email ids
- Answer all of the questions (9) found in the lab description.
- The report should be in a single PDF file (including answers to
questions, verilog source code, graphs, screen-shots, etc). There
are many tools out there capable of integrating text and graphics
and producing PDF files (OpenOffice does a pretty good job).
- Name your PDF file cse141L-lab1-LastName-FirstName.pdf
with your last name and first name substituted for LastName and
FirstName, respectively.
|
Due: April 08 |