0% found this document useful (0 votes)
381 views

Quartus VHDL Tutorial

This document provides instructions for using Quartus II software to build and simulate a logic circuit using VHDL. It describes how to create a new project in Quartus II, add a VHDL file to describe a logic circuit, compile the design to check for errors, simulate the circuit by defining input waveforms and observing the output, and assign pins to interface with physical inputs and outputs on a development board. Specifically, it walks through building a circuit with inputs A, B, C and output Z that implements the function Z = A'B + ABC + BC' as an example.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
381 views

Quartus VHDL Tutorial

This document provides instructions for using Quartus II software to build and simulate a logic circuit using VHDL. It describes how to create a new project in Quartus II, add a VHDL file to describe a logic circuit, compile the design to check for errors, simulate the circuit by defining input waveforms and observing the output, and assign pins to interface with physical inputs and outputs on a development board. Specifically, it walks through building a circuit with inputs A, B, C and output Z that implements the function Z = A'B + ABC + BC' as an example.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Quartus II Tutorial Building and simulating a logic circuit using VHDL

Kevin Bolding, Seattle Pacific University

Introduction
Quartus II is a powerful tool for entering, editing, simulating, and building digital circuits. In this tutorial, you will learn how to enter a VHDL design in Quartus II, edit it, compile it, and simulate it.

Getting started
Before starting Quartus II
Before starting your project, you should first create a folder (File | New | Folder from any Explorer Window) to store your circuit and simulation information in. There are different choices to make depending on whether you are using a school computer or your home computer. Home computer: You may make a folder wherever you like to store your data Use Windows to create this directory. Lab computer: Use your netstore drive (N:) Create a directory on this drive, such as N:\alterawork\tutorial1\. At this point, you now have a folder in which to keep work for this tutorial.

Starting up Quartus II
Start up Quartus II by clicking on the Quartus II link from the Start Menu. On lab machines, this is in Start | Engineering Sciences | Altera | Quartus II (ver) Web Edition. A getting started window will appear. Choose Create a New Project. Next, youll be asked to pick a project directory and name your project. 1. Select the directory you set up in the beginning (or make a new one now). Give your project a name, such as circuit2. The top-level entry should have the same name. Click Next. 2. Add files. You have no existing files, so just click Next. 3. Family and Device. Select the chip used in the Altera DE1 boards Cyclone II 2C20F484C7. Click Next. 4. EDA Tools Settings. Just click Next. 5. Summary. Look over the settings and click Finish. At this point, the main Quartus II environment should be open. You should see the project name you entered (circuit1) listed in the upper left under Entity.

Building a circuit
The next step is to describe a circuit using the Quartus II editor. For this tutorial, we will use a graphical (logic gate) drawing to describe our circuit.

Opening up a new VHDL File


Altera uses the extension .VHD for schematic/block diagram files. We will create our first VHDL design by using the Text Editor built into Quartus II. To define a new VHDL file: 1. Select File | New 2. Select Design Files | VHDL File 3. Click on OK. This creates a new file with a name like VHDL1.VHD. 4. Give the file a name by selecting File | Save or clicking on the disk tool button. 5. Type the name circuit2 in the dialog box. WARNING the top-level VHDL file (this one) must be named the same as your project name. 6. Click on Save. The file is now named circuit2.vhd. At this point, you now have, within the Quartus II window, a window for you to enter your VHDL code. You may minimize or maximize this window if you wish. Also notice that there is a tab for this internal window right now it is the only tab, but later, when you have more files, you can switch between files by clicking on the tab.

Entering your VHDL Design


You may enter your VHDL design by simply typing in the code. We want to build a circuit that implements the function Z = AB + ABC + BC. Remember, there are two major parts to a VHDL design the ENTITY, which describes the input/output portions of the circuit, and the ARCHITECTURE, which gives the details for the circuit. Begin with the ENTITY, which should give the following information: Entity name: circuit2 (this must match the filename of the VHD file and the project name) Inputs: A, B, C Outputs: Z

Now enter the ARCHITECTURE, which should specify the logic function Z = AB + ABC + BC. Remember to refer to circuit2 in the of clause.

Compiling your circuit


Now that youve drawn your first circuit, it is time to compile it. Compiling is the process in which the computer reads the diagram you have drawn and converts it to its own internal form so it can simulate and build the circuit for you. The compiler will also check your diagram for any obvious errors.

Using the compiler tool


Bring up the compiler and compile your project by the following method: 1. Select the compiler tool by choosing Processing | Start Compilation or by clicking on the play tool button. A compiler window should open up. 2. A Flow Summary window should show up, and various indicators of progress in the development environment will show up. Youll see lots of information messages in the lower window. If all goes well, you should see one or more successful messages. To see your VHDL file again, click on the tab for it at the top of the window.

Finding and fixing errors


Of course, you did this tutorial perfectly, so you had no errors. Lets make some errors and see what happens. 1. Edit your VHDL file to remove the parenthesis after the AND B in the logic statement (see below) 2. Now, save the VHDL file and start up the compiler again (press start on the compiler). 3. Notice that a window pops up stating that your project has errors, and theyre listed at the bottom of the screen. Click OK on the warning window so it will go away. 4. Look at the Messages window it should list three errors, as shown below. The first error message says that a parenthesis is missing. 5. To trace this error down, double-click on the first error message. Notice that the VHDL window pops up, and the offending statement is highlighted. 6. Fix your error and save your file.

Printing your VHDL file


Use the Print Preview function to make sure that your file will print properly before clicking on the print button.

Simulating your circuit


At this point, you have a valid circuit entered into Quartus II. It is time to simulate it to check its operation. To do this, well have to set up a simulator file and define inputs. We can then check the outputs to confirm that this circuit does what we designed it to do.

Making a simulation file


Well start by building a simulation file. 1. Select File | New and select Vector Waveform File. A new window will open with a simulator file in it. Save this file as circuit1.vwf. 2. Zoom out to see all 1000ns. Use the magnifying glass button remember left-click zooms in, right-click zooms out. to do this

Selecting nodes to simulate


The first step in simulating your circuit is to select which nodes to simulate and display. For our simple circuit, well choose the inputs and outputs: A,B,C, and Z. 1. Right-click in the left portion of the simulator window (under Name and Value). Select Insert | Insert Node or Bus (see below). A window will pop up. 2. Click Node Finder. A new window will pop up.

3. Make sure that the middle drop-down box reads Pins: all. Click List. The pins A,B,C, and Z should show up on the left side under Nodes Found. (see below) 4. Copy all the nodes to the Selected Nodes on the right size by using the > or >> buttons. 5. Click OK to both windows. The simulator will now show the four nodes you selected, as shown in the third diagram below.

Drawing input waveforms


We now need to set up the input waveforms for our simulator. Currently, the inputs A,B, and C are always set to zero. You can tell this by the flat lines at zero for each of the inputs. The output is shown cross-hatched, meaning that it is undefined. This is because it has not yet been simulated, so the simulator doesnt know its value. Follow these steps to set up the inputs: 1. To make it easier to draw waveforms, set the grid size to 100ns. Use Edit | Grid Size to do this. Also, if you need to extend the timeline past 1000ns, use Edit | End Time to change the ending time. 2. First lets draw the waveform for input A. We want this waveform to be zero for the first 400ns, then one for 400ns, then zero again. 3. Use the Waveform Editing Tool . Click and drag the mouse from 400ns to 800ns for input A. When you release it, the waveform in that period will be inverted from zero to one. 4. Make the input waveforms for B and C as shown below. 5. Notice that the timing diagram now traces all possible input combinations for A, B, and C from 0,0,0 to 1,1,1. Now were ready to simulate. Save your file and move to the next step.

Simulating
Now were ready to simulate! Follow these steps to simulate your circuit. 1. Start the simulation by selecting Processing|Start Simulation or clicking the appropriate tool button . 2. The circuit will be simulated. When it is done, a confirmation window will pop up. Click OK. The simulation results will pop up you can switch between your simulation setup and the report with results by clicking the appropriate tab near the top.

3. Examine the results (below). You can confirm the correct operation by reading the simulation results like a truth table the first 100ns correspond to inputs A=0, B=0, C=0 and output Z=0. 4. Notice that there is a slight delay (about 8ns) from the input change to the output change this is because the simulation is done with actual timing data for the chip.

Assigning Pins to I/O Ports


Since the logic seems sound, we need to prepare to program our function into an actual programmable logic chip. First, confirm that you have the correct Altera part selected. (You should have done this in the New Project Wizard, but check anyway.) 1. Open Assignments | Device 2. Confirm that the Cyclone II 2C20F484C7 is selected Our project has three input ports (A,B,C) and one output port (Z). We need to assign these to specific pins on the actual CPLD device. The Cyclone II part were using has 484 pins, all arranged underneath the package in a 22 x 22 array. Clearly, we cant access them directly because theyre all under the chip (and very small). Each pin is identified by a row (A through AB) and column (1 through 22). The Altera DE1 board has connections for all the pins of the Cyclone II part to various components on the board. The most important (to the switches, buttons

and LEDs) are shown below.

We want to connect Input A to SW2, Input B to SW1, Input C to SW0, and Output Z to LEDR0. We need to note the pin numbers for each of these parts from the table above and map them using the Pin Assignments tool. 1. Select Assignments | Pins. This brings up a somewhat intimidating map of all the pins of the chip, with a table at the bottom for entering assignments. For now, ignore the fancy diagram on top. 2. The table at the bottom indicates pin assignments. Note that it has a row for A,B,C, and Z already, but there is nothing in the Location field yet. 3. Assign Input A to SW2 by selecting PIN_M22 as its location. You can just type in M22 and the software will figure out the rest for you. 4. Repeat the assignments for B, C, and Z, as shown below. Note that the pins correspond to the appropriate switches and LEDs as shown in the diagram above. 5. Close the Pin Assignments window and Recompile the project. Do not forget this step or all of your pin assignments will be ignored!

Programming the Chip


Now, lets program the chip and watch our logic at work. The chip is programmed through a USB connection using a protocol called JTAG. The method were using will program the chip

temporarily; if you turn off power to the board, the programming will be lost. Of course, you can always reprogram the chip. 1. Make sure that the DE1 board is connected to the computer using a USB cable. 2. Turn on the DE1 board by pressing the red switch. A demonstration light show will appear. 3. Select the programmer (Tools | Programmer) or . 4. Ensure that the hardware is set to the USB-Blaster (seen below). Use the Hardware Setup button to change this if needed. 5. Confirm that the file selected is the circuit you just compiled (circuit2.sof). 6. Press the Start button. You will see a blue LED light up briefly on the board as your file is downloaded. When it is complete, the light show program is replaced with your circuit.

Testing your circuit


All thats left to do is test your circuit. Remember that you assigned A,B,C to SW2,1,0 and Z to LEDR0. Move SW2,1,0 around and confirm that Z lights up when the function is true. Go through all the combinations and confirm that the hardware now matches the simulation output. Assuming it does, youve completed your first VHDL circuit design.

You might also like