Lab Activitiy 1 - For ES
Lab Activitiy 1 - For ES
Lab Activitiy 1 - For ES
LAB 1
An Introduction to Modeling, Verilog, and Real World Digital Parts
1. Project Objective:
The objectives of this lab are the following:
To begin to learn to work with data sheets for digital components..
To learn some of the behaviors of real world logic components and how these
may vary within the range of the specifications given in the data sheets. These
really aren’t like the textbook parts which are a good ideal model…
To begin to learn the Verilog Hardware Description Language
To begin to learn to use a modeling language like Verilog to aid in the design of
complex digital systems.
To learn to develop a test bench and to formulate then run tests on a gate-level
structural model of a system that we are designing. Note, we will use only
structural Verilog in all labs this term.
To begin to learn to move our design from the modeled version to a real world
implementation in a programmable part.
To introduce the Altera’s Terasic DE1 development board.
To learn that the job sometimes takes longer than we think it will.
2. Project Scope:
To meet project requirements, you will need to:
a. Get used with Instrument and Tools for Digital System Design and Analysis.
b. Get through data sheets for some devices.
c. Warm up core and background knowledge and comprehend Verilog language.
d. Draw logic diagram, build truth table and analyze the stimulation results.
3. Lab description:
In this first lab project, we’re going to be doing a lot of things, probably for the
first time for most. Our goal is to introduce the material, some of the tools, and the
concepts that we’ll be working with this term and that we’ll use to design and
develop modern (embedded) digital systems that we find in nearly every commercial
product today.
We strongly encourage you to read the entire lab specification before starting any
work. This is important. However, do not feel over whelmed; we are here to work
with you and we certainly do not expect you to be an expert in everything by the end
of this first project. We do want you to start to become familiar with the ideas,
though.
3.1 Prerequisites:
You must have some typing and programming experience. A basic understanding
of electronics that you will have gotten in your physics classes. You should
understand voltage, current, resistance, and Ohm's law. You must also have some
introduction to Boolean algebra.
3.2 Cautions and Warnings:
Never try to run your circuit with the power turned off. Under such
circumstances, the results are generally less than satisfying.
Since current is dq/dt, if you are running low on current, raise your circuit board
to about the same level as the power supply and use short leads. This has the affect
of reducing the dt in the denominator and giving you more current.
If your circuit is turning on too slowly, lower your breadboard so that it is
substantially below the power supply. This enables the charge to get a running start
before coming into your board. It will now turn on much faster.
Throwing your completed but malfunctioning implementation on the floor,
stomping on it, and screaming ‘work you stupid fool, work’ is typically not the most
effective debugging technique although it is perhaps one of the more satisfying.
When you are debugging you circuit, wiring it, taking it apart, and rewiring again
several dozen times does little to fix what may be a design error. Such an approach
is not highly recommended, but, can keep you entertained for hours….particularly if
you can convince your partner to do it.
Sometimes - but only in the most dire of situations – sacrificing small animals to
the smoke demon living in your circuit does work. However, these are not
included in your lab kit and must be purchased separately from an outside vendor.
Also, be aware that code gremlins are not affected by such sacrifices.
Alternately, blaming your lab partner can work for a short time…until everyone
finds out that you are really to blame.
Always keep only a single copy of your Verilog code. This ensures that you will
always have a maximum amount of disk space available for games, email, and some
interesting pictures. If a code eating gremlin happens to destroy your only copy, not
to worry, you can always retype and debug it again.
3.3 Instruments and Tools for Digital System Design and
Analysis
There are some helpful traditional instruments and tools that we
will be using in this lab and then when we start working as
practicing engineers.
Digital Multimeter (DMM) / Digital Volt Meter (DVM) Digital Voltmeter
A typical handheld DMM is shown in figure 1. The DMM is a Figure 1
very useful instrument when you are analyzing electronic circuits.
It can be used to check whether or not a certain DC voltage is applied or has the
expected value.
Although you can use a DVM for AC voltages, AC and DC currents, and
resistance as well as DC voltages, to be able to see and truly understand what is going
on in a digital circuit, you must use an oscilloscope or logic analyzer.
Oscilloscope
A multimeter is a useful tool for looking at the value of a
(typically DC) signal. To be able to see how a signal is
changing in time or to analyze its waveform, we must use an
oscilloscope. A Tektronix instrument is shown in figure 2.
Altera Terasic DE1 Development Board
The Altera Development board is typical of the
environments with which one might work during the design,
development, and test of many contemporary digital systems. Oscilloscope
The environment supports a variety of different kinds of Figure 2
components that, during the later phases of a project
development, will be migrated to a system board that will be integrated into the
completed design.
The picture in figure 3 shows the DE1 board with most of the major components
highlighted. We will be using the various input/output devices located directly on
the board such as the switches and LEDs. Further details will be provided in each
lab. Take note of the large FPGA (Field Programmable Gate Array) that is
highlighted on the board. Later on in the term we will be programming this and
directly interfacing with many the devices on the board. Think of it like a universal
logic unit that all the devices can talk to. For now there is a program loaded into the
Figure 3
FPGA to allow you to use the Input/Output connectors on the board to make the
earlier labs easier.
The FPGA
FPGA is an acronym for Field Programmable Gate Array. Essentially, it is a large
array of logical elements that have been connected together. However, in an FPGA,
the connections between these logical elements can be programmed and
reprogrammed. This means that it can be used to build many different kinds of
hardware all on the same chip.
OK, time to get to work…
3.4 Procedure:
3.4.1 Part 1: Modeling, Simulating, and Testing a Digital Comparator
In the first part of the lab project, we will begin to learn to develop models of our
systems as an integral step in the design process. We will start by working with the
Verilog hardware design language and the Icarus Verilog development environment.
Later, we will also utilize Altera’s Quartus development environment.
File Creation and Simulation
Using the background information provided on Verilog and Icarus, create a
Verilog source file (comparator.v, for example) containing the code provided in
Verilog Source Code Example in the Appendix B of this lab. Tutorial information
can be found online, given in Appendix A of this lab, given in the lab lectures, and
in Appendices A and B of your text.
Once the file has been written, run the Icarus compiler to synthesize your system
model then run your test bench and test vectors (your test inputs) to verify the
accuracy of your design. From your simulation, obtain the following,
1. A hardcopy of the source code that you developed.
2. A hardcopy of the result of running your test bench under Icarus.
NOTE: On your first pass, there may be a couple of simple errors in the program –
these are intentional. If so, use your compiler error messages to find them.
Each team member should complete the initial portion of part 1.
Build
To implement the system, we are going to use the Altera Cyclone II FPGA on
the DE 1 Board.
Although the Quartus tools support graphical entry, for our first design using the
DE 1 Board and Quartus environment, we are going to work with the Verilog code
that we have developed and tested up to this point.
All of that said, read through this section completely before starting your
implementation…
Important First Steps
First scan through the DE1_user_manual:
This is a very good overview of the capabilities of the board and a handy
reference.
Start with and follow Tutorial 1in Appendix B of our class text to see how
to get a new project started (also see Recommended Design Approach
below).
Specifically, first read sections B1, B2, and B4; then, from Appendix C,
read sections C1.1 and C1.2.
The same information is presented in a slightly different form, in the
Altera tutorial in the DE1 tutorials in the document:
tut_quartus_intro_verilog.pdf.
Bear in mind, that the devices in the Altera tutorial (s) are different from
ours, they may reference the DE2 board, and there may be some
information that we are not using at the moment.
Go through this document to get a step-by-step guided tour of developing
a Verilog entry project in the Quartus environment.
After you have gone over the tutorials and other background material,
you’re ready to go.
A C A C
B A B
AB C B AB C A B
00 0 00 0 0 1
AND Gate OR Gate Inverter
01 0 01 1 1 0
10 0 10 1
11 1 11 1
Figure 4
Figure 7
SEL1
SEL1 SEL2 RESULT
0 0 Result = A and B
SEL2 0 1 Result = A or B
1 0 Result = A xor B
1 1 Result = 0
A
B
RESULT
As we saw in the first model, the Verilog module names for these gates are the same
as the gate type, except they should be in lower case. The inverter in Verilog is called
a not gate.
Follow the circuit diagram and the selection assignments shown above.
Create the source code for the gate-level (structural) model. To make life
easier, look to the sample Verilog code as an example.
Use common sense in creating signal names, a person with no prior
knowledge of the lab should be able to tell them apart.
Create a tester and a test bench then use these to confirm that the design
implements the truth table in table 1.
If the Verilog code from the Comparator design is used as a guide, do not use any
time delays, i.e.: omit the #delay from any gate instantiation. Use module, gate, and
signal names that reflect the current circuit, not those from the Comparator design.
Implementation and Test
After confirming the operation of the design, we now implement the circuit.
In the Quartus IDE, create a new project and enter your MultiFunction source
code file. Be certain not to include your test bench or test code. Assign pins to
connect each of the system inputs to one of the switches and, similarly, each of the
outputs to one of the LEDs on the DE1 board.
Confirm that the functionality of your design agrees with its truth table.
Part 2 Report
Your report for part 2 must contain the following,
1. A copy the Verilog source code for the MultiFunction Logic Block, the
testbench, and the tester.
2. A copy of the simulation results.
Wiper Wiper
Single Pole - Single Throw Single Pole - Double Throw Double Pole - Single Throw Double Pole - Double Throw
Figure 6
Switch Examples
(SPDT) switches, since the single arm is making contact in either position. We
see examples of such switches in figure 6.
In this lab, we will be using a DIP switch to assert our logic input states.
It's also important to remember that semiconductors - integrated circuits - are
delicate and static sensitive devices.
To use a DIP switch as a logic input, connect the switch as shown in figure 7.
Observe that we have a pull-up resistor shown. Such a resistor is used to ensure
that we never have an open input (nothing connected) to the circuit input when
the switch is in the open position.
When we start to study sequential circuit design in
Vcc
future labs, we will encounter some problems that are
10K
associated with mechanical switches and we will have
to use a single pole - double throw switch. But for circuit input
now, the setup as shown will be good enough.
Switch Closed - Logic 0
Switch Open - Logic 1
Figure 7
DIP Switch with Pull-Up Resistor
The DIP switch we will be using in the lab has the same number of pins on
each side. Each switch connects the two terminals that are across from each other.
Depending on the position of the switch, the two terminals are either connected
(shorted) or disconnected (open circuit).
Using an LED as an Output Device Vcc
Figure 11
module testBench;
// wires connect things together
wire lesseq, a, b, c, d;
endmodule
// within the modules, wires are implied…we can put them in if we want to
parameter delay = 2;
output lesseq; // Ouputs: lesseq
input a, b, c, d; // Inputs: to compare, ab
and cd
/**************************************************************
* Define the test bench module.
**************************************************************/
module testBench;
// wires connect things together
wire lesseq, a, b, c, d;
endmodule
/**************************************************************
* Define the Comparator module.
**************************************************************/
// within the modules, wires are implied…we can put them in if we want to
parameter delay = 10
output lesseq; // Ouputs: lesseq
input a, b c, d; // Inputs: to compare, ab
and cd
// the following code illustrates how we can test for aberrant conditions
// we use the specific SEQUENCE of events to cause a glitch - were there others
begin
$display("Producing Glitch");
#stimDelay {a,b,c,d} = 0; // a=0, b=0, c=0, d=0
#stimDelay {a,b,c,d} = 10; // a=1, b=0, c=1, d=0
end