Lab 1: Digital Logic CAD Tools
The purpose of this lab is to familiarize you with logic gates and basic digital logic design techniques. We will be using a digital logic CAD program, Quartus, to generate our designs using a graphic layout tool. We will use a simulation tool, ghdl, to test our designs and ensure they are working correctly. We will download the program to an FPGA board to see it in action, which is what I hope you will do for most projects. But if that isn't possible (we do have a limited number of boards), you can focus more on the simulation output..
If you want to watch a movie of the first 40 minutes of the lab Zoom session from Fall 2020, please do so here.
Design a Circuit using Quartus
-
/
Log into the lab computer. It will be named d122-## where ## is a 2-digit number in the range 0 to 15.
+ (If you are using your laptop)
If you are not in the lab, you will need to log into the computer remotely. You will need to do so using your Terminal (or equivalent if on a Windows machine). You will be running all programs from the terminal and you will have access to the GUI on the applications we us (Quartus, GTKWave, and Python), but it will be slow and you will not be looking at the desktop of the lab computer.- If you are on a Mac
- If you do not have XQuartz installed, then you will need to install it (this is the application that runs on your computer but allow the remote computer to pop up windows).
- Open a Terminal on your laptop. Note: this may need to be an XQuartz terminal, rather than a Mac terminal. Try the Mac Terminal first, and use it if you the display works correctly (I.e. if you are able to see Quartus run when you get to that task in a few steps).
- Open a secure remote connection to on of the lab computers. You can choose from d122-01, ... d122-15. You will need to include your username and a flag indicating that you want to allow graphic information to be sent to your laptop (-Y or -X, and if you have a slow connection, -Y is a better choice). If I am logging into d122-01, then this is the command I use
ssh -Y srtaylor@d122-01.colby.edu
You need to use your username instead of srtaylor and you choose one of the computers.
- If you are on a Windows machine
- You may want to watch this video, that a student found to be helpful.
- Install XMing and Putty
- Start XMing
- Start Putty, but you need to adjust your settings: Find the SSH settings, and click on the X11 settings, select "Enable X11 forwarding" and enter "localhost:0" as the host. You might want to save these settings. You also need to enter the name of the host computer. Choose one of the lab computers (d122-01 .. d122-15)) and provide the name with .colby.edu appended to it.
- Press the connect button (Sorry, Stephanie doesn't remember exactly what it says on it!)
- Enter your password, and you should see the prompt change from your usual prompt to one indicating which computer you are on. For example, when I log into d122-01, here is what I see
srtaylor@davis122-2705a1:~$
- Now you can follow all the instructions for students in the lab, because anything you type after that prompt is commanding a lab computer to do something.
Quartus is the main application we are doing to use to desing our circuits. Early in the semester, we will be drawing circuit graphically by pictures of gates with pictures of wires. Then, we will switch to programming in a language called VHDL.
We start Quartus from the command line of a terminal, so if you are in the lab, open a terminal. If you are not in the lab, then open a terminal on your laptop and ssh in to one of the lab computers by following the instructions above.
When we start an application from the command line, we can't use that shell again until the application is closed, unless we start it in the background. We can run any program in the background by putting an ampersand after the command. To run Quartus in the background, we type
/opt/quartus13.1/quartus/bin/quartus &
The first time you open Quartus, it will prompt you to pay for the full version. Instead, indicate you want to use the web version.
Quartus should start up. In the main window are buttons to open an existing project (Open Project) and to create a new project (New Project Wizard). Press the New Project Wizard button.
Specify where you want to put the project and a name for it and the top level design entity. As noted, the project name and entity name must be identical. You should put each project in its own sub-directory, probably inside a cs232 folder.
We have no design files to add, so skip the next screen.
You will be testing the circuits in one or two ways - you will simulate the circuit, and, if you are in the lab and all is working, you will also be able to run the circuit on the FPGA board. Today, my plan is for everyone to test on the boards, but this is the first time we are using the new boards, so I expect something will go wrong and we will need to adapt. Select the device for the DE0 board, which is a Cyclone III FPGA with the name EP3C16F484C6. You should use the Family list to choose Cyclone III, then you can either scroll through the Available devices list until you find it, or you can copy-paste the name into the Name filter. You will probably need to use Control or right-click instead of Cmd. Once you have the right device name in the list, select it (it will appear blue as shown in the image below).
That should complete your project setup.
After creating the project, select File::New and pick a Block Diagram/Schematic File.
In the block diagram file you can now lay out circuits graphically and connect them with virtual wires.
- If you are on a Mac
-
Using the graphic layout tool, make a simple combinational logic tree
for the function F = AB + A'B'. Double-click on the dotted background or press the button above that looks like an AND gate to place a new
module. There are many types of modules. We want to use a simple
primitive logic gate, as shown below.
Lay out two 2-input AND gates and one 2-input OR gate to build the circuit. Then connect the output of each AND gate to the inputs on the OR gate. You can click and drag to make wires.
Create two input pins and one output pin, again by double-clicking and then selecting input or output from the pins category. Place the pins in the upper left (inputs) and upper right (outputs) of your graphical design. Then edit the names so the pins are named A, B, and F.
Next, make a small wire coming out of each input pin and a small wire coming into the output pin. A really helpful feature of Quartus is that is allows yout to label wires. This makes virtual connections, so you don't need to have lots of crossing lines. To label a wire, simply type while it is selected. Label these as A, B, and F, respectively.
Next, add two NOT gates in front of the second AND gate and feed the A and B inputs to the NOT gates. The final circuit is shown below.
Select File->Save Project and save your work as a bdf file. Since it is the top level file in your project, give it the same name as your project name, in this case circuit1.bdf.
Simulate a Circuit Using GHDL
Our next goal is to simulate the circuit. First, we convert the circuit diagram to VHDL file. VHDL is a programming language designed for simulating circuits, and you will learn it in coming weeks. Then, we use the ghdl command line tool to run the simulation.
- Select File::Create/Update::Create HDL Design File from Curent File.
- Now you need to create a driver file that sends signals into your circuit and accepts the output. An example for the circuit above is testbench.vhd. This file defines three signals: A, B, and F. It then assigns values to A and B at certain time intervals. These values and time intervals form the four possible combinations of A and B. The file then attaches these signals to the circuit you created above. Note that you will need to edit the testbench.vhd file so the component statement label matches the name of the circuit you created. I named mine test, so my version needs to say "component test" in the declaration section and "test port map" in the code section. If your file is named circuit1, then your file needs to say "component circuit1" in the declaration section and "circuit1 port map" in the code section.
- Save your VHDL test bench file in the same directory with your circuit's vhdl file.
- In the terminal window on the lab computer, run the ghdl tool to compile the code, produce a simulation output (a .vcd file), and then view each signal over time with gktwave.
The instructions are in this movie and below:
- Run the ghdl tool in the Terminal (making sure you are in the same directory as the .vhd files) to compile and simulate your circuit. Remember,
I called my circuit circuit1, so my vhdl file is called
circuit1.vhd.
ghdl -a circuit1.vhd testbench.vhd
ghdl -e testbench
ghdl -r testbench --vcd=testbench.vcd
-
Finally, open up the .vcd file in gtkwave.
gtkwave testbench.vcd
Once the window opens, select all of your signals and select "Insert". Then click on the "Zoom to Fit" button or set the bounds of the window to 0 ns to 100 ns. You should end up with a visualization like below.
You can see in this example that the circuit is working properly. The output F is high when A and B are both low (0) or both high (1), and F is low (0) when A and B are not the same value.
- Run the ghdl tool in the Terminal (making sure you are in the same directory as the .vhd files) to compile and simulate your circuit. Remember,
I called my circuit circuit1, so my vhdl file is called
circuit1.vhd.
In the popup, select VHDL and click Ok. This should create a vhdl file version of your circuit. The name of the file will end in .vhd
Test a Circuit with the Altera DE0 Board
The Altera DE0 board contains a programmable Field Programmable Gate Array [FPGA]. An FPGA is an electronically configurable set of gates (truth tables) that can be programmed to emulate very complex digital circuits, including CPUs. The Quartus software can compile a digital circuit into a form that can be downloaded onto the FPGA.
The Altera DE0 board contains many different input and output devices, including push-buttons, switches, LEDs, and 7-segment displays. We will be using these input and output devices to control and evaluate our circuits.
You can find the documentation for the DE0 board here. Pages 25-29 specify which output pins control which I/O devices.
In order to program the board, you need to follow these steps.
- Compile the code with Quartus (Quartus compiles the code for download onto the board, whereas ghdl compiled it for simulation). Press the purple arrow to do so.
-
Open up the Assignment:Pin Planner window. If you have set
up the input and output pins of your circuit correctly, they will
show up at the bottom of the window. In the Location column,
specify the pin for each input and output. For the simple circuit
above, for example, you can use the first two switches (PIN_J6
and PIN_H5) as the inputs and the first green LED (PIN_J1) as the
output.
Once you have specified the pins for all inputs and outputs, close the Pin Planner window and compile your circuit. Any time you change pin assignments, you must recompile.
- Second, plug the DE0 board into an available USB port, if it is not already plugged in. If no lights appear, then click the red button to turn on the board. The default program should produce flashing lights.
-
Third, open up the Tools::Programmer window. If the window says
"No Hardware" then click on Hardware Setup, click on the popup
menu that says "No Hardware" and select the USB Blaster. Then
close the Hardware Setup window.
At this point, if the Start button is available, click it and it should program the board. If the Start button is not active, then click Select File, navigate to your output_files directory and select the .sof file corresponding to your circuit. If the Start button is now active, click Start and it should program the board. You will know the board has been programmed when the default FPGA program with the flashing lights stops.
If clicking on the Start button does nothing, please contact me and let me know the (1) name of the machine on which you are working and (2) whether any error messages show up in the Quartus log window.
-
Once the board is programmed, you can control your circuit by
modifying the switches you set up to control the circuit inputs.
In the case of the simple circuit above, if the two switches are
both 0 or both 1, then the LED should light up.
Here is a demo if you really want to watch one. I warn you that production values are extremely low.
- When you are done with the board, please use the red button to turn it off.
When you have completed the lab assignment, go ahead and get started on the first project.
Fall 2026