CPRE281_LAB03
CPRE281_LAB03
PRELAB!
Read the entire lab, and complete the prelab questions (Q1-Q2) on the answer sheet
before coming to the laboratory.
1.0 Objectives
In the last lab, we learned how to use schematic capture to design digital circuits in Altera
Quartus Prime. The steps performed were: understanding the problem statement,
deriving a logic function, drawing the logic expression using logic gates (NOT, OR, AND),
naming the inputs and the output, and finally using the FPGA and/or ModelSim to verify
the circuit for all possible values of the input. This lab is similar; however, we will take a
different approach. We will write Verilog code to describe the logic expression instead
of drawing the logic gates.
2.0 Setup
2.1 Verilog
At this point, you might be asking yourself, “What is Verilog, anyway?” First, you have to
know what a Hardware Description Language (HDL) is. HDLs are used to perform a logic
synthesis of a design. That means we write a code describing our logic and the HDL
compiles it to create the adequate circuit diagram. This simplistic definition is very
powerful and tells us that now we can just “code” our logic, and we will get the equivalent
circuit, without going through the hassle of drawing it. Verilog is an HDL that is used
widely throughout the US industry since it went open-source in 1990. It is portable in
nature, meaning that the same code can be used in different CAD tools. Just like any
coding language, it has a compiler, libraries, syntax, commenting, etc. There exist many
HDLs besides Verilog. The most popular among others is VHDL (V stands for Very High
Speed Integrated Circuit), and is used in most industries in the rest of the world.
1
Cpr E 281 LAB3 Introduction to Circuit Design using
ELECTRICAL AND COMPUTER
ENGINEERING Verilog
IOWA STATE UNIVERSITY
endmodule
endmodule
After this brief introduction to Verilog, we will get started on two design examples. For a
more thorough reference on Verilog, read textbook.
2.4 Setup
Create a folder U:\Documents\CPRE281\Lab03, and four sub-folders \Lab03\lab3step0,
\Lab03\lab3step1, \Lab03\lab3step2, and \Lab03\lab3step3. You will be saving your
work and programming the hardware for this lab in these directories.
2
Cpr E 281 LAB3 Introduction to Circuit Design using
ELECTRICAL AND COMPUTER
ENGINEERING Verilog
IOWA STATE UNIVERSITY
3.0 Design 1
You will design and verify the “farmer’s problem” describe below using Verilog. You will
use the product-of-sums (POS) expression. You will run a schematic, a structural, and a
behavioral description of the same problem. The goals of this lab session are:
For each design simulation, you have to show your simulation results and your code
and/or schematic to the lab instructor to obtain their initials on your answer sheet.
Description:
A farmer owns two barns; one north of a creek and the other south. The farmer has a
Cabbage, a Goat, and a Wolf. The Farmer needs to put each item in a barn every night.
If the Cabbage and the Goat are in the same barn, the Goat will eat the Cabbage. If the
Wolf and the Goat are in the same barn, the Wolf will eat the Goat. The Farmer is
worried and you have to design an alarm circuit that will let him know if two items can
safely be placed in a barn.
For this circuit, you have three inputs = {Cabbage, Goat,Wolf } and one
output = {Alarm}.
If an input is in the north barn, it gets assigned logic 1, and if it is in the south barn it
gets assigned logic 0. The output Alarm, asserts if there are two items in a barn that
should not be kept together.
3.1 Schematic Capture with Quartus Block Design Files (lab3step0) and FPGA
In this step, you will use Schematic Capture with the FPGA to simulate the alarm circuit.
This is the method we used to simulate the simpler circuit in Lab 2.
1. Verify your logic expression for the alarm circuit.
2. Open Quartus and create a project named lab3step0 and save it under
U:\CPRE281\Lab03\lab3step0.
3. Implement your Product-of-Sums logic expression in a BDF.
4. Compile as necessary, assign pins, and program the FPGA.
5. Verify your results and demonstrate the completed circuit to the TA.
3
Cpr E 281 LAB3 Introduction to Circuit Design using
ELECTRICAL AND COMPUTER
ENGINEERING Verilog
IOWA STATE UNIVERSITY
run 400
(Note that if your Verilog inputs are not named C, G, and W, then you will have to rename
them here such that they are the same.)
3. Save this file to the lab3step2 project folder as basic-alarm.do.
4
Cpr E 281 LAB3 Introduction to Circuit Design using
ELECTRICAL AND COMPUTER
ENGINEERING Verilog
IOWA STATE UNIVERSITY
4. Now, in Questa, after you have established waveforms for the inputs and outputs
by selecting them all and pressing Ctrl-W, you can go to the command line and
simulate the inputs by running your DO file with “do basic-alarm.do”
5. Once all of your outputs are simulated correctly, show your code and results to
the lab instructor.
3.4 Troubleshooting
Error: Can’t compile duplicate declarations of entity “filename” into library “work”.
This error is generally due to having two files with the same name as the project.
5
Cpr E 281 LAB3 Introduction to Circuit Design using
ELECTRICAL AND COMPUTER
ENGINEERING Verilog
IOWA STATE UNIVERSITY
6
Cpr E 281 LAB3 Introduction to Circuit Design using
ELECTRICAL AND COMPUTER
ENGINEERING Verilog
IOWA STATE UNIVERSITY
5.0 Complete
You are done with this lab. Ensure that all lab files are closed, exit Quartus Prime and
Questa, log off the computer, power down the DE2-115 board, and hand in your answer
sheet. Don’t forget to write down your name, student ID, and your lab section number.