Lab Exercises LaMeres Intro To Logic WVHDL
Lab Exercises LaMeres Intro To Logic WVHDL
LAB EXERCISES
Table of Contents
TABLE OF CONTENTS .............................................................................................................................. III
INTRODUCTION .......................................................................................................................................... 1
PARTS LIST ................................................................................................................................................. 3
CHAPTER 1: ANALOG VS. DIGITAL ......................................................................................................... 7
LAB 1.1: INTRODUCTION TO LAB EQUIPMENT & BLINKING AN LED WITH AN AWG............................................ 7
1.1.1 Objective ....................................................................................................................................... 7
1.1.2 Learning Outcomes ...................................................................................................................... 7
1.1.3 Parts Needed ................................................................................................................................ 7
1.1.4 Deliverables .................................................................................................................................. 7
1.1.5 Lab Work & Demonstration ........................................................................................................... 7
Using the AWG to make an LED Blink ...................................................................................................7
Measure the Logic Signals in the LED Circuit ...................................................................................... 13
iii
iv • Table of Contents
9.1.5.1 Implement the Ripple Counter System in VHDL on the DE0-CV Board ......................................... 125
9.1.5.2 Take a Logic Analyzer Measurement of your Counter ................................................................... 127
9.1.5.3 Save a Copy of your top.vhd for your Records ............................................................................... 130
LAB 9.2: A “W ALKING 1” FINITE STATE MACHINE ...................................................................................... 131
9.2.1 Objective .............................................................................................................................. 131
9.2.2 Learning Outcomes ............................................................................................................. 131
9.2.3 Parts Needed....................................................................................................................... 131
9.2.4 Deliverables ......................................................................................................................... 131
9.2.5 Lab Work & Demonstration ................................................................................................. 131
9.2.5.1 Implement the Walking 1 FSM ....................................................................................................... 133
9.2.5.2 Take a Logic Analyzer Measurement of your Walking 1 Pattern .................................................... 134
9.2.5.3 Save a Copy of your top.vhd for your Records ............................................................................... 135
LAB 9.3: COUNTERS USING A SINGLE PROCESS AND A 2N CLOCK DIVIDER ................................................. 137
9.3.1 Objective .............................................................................................................................. 137
9.3.2 Learning Outcomes ............................................................................................................. 137
9.3.3 Parts Needed....................................................................................................................... 137
9.3.4 Deliverables ......................................................................................................................... 137
9.3.5 Lab Work & Demonstration ................................................................................................. 137
9.3.5.1 Design the 24-Bit Counter and Selectable 2n Clock Divider ........................................................... 139
9.3.5.2 Take a Logic Analyzer Measurement of your Counter ................................................................... 141
9.3.5.3 Save a Copy of your top.vhd for your Records ............................................................................... 142
LAB 9.4: PRECISION CLOCK DIVIDER AND A BCD COUNTER ...................................................................... 143
9.4.1 Objective .............................................................................................................................. 143
9.4.2 Learning Outcomes ............................................................................................................. 143
9.4.3 Parts Needed....................................................................................................................... 143
9.4.4 Deliverables ......................................................................................................................... 143
9.4.5 Lab Work & Demonstration ................................................................................................. 143
9.4.5.1 Implement the Precision Clock Divider ........................................................................................... 145
9.4.5.2 Implement the 6-Digit BCD Counter ............................................................................................... 148
9.4.5.3 Save a Copy of your top.vhd for your Records ............................................................................... 149
10.2.5.4 Save a Copy of your top.vhd for your Records ........................................................................... 164
1
2 • Introduction
Parts List
The following parts are required to complete all of the lab exercises in this book. The breadboard and the discrete
parts are only used on lab exercises for chapters 1-7. The FPGA board starts to be used in Chapter 5. Chapters 8-13
only use the FPGA board and the Analog Discovery 2.
3
4 • Parts List
Lumex
LED, 7-Segment Opto/Components Digi-Key
1 Data Sheet
Display Inc. (67-1446-ND)
(LDS-C416RI)
CTS
Switch, slider, Digi-Key
1 Electrocomponents Data Sheet
SPST, 8-position (CT2088-ND)
(208-8)
Resistor Network,
Bourns Inc Digi-Key
1 8x, DIP, 330 Ohm, Data Sheet
(4116R-1-331LF) (4116R-1-331LF-ND)
Isolated
Jumper Wires,
MikroElektronika Digi-Key
1 Female-to-
(MIKROE-511) (1471-1230-ND)
Female, 10-Pack
Digi-Key
(P0192-ND) or
DE0-CV, Cyclone Terasic User
1
V, FPGA Board (P0192) Manual
Terasic
(P0192)
1.1.1 Objective
The objective of this lab is to become familiar with the equipment we will be using for the rest of the lab exercises
and also gain experience with the on/off nature of digital signals. We will use the Arbitrary Waveform Generator (AWG)
of the Analog Discovery to drive a simple LED circuit to turn it on and off. We will also use the oscilloscope function of
the Analog Discovery to view the AWG input and the voltage across the LED.
1.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate the use of the AWG to make an LED blink at 2 Hz (50% of exercise).
2. Produce an oscilloscope measurement of the LED circuit running at 5 MHz (50% of exercise).
Figure 1.1
Simple LED-Resistor Circuit
7
8 • Chapter 1: Analog vs. Digital
A breadboard provides a way to electrically connect circuit components without solder. The breadboard consists
of a series of holes designed to accept pins of standard digital logic parts and various switches and LEDs. Within the
breadboard are internal connections that allow components to be electrically connected by inserting pins within the
same hole set. Figure 1.2 shows an overview of the main connection scheme of a breadboard.
Figure 1.2
Overview of a Breadboard
For these lab exercises, it will be helpful if all of the vertical red lines are connected together and all of the vertical
blue lines are connected together. This can be accomplished by wiring each red vertical connection into one of the red
horizontal strips along the top and the same for the blue vertical connections. This will allow power to be provided to
the entire board by connecting it into any of the holes on red vertical strips and ground to be provided to the entire
board by connecting it to the any of the holes on the blue vertical strips. Enter wires into your breadboard to electrically
connect the vertical red/blue strips together as shown in Figure 1.3.
Figure 1.3
Setting up the Power/Ground Strips of the Breadboard
Lab 1.1: Introduction to Lab Equipment & Blinking an LED with the AWG • 9
The breadboard is now for ready to implement the LED-resistor circuit. The first step is to locate a 150 Ω, axial
resistor from your parts kit. The term axial means that the resistor resides on the same axis as the leads that are used
to connect to it. The colors on the resistor’s ceramic body indicate the value and tolerance of the resistor. Figure 1.4
shows an image of a 150 Ω axial resistor and a standard color code chart. The code uses one color for the first digit
of the resistor value and a second color for the second digit of the resistor value. This is then followed by a color
representing a multiplier to find the final value of the resistor. A 150 Ω resistor has a code of brown (1) – green (5) –
brown (101). This can be thought of as forming the number “15” using the first two colors and then multiplying it by “10”
to get 150. The final color on the resistor is the tolerance. All of the axial resistors in the parts kit are +/-5%, so all
tolerances are indicated with the color gold.
Figure 1.4
Determining the Value of an Axial Resistor (150 ohm example)
The next step is to locate the red LED from the parts kit and understand its polarity. The term polarity means that
the pins of a part have different functions and that the orientation of the part matters when it is placed into the
breadboard. An example of a part that is not polarized is the 150 Ω resistor discussed above. This part can be placed
in a circuit in any orientation and it behaves the same. This is not the case with an LED. For all of the circuits in this
lab manual, we will use LEDs in a forward-biased configuration. This simply means that the current will flow from the
anode to the cathode of the LED. When current flows in this direction, the LED will turn on. Current will not flow in
the opposite manner. What is important when using a discrete LED is to determine which pin is the anode and which
is the cathode. In the discrete LED in our parts kit, the anode is always the longer pin while the cathode is the shorter
pin. Figure 1.5 shows a graphical depiction of the polarity of discrete LED.
10 • Chapter 1: Analog vs. Digital
Figure 1.5
Determining the Anode and Cathode of the Discrete LEDs in our Parts Kit
Now that we have the two components for our circuit, we can insert them into the breadboard to form their electrical
connections. Figure 1.6 shows an example of how to breadboard this circuit.
Figure 1.6
Wiring the LED-Resistor Circuit
Now that the resistor and LED are in place, we can connect the AWG of the Analog Discovery. An AWG provides
an input signal to a circuit that can have a user-defined shape (i.e., square, sinusoid, triangle, etc.). The amplitude and
offset of the waveform can also be defined. The Analog Discovery has two AWG outputs (W1 and W2). We will be
using W1 in this exercise. The signal labels for the Analog Discovery are located on the plastic body near the main 30-
pin connector. This is shown in Figure 1.7.
Lab 1.1: Introduction to Lab Equipment & Blinking an LED with the AWG • 11
Figure 1.7
Pinout for the Analog Discovery 2
A wire kit is provided with the Analog Discovery that allows easy connections to external circuits. On one side of
the wire kit is the mating connector that plugs into the 30-pin connector on the Analog Discovery’s main body. On the
other end, each signal is brought out to a 0.1” square, female receptacle. This receptacle is ideal for interfacing to a
breadboard using either 0.1” header pins or simple breadboard wires. At this point, plug channel W1 into the
breadboard using a 0.1” header pin to make the input connection shown in Figure 1.1. All electrical circuits need a
ground¸ or a return path for the circuit to flow back to the source. The Analog Discovery has four ground signals in its
wire kit indicated with the ↓ symbol. At this point, also connect one of the grounds from the Analog Discovery to the
ground of the breadboard. Notice that since we setup our blue vertical strips to all be connected, we can plug in the
Analog Discovery’s ground anywhere on the breadboard. Figure 1.8 shows the connection of the Analog Discovery to
the breadboard containing the LED-resistor circuit. After these connections are made, we are ready to configure the
AWG output to drive the LED circuit to make it turn on and off.
Figure 1.8
Connection between the Analog Discovery and the LED-Resistor Circuit on the Breadboard
12 • Chapter 1: Analog vs. Digital
Launch Waveforms (Start –Digilent – Waveforms). The software will automatically recognize the Analog Discovery
and connect. The Waveforms startup window shown in Figure 1.9 will appear.
Figure 1.9
Waveforms 2015 Startup Window
The term “amplitude” refers to the amount that a signal swings above and below an “offset”. This means in order
to produce a signal that goes from 0v to +3.4v, we want to set the amplitude to +1.7v with an offset of +1.7v. This can
be thought of as a signal centered at 1.7v that will go above this center by +1.7v (i.e., 1.7v + 1.7v = 3.4v) and go below
this center by +1.7v (i.e., 1.7v - 1.7v = 0v). Set the following values for the Wavegen.
• Type = Square
• Frequency = 2 Hz
• Amplitude = 1.7 V
• Offset = 1.7 V
• Symmetry = 50%
• Phase = 0°
Your AWG setup should look like Figure 1.10. Note that the background can be changed from Dark to Light using
the setup gear button in the upper right corner of the waveform. You can also change the thickness of the line. Making
the background light and the line thicker makes taking and printing screenshots easier.
Lab 1.1: Introduction to Lab Equipment & Blinking an LED with the AWG • 13
Figure 1.10
Waveforms AWG Setup Window
At this point, you should save your workspace to your computer. Click on the menus “Workspace – Save”. Browse
to a location on your computer you wish to save your lab work and click “Save”. You can save the workspace continually
as you configure settings throughout this exercise.
Figure 1.11
Connection Points for the Oscilloscope Measurement
In order to make these connections, use 0.1” header strips to plug 1+ into the same breadboard strip as the AWG
input and 2+ to the same breadboard strip as the Anode of the LED. The 1- and 2- should be connected to the ground
of the breadboard. Figure 1.12 shows how the connection should look.
14 • Chapter 1: Analog vs. Digital
Figure 1.12
Connection between the Analog Discovery and the LED-Resistor Circuit on the Breadboard
• Offset = 0 V
• Range = 1 V/div
On the right side of the screen you’ll also see zoom controls for time. Again, both a scaling per division is given
(base) and a horizontal offset (position). Oscilloscope are usually used for signals that are fast enough that they can’t
be observed with the human eye. In this part, we will take a measurement on the LED-resistor circuit when it is running
at a faster frequency (1 kHz) so we need to configure the time zoom accordingly. Configure the time control to:
• Position = 0 s
• Base = 1 ms/div
When signals are too fast to be seen with the human eye, simply displaying what the oscilloscope is measuring on
the screen would result in the entire screen being lit up. To handle displaying fast repetitive signals, an oscilloscope
uses a trigger. A trigger represents an event that occurs on the incoming signal, such as a rising edge passing a certain
voltage level. When this occurs, the oscilloscope positions all of its recorded data on the screen with the trigger moment
located at time=0s. As the oscilloscope continues to run, it will continually trigger and overwrite the data on the screen
with the new set of data positioned with the trigger at time=0s. If the signal is repetitive, the resulting screen will show
a steady waveform in which the characteristics of the signal can be determined. We want to setup the trigger so that
every time Channel 1 has a rising transitions that passes through 2v, the oscilloscope will trigger. Along the top of the
measurement screen there are a variety of trigger settings. Configure these as follows:
• Mode = Auto
• Source = Channel 1
• Condition = Rising
• Level = 2 V
Run the Oscilloscope to Measure the Input and Output Voltages of the LED-Resistor Circuit
Now we are ready to take an oscilloscope measurement. First, we need to set the frequency of the AWG to 1 kHz
and turn it back on. Go back to the “Wavegen 1” tab, change the frequency to 1 kHz, and press the run button. Now
Lab 1.1: Introduction to Lab Equipment & Blinking an LED with the AWG • 15
go back to the “Scope 1” tab and press run. You will see the waveform in Figure 1.13. Again, the background and line
thickness of the oscilloscope measurement screen can be changed using the gear setup button in the upper right corner
of the screen.
Figure 1.13
Oscilloscope Measurement of 1 kHz Signals
Take a screenshot of your 5 MHz oscilloscope measurement for your records. In Windows you can do this using
either the Snipping Tool or by using the Print Screen button on your keyboard to place the screen on your clipboard
and then pasting it into Paint. Save the image in JPG format with a descriptive file name. This image satisfies the
requirements for deliverable #2.
CONCEPT CHECK
2.1.1 Objective
The objective of this lab is to demonstrate how logic signals can be interpreted as numbers. This lab will also allow
you to gain more familiarity with the arbitrary waveform generator and introduce logic analysis. You will drive two
square waves from the AWG into two LED circuits on your breadboard. You will configure the AWG outputs to drive a
2-bit binary counter pattern by adjusting the phase of the signals. You will then measure the LED signals using the
logic analyzer within the Analog Discovery. You will then view the 2-bit binary information in both binary and decimal
formats within the logic analyzer waveform.
• Use an arbitrary waveform generator to output a binary counter pattern by adjusting the phase of the
outputs.
• Use the logic analyzer to measure the digital values of a set of signals.
• View the logic analyzer measurement in different bases to see how the logic signals are interpreted as
numbers.
2.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate the use of the AWG to create a 2-bit binary counter displayed on two LEDs (50% of
exercise).
2. Produce a logic analyzer measurement displaying the counter value in both binary and decimal (50% of
exercise).
17
18 • Chapter 2: Number Systems
Figure 2.1
LED-Resistor Circuits to Display Binary Counter on LEDs
Figure 2.2 shows how the circuit will look after it is wired.
Figure 2.2
Wiring the Two LED-Resistor Circuits
Launch the Waveforms application. Click on the Wavegen button to bring up the AWG control window. In this
exercise we will be using both AWG channels of the Analog Discovery. By default, only Channel 1 appears when the
Wavegen tool is launched. In order to turn on Channel 2, use the “Channels” dropdown menu and select “2”. Once
this is selected, two waveform plots will appear. To the right of the “Channels” dropdown menu there is another menu
that controls whether the two signals are synchronized or unsynchronized. Choose “Synchronized” in this dropdown
menu. Now configure both waveforms with the following settings.
• Type = Square
• Amplitude = 1.7 V
• Offset = 1.7 V
• Symmetry = 50%
• Phase = 0°
We will use channel 1 (W1) to drive the LSB of the counter pattern. Set the frequency of Channel 1 to 1 Hz. We
will use channel 2 (W2) to drive the MSB of the counter pattern. Set the frequency of Channel 2 to 0.5 Hz.
The time zoom and time offset for both waveform images can be configured independent of each other. In order
to visualize the phase relationship between the two waveforms, we want to set both waveforms to be on the same time
scale. In the upper right corner of each waveform window, there are gear setup buttons. Use these buttons to configure
the time settings for both plots to the following.
• Scale = Manual
• Length = 0.2 s/div
• Start = 0.5 s
At this point we have the AWG configured nearly correct; however, the pattern that will be driven does not follow
a 00-01-10-11 counting pattern. Instead, you will see the pattern in Figure 2.3
Figure 2.3
AWG Setup to Drive a 2-Bit Counter, but with the Incorrect Phase Relationship
In order to get the correct pattern, we need to configure the phase of channel 2 to 90°. Make this change and you
will now see the pattern in Figure 2.4.
20 • Chapter 2: Number Systems
Figure 2.4
AWG Setup to Drive a 2-Bit Counter, but with the Correct Phase Relationship
We want to measure the logic values of the 2-bit counter that was implemented on the breadboard. The logic
channels of the Analog Discovery are labeled 0-15. Connect channels 0 and 1 of the logic analyzer to the LED-resistor
circuit as shown in Figure 2.5.
Lab 2.1: 2-Bit Binary Counter & Logic Analysis • 21
Figure 2.5
Connection Points for the Logic Analyzer to Measure the 2-Bit Counter
Figure 2.6 shows how the breadboard will look after connecting the logic analyzer.
Figure 2.6
Connecting the Logic Analyzer to the LED-Resistor Circuits
22 • Chapter 2: Number Systems
Figure 2.7
Logic Analyzer Bus Setup
Click the “Add” button to close the options window. In the logic waveform screen you’ll now see the Count bus in
addition to the individual bits of the bus.
Just as with an oscilloscope, a logic analyzer is typically used to measure signals that are faster than the human
eye can see. Go back to the Wavegen tab and increase the frequency of Channel 1 to 1 kHz and Channel 2 to 500
Hz. This will allow us to examine more data at once. Make sure the AWG is still running.
Figure 2.8
Logic Analyzer Measurement of 2-Bit Counter Displayed in Binary Format
Now change the format of the bus to interpret the 2-bits as a decimal number. Double click on the Count label and
the settings dialog will appear again. Change the format to decimal and press “OK”. You will now see the results as
shown in Figure 2.9.
Figure 2.9
Logic Analyzer Measurement of 2-Bit Counter Displayed in Decimal Format
24 • Chapter 2: Number Systems
The logic analyzer displaying the 2-bits in decimal is an example of how digital signals are representations of data
and as long as the receiving system knows how to interpret the representation, the data can be successfully transmitted.
In this case, the logic analyzer is set to treat the 2-bits as a positive decimal number. This is just one example of how
to interpret the data. Other coding schemes can be used to transmit information such as signed numbers, characters,
or other forms of data.
Take a screenshot of the logic analyzer measurement displaying the 2-bits in decimal format. Save the image in
JPG format with a descriptive file name. This image satisfies the requirements for deliverable #2.
CONCEPT CHECK
3.1.1 Objective
The objective of this lab is to demonstrate the DC and AC operation of digital circuits. This lab will also introduce
the power supply functionality of the Analog Discovery. You are going to breadboard three simple logic circuits from
the 74HC logic family (an inverter, an AND gate, and an OR gate). You will provide power to each of the gates using
the power supply output (+3.4v) of the Analog Discovery. You will then perform a series of activities to examine the
operation of the logic gates. First, you will determine the input/output specifications for the 74HC logic family by reading
a datasheet. Next, you will use the arbitrary waveform generator to drive in all possible input codes to the gates and
observe the input/output behavior of the gates using the logic analyzer. Next, you will observe the analog input/output
behavior of the inverter using the oscilloscope and examine the impact of an input signal that does not meet the DC
specifications of the receiving gate. Finally, you will measure the propagation delay and transition time of the inverter
using the oscilloscope.
• Read and understand the pin out, DC, and AC specifications of a basic gate from its data sheet.
• Breadboard basic gates from the 74HC logic family.
• Use the power supply output of the Analog Discovery to provide +3.4v to your breadboard.
• Measure the DC behavior of an inverter, AND gate, and OR gate using an AWG and logic analyzer.
• Measure the AC behavior of an inverter using the AWG and oscilloscope.
• Measure the impact of an input signal that does not meet the DC specifications of the receiving gate.
• Measure the switching characteristics of a basic gate using an AWG and an oscilloscope.
3.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Provide the operating specifications for a 74HC logic gate by reading its data sheet (5% of exercise).
2. Demonstrate the DC operation of a 74HC inverter, AND gate, and OR gate using the AWG and logic
analyzer (45% of exercise).
3. Demonstrate the AC operation of a 74HC inverter using the AWG and oscilloscope (15% of exercise).
4. Demonstrate the impact of an input signal not meeting the minimum input specifications of the 74HC
inverter (15% of exercise).
5. Measure the AC characteristics of the 74HC inverter (transition time and propagation delay) using the
AWG and oscilloscope (20% of exercise).
25
26 • Chapter 3: Digital Circuitry & Interfacing
being measured to the input of another gate on its same package to provide a typical load configuration (see the
following figure). You will connect the logic analyzer to the input(s) and output of each gate in turn in order to observe
the DC logic behavior. Figure 3.1 shows the breadboard setup and wiring diagram for the basic gate circuits.
Figure 3.1
Wiring Diagram for Breadboarding the Basic Gate Circuits
28 • Chapter 3: Digital Circuitry & Interfacing
Figure 3.2
Power Supply Setup
• Type = Square
• Frequency = 1 kHz
• Amplitude = 1.7 V
• Offset = 1.7 V
• Symmetry = 50%
• Phase = 0°
Press the “Run” button. You are now driving in a logic signal into the input of the inverter.
Lab 3.1: Digital Circuit Operation • 29
Figure 3.3
Logic Analyzer Measurement of the Inverter
At this point you have successfully wired an inverter, provided it power and ground, provided a logic input, and
measured its proper operation by observing the input and output. Take a screenshot of the logic analyzer measurement
for your records and save in a JPG format. This image partially satisfies the requirements for deliverable #2.
Setup and Run the Logic Analyzer Measurement on the AND Gate
You are now going to repeat this measurement on the AND gate. You first need to connect both channels of the
AWG to the inputs of the AND gate on pins 1 and 2. You should then configure the AWG to output a 2-bit counting
pattern (refer to lab 2.1 for how to setup the AWG to produce a counting pattern). You will next need to connect logic
analyzer channels 1 and 2 to the inputs of the AND gate and channel 3 to the output of the AND gate. Configure the
logic analyzer to have DI0 0 observe the channel 1 input, DI0 1 observe the channel 2 input, and DIO 2 observe the
output of the AND gate. Label DIO 0 “A”, DIO 1 “B”, and DIO2 “F”. Run the logic analyzer. You should see the
measurement shown in Figure 3.4.
30 • Chapter 3: Digital Circuitry & Interfacing
Figure 3.4
Logic Analyzer Measurement of the 2-Input AND Gate
At this point you have successfully wired a 2-input AND gate, provided it power and ground, provided logic inputs,
and measured its proper operation by observing the inputs and output. Take a screenshot of the logic analyzer
measurement for your records and save in a JPG format. This image partially satisfies the requirements for
deliverable #2.
Figure 3.5
Logic Analyzer Measurement of the 2-Input OR Gate
At this point you have successfully wired a 2-input OR gate, provided it power and ground, provided logic inputs,
and measured its proper operation by observing the inputs and output. Take a screenshot of the logic analyzer
measurement for your records and save in a JPG format. This image partially satisfies the requirements for
deliverable #2. To full satisfy deliverable #2 you will produce three images (INV, AND, OR).
Lab 3.1: Digital Circuit Operation • 31
• Mode: Auto
• Source: Channel 1
• Rising
• Level: 1.7 V
Press the “Run” button on the oscilloscope. You should now see the input and output signals for the inverter.
Zoom in horizontally by setting the time base to 0.2 ms/div. Zoom vertically by setting the range of both channels to 1
V/div. On the left of the screen, you can drag/drop the triangles for each channel to shift them up or down. Position
the waveforms so you can clearly see the input and output. You should see a measurement similar to Figure 3.6.
Figure 3.6
Oscilloscope Measurement of the Input and Output of the Inverter
This measurement shows the analog nature of the behavior of the inverter. Take a screenshot of the oscilloscope
measurement for your records and save in a JPG format. This image satisfies the requirements for deliverable #3.
Observing the Impact of an Input Signal that Doesn’t Meet the Minimum Specifications.
Now let’s observe the impact when the input does not meet the minimum input specifications that you determined
for the first deliverable of this lab. Let’s keep the input centered at +1.7v but begin shrinking its amplitude. Keep the
32 • Chapter 3: Digital Circuitry & Interfacing
oscilloscope measurement running while you reduce the amplitude of channel 1 of the AWG. Note that you can undock
a tool window in Waveforms by clicking the icon in the upper right corner of any window.
As you reduce the input signal amplitude, you’ll first notice that the output of the inverter remains a quality digital
signal for quite a while. It is only once the amplitude gets down to ~0.3 V does the output begin to show signs of failure.
You will begin to see the output pulses have different magnitudes and behave erratically. This can be seen in Figure
3.7. When the input amplitude is reduced further the output ultimately go to 0v.
Figure 3.7
Impact of an Input Signal Not Meeting the Minimum Specifications
Set the AWG amplitude back to the point where the output is exhibiting erratic behavior. Take a screenshot of the
measurement for your records and save in a JPG format. This image satisfies the requirements for deliverable #4.
Figure 3.8
Measurement of the AC Characteristics of the Inverter
The oscilloscope tool has a feature called “HotTrack”. This provides a cursor that automatically measures time
and voltage of the waveforms on the screen. To turn on HotTrack, click on the icon in the upper right corner of the
measurement section. The icon looks like a ruler. Once on, you’ll see a cursor that you can drag left and right and
view various time and voltage information about your measurement. Use HotTrack to determine the propagation delay
(i.e., the time difference between when the input and output cross the 50% point of their transition) and the transition
time (i.e., the time it takes the output to go from 10% to 90% of its logic swing). Note that HotTrack doesn’t automatically
produces these results. You will need to manually move the cursor to the specific points on the waveform, record the
time manually, and then perform a subtraction.
Take a screenshot of your oscilloscope measurement with HotTrack on for your records and save in a JPG format.
This image satisfies the requirements for deliverable #5.
CONCEPT CHECK
4.1.1 Objective
The objective of this lab is to gain experience with logic synthesis using canonical sum-of-products (SOP) and
canonical product-of-sums (POS) forms. You will design a 3-input prime number detector using both forms and
demonstrate the proper (and equivalent) operation. You will also gain experience with addressing fan-in constraints of
real logic circuits. You will also build an LED driver circuit that will allow you to drive in different codes into your detector
using switches and observe both the input and output logic values on LEDs.
• Implement an LED driver circuit that will be used to provide the inputs of your logic circuits.
• Design, breadboard, and test 3-input combinational logic circuits using a canonical SOP form?
• Design, breadboard, and test 3-input combinational logic circuits using a canonical POS form?
• Understand how fan-in constraints can be addressed in real-world circuits.
4.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate the proper operation of an LED driver circuit (30% of exercise).
2. Provide your design steps to synthesize a canonical SOP logic circuit to implement a 3-input prime
number detector (10% of exercise).
3. Demonstrate the proper operation of a 3-input prime number detector implemented with a canonical
SOP form (25% of exercise).
4. Provide your design steps to synthesize a canonical POS logic circuit to implement a 3-input prime
number detector (10% of exercise).
5. Demonstrate the proper operation of a 3-input prime number detector implemented with a canonical
POS form (25% of exercise).
35
36 • Chapter 4: Combinational Logic Design
Figure 4.1
LED Driver Circuit Schematic
Lab 4.1: 3-Input Prime Number Detector using Canonical Forms • 37
Figure 4.2
LED Driver Circuit Layout
Take a short video (<5 s) showing the proper operation of your LED driver circuit. This video satisfies the
requirements for deliverable #1.
• Create a 3-input truth table with the desired output for each input code.
• Create a minterm list from the truth table.
• Create a canonical SOP logic expression from the truth table / minterm list.
• Draw the logic diagram of the SOP logic expression.
• Map the logic operations into the available ICs in your parts kit.
• Address any fan-in issues you may have (HINT: You will have a fan-in issue when implementing the 4-
input OR operation).
• Redraw the final logic diagram that will be implemented on your breadboard.
38 • Chapter 4: Combinational Logic Design
Draw the Logic Diagram for the Canonical SOP Logic Expression
In the space provided below, draw the logic diagram for the canonical SOP logic expression for the 3-input prime
number detector. Your circuit should contain three inverters to generate A’, B’, and C’. Your circuit should contain 4x,
3-input AND operations to generate the 4x minterms in this circuit. Your circuit should contain 1x, 4-input OR operation
to generate the output of the circuit.
Lab 4.1: 3-Input Prime Number Detector using Canonical Forms • 39
Map the Logic Diagram for your SOP Circuit into Available ICs in your Kit
At this point you are now ready to begin thinking about how to implement your logic diagram in real circuitry. Each
of the gates in the above logic circuit will be implemented using real circuits from your parts kit. In this step you need
to think about which ICs will implement the logic operations. You are essentially mapping the operations into real
circuitry. This can be done by drawing rectangles around various operations that can be grouped into specific ICs.
First, you need 3x inversion operations. Note that your parts kit contains an HC04 IC, which has 6x inverters on
it. This means you can implement all three inversion operations on 1x HC04. Draw a rectangle around your 3x inverters
in your logic diagram and label the rectangle “HC04”. This rectangle represents how you will implement the inverters
on our breadboard.
The next step is to map the 4x, 3-input AND operations into ICs in your parts kit. Note that your parts kit contains
a 3-input AND gate in the form of the HC11 IC. The HC11 contains 3x, 3-input AND operations. This means you will
need 2x of the HC11 IC in order to implement all four of the AND operations in your circuit. Draw one rectangle around
the upper three AND operations and another rectangle around the lower AND operation. Label both rectangles “HC11”.
These rectangles represent how you will implement the AND operations on our breadboard.
Finally, you need to map the 4-input OR operation into ICs in your parts kit. Note that you do NOT have a 4-input
OR gate IC. The largest OR gate in your kit has 3-inputs. You have encountered a fan-in issue.
Figure 4.3
Prime Number Detector SOP Breadboard Layout
Draw the Logic Diagram for the Canonical POS Logic Expression
In the space provided below, draw the logic diagram for the canonical POS logic expression for the 3-input prime
number detector. Your circuit should contain three inverters to generate A’, B’, and C’. Your circuit should contain 4x,
3-input OR operations to generate the 4x maxterms in this circuit. Your circuit should contain 1x, 4-input AND operation
to generate the output of the circuit.
42 • Chapter 4: Combinational Logic Design
Map the Logic Diagram for your POS Circuit into Available ICs in your Kit
Now map the logic operations in your diagram into the parts that are available in your kit. For your inverters, you
can reuse the inverter IC from your SOP circuit. You will need to use 2x, HC4075 ICs to implement the 4x, 3-input OR
operations. For your final 4-input AND operation, your lab kit contains a 4-input AND IC (HC21) so you don’t have any
fan-in issues in your POS circuit. As before, draw rectangles around the logic operations to represent the ICs that will
be used to implement the gates. Label each rectangle with the IC part number.
Record your POS design process from above electronically. You should have all of your work on one page. If you
printed the page with your design steps and manually wrote in your steps, you can either scan the page or take a photo
of the page and save as a JPG. If you created the design electronically, take a screen shot of your design steps and
save in JPG format. This image satisfies the requirements for deliverable #4.
CONCEPT CHECK
4.2.1 Objective
The objective of this lab is to gain experience with logic synthesis using minimized sum-of-products (SOP) and
minimized product-of-sums (POS) topologies. You will design a 3-input prime number detector using both forms and
demonstrate their proper (and equivalent) operation. You will also gain experience with a circuit used to drive higher
current loads than a basic gate can provide (i.e., a buzzer).
• Design, breadboard, and test combinational logic circuits in both minimized SOP and POS forms.
• Implement a circuit to drive a buzzer with a logic signal as its control input.
4.2.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Provide your design steps to synthesize a minimized SOP logic circuit (10% of exercise).
2. Demonstrate the proper operation of a 3-input prime number detector implemented with a minimized
SOP form (30% of exercise).
3. Provide your design steps to synthesize a minimized POS logic circuit (10% of exercise).
4. Demonstrate the proper operation of a 3-input prime number detector implemented with a minimized
POS form (30% of exercise).
5. Demonstrate the proper operation of a buzzer driving circuit (20% of exercise).
• Create a 3-input truth table with the desired output for each input code.
• Use a K-map to drive a minimized SOP logic expression.
• Draw the logic diagram of the SOP logic expression.
• Map the logic operations into the available ICs in your parts kit.
44 • Chapter 4: Combinational Logic Design
Draw the Logic Diagram for the Minimized SOP Logic Expression
In the space provided below, draw the logic diagram for the minimized SOP logic expression for the 3-input prime
number detector.
Map the Logic Diagram for your SOP Circuit into Available ICs in your Parts Kit
In the above logic diagram, draw rectangles around the logic operations that can be implemented within a single
logic IC from your parts kit. Write the part number next to the rectangle.
Lab 4.2: 3-Input Prime Number Detector using Minimized Forms • 45
Record your SOP design process from above electronically. You should have all of your work on one page. If you
printed the page with your design steps and manually wrote in your steps, you can either scan the page or take a photo
of the page and save as a JPG. If you created the design electronically, take a screen shot of your design steps and
save in JPG format. This image satisfies the requirements for deliverable #1.
4.2.5.2 Implement a 3-Input Prime Number Detector using a Minimized SOP Form
Breadboard your Minimized SOP Circuit for the Prime Number Detector
You are now going to breadboard your minimized SOP circuit. You will drive in the 3-bit input codes using your
LED driver circuit. You will display your detector’s final output on the “F” LED of the driver circuit.
4.2.5.3 Design a 3-Input Prime Number Detector using a Minimized POS Form
You are now going to design a circuit that will implement the 3-input prime number detector, but this time using a
minimized POS approach. You will derive the minimized POS logic expression using a K-map. The steps in this design
process are as follows:
• Create a 3-input truth table with the desired output for each input code.
• Use a K-map to drive a minimized POS logic expression.
• Draw the logic diagram of the POS logic expression.
• Map the logic operations into the available ICs in your parts kit.
Draw the Logic Diagram for the Minimized POS Logic Expression
In the space provided below, draw the logic diagram for the minimized POS logic expression for the 3-input prime
number detector.
Map the Logic Diagram for your POS Circuit into Available ICs in your Parts Kit
In the above logic diagram, draw rectangles around the logic operations that can be implemented within a single
logic IC from your parts kit. Write the part number next to the rectangle.
Record your POS design process from above electronically. You should have all of your work on one page. If you
printed the page with your design steps and manually wrote in your steps, you can either scan the page or take a photo
of the page and save as a JPG. If you created the design electronically, take a screen shot of your design steps and
save in JPG format. This image satisfies the requirements for deliverable #3.
4.2.5.4 Implement a 3-Input Prime Number Detector using a Minimized POS Form
Breadboard your Minimized POS Circuit for the Prime Number Detector
You are now going to breadboard your minimized POS circuit. You will drive in the 3-bit input codes using your
LED driver circuit. You will display your detector’s final output on the “F” LED of the driver circuit.
Figure 4.4
Schematic of Interfacing Circuit for a Magnetic Buzzer
The 2N3904 is an NPN transistor. This transistor can be thought of as a switch with a control signal. When we
provide a high voltage to its control input (the BASE), it will close the switch, allowing current to flow between the other
two terminals (the COLLECTOR & EMITTER terminals). The control signal takes very little current so we can drive it
directly from a 74HC gate. The advantage of using this transistor is that the current between the collector and emitter
terminals can be very high (200mA max). This allows us to use a 74HC gate to drive a device that pulls more current
than the 74HC can provide. The diode in this circuit is used to sink the remaining current in the buzzer when it is turned
off. Since the buzzer is magnetic, it acts like an inductor. When we turn it off, the current can’t stop flowing
instantaneously. The diode provides a path for the current to flow when it switches off instead of forcing it into the NPN
transistor, which will cause damage. The 10kohm resistor is used to limit the current that flows into the NPN transistor.
Keep the protective tape on the buzzer or it will be LOUD!
Figure 4.5
Layout of Interfacing Circuit for a Magnetic Buzzer
CONCEPT CHECK
4.3.1 Objective
The objective of this lab is to gain additional experience with logic synthesis using minimized SOP/POS forms and
logic manipulation using DeMorgan’s Theorem. You will be designing a 3-input, 7-segment display decoder and
demonstrating its proper operation.
4.3.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Provide your design steps to synthesize the minimized SOP/POS logic expressions for the 7-segment
decoder circuitry (10% of exercise).
2. Provide your steps to manipulate at least one logic expression using DeMorgan’s Theorem to
implement the expression using only NAND or NOR gates (10% of exercise).
3. Demonstrate the proper operation of your 7-segment decoder circuit implemented on your breadboard
(80% of exercise).
Figure 4.6
7-Segment Display Pinout, Schematic, and Use-Model
The first step in designing the decoder logic is to build a truth table for each of the seven circuits that will drive the
display. Figure 4.7 illustrates how to derive the truth tables for the decoder. Each of the seven LEDs are labeled a, b
c, d, e, f and g. For each input code, you will enter a 1 in the row of the following table if the individual LED needs to
be ON to display the corresponding decimal character. For example, the input code A=0, B=0, C=0 corresponds to a
display character of “0”. To create this character, you turn on all LEDs within the display except for “g”. In the table
you would go to the row corresponding to input codes A=0, B=0, C=0 and enter Fa=1, Fb=1, Fc=1, Fd=1, Fe=1, Fde=1,
and Fg=0. Once you have completed the table for all input codes, logic expressions can be derived for each column.
The column values for Fa have been provided to get you started. The first part of deliverable #1 is to complete the truth
table in Figure 4.7.
Lab 4.3: 7-Segment Display Decoder (Discrete) • 51
Figure 4.7
Truth Table for 7-Segment Display Decoder
Record your table and logic expressions from above electronically. This should consist of two pages, one for the
truth table and one with your seven logic expressions. If you printed the pages and completed them manually, you can
either scan the pages or take photos of the pages and save as a JPG. If you completed the design electronically, take
a screen shot of your design steps and save in JPG format. These image satisfies the requirements for deliverable
#1.
4.3.5.2 Use DeMorgan’s Theorem to Manipulate at Least One of the Logic Expressions
Now you are going to begin mapping the logic expressions into the logic gates in your parts kit. As you go through
this process, you will quickly realize that you do not have enough AND gates and OR gates to implement all seven
logic expressions in their derived SOP/POS forms. You will need to manipulate some (or all) of your logic expressions
using DeMorgan’s Theorem into forms that use NAND gates and NOR gates. Your lab kits does contain a variety of
n-input NAND/NOR gates that will allow you to complete the implementation. For this deliverable, show your use of
DeMorgan’s to manipulate at least one of your logic expressions from above. Record your logic manipulation
electronically. This image satisfies the requirements for deliverable #2.
CONCEPT CHECK
5.1.1 Objective
The objective of this lab is to gain experience designing combinational logic using a hardware description language
and implementing the circuitry using the modern digital design flow. In this lab you will design a 4-input prime number
detector in VHDL and then use the Quartus toolchain to synthesize and implement your circuit on a common
programmable logic device, the field programmable gate array (FPGA). You will also gain experience on how to
interface an FPGA board to your breadboard.
• Use the Quartus toolchain to synthesize, technology map, place/route and implement a VHDL model on
an FPGA.
• Interface an external FPGA board to your breadboard.
5.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a VHDL design on an FPGA that drives the DE0-CV slider switches to the DE0-CV LEDs
(50% of exercise).
2. Demonstrate a 4-input prime number detector in VHDL on an FPGA (40% of exercise).
3. Provide your top.vhd design file (10% of exercise).
55
56 • Chapter 5: VHDL (part 1)
output displayed on an LED on your breadboard. We will also drive the buzzer on the breadboard to provide audible
feedback. Figure 5.1 shows the block diagram for this lab exercise.
Figure 5.1
Block Diagram of the 4-Input Prime Number Detector System
Figure 5.2 shows the final implementation of the prime number detector. Note that the DE0-CV board is connected
to the breadboard using jumper wires. The jumper wires are used to connect power (+3.4v) and ground between the
boards and routes the output of the detector (Prime) to the breadboard LED and buzzer. Don’t connect the DE0-CV
to your bread board yet. You will first get the DE0-CV working and then make the connection in a later step.
Figure 5.2
Picture of the 4-Input Prime Number Detector System on the DE0-CV Board + Breadboard Interface
5.1.5.1 Implement a VHDL Design that will Drive the Switches to the LEDs on the DE0-CV Board
We first want to create a simple design that will drive the lower four slider switches on the DE0-CV board (labeled
SW3, SW2, SW1 and SW0) to the red LEDs on the DE0-CV board (labeled LEDR3, LEDR2, LEDR1 and LEDR0). In
this portion of the lab exercise we will create a new Quartus project, create the VHDL to accomplish driving the switch
Lab 5.1: 4-Input Prime Number Detector in VHDL • 57
values to the LEDs, assign the pins of the FPGA to the I/O we are using, and synthesize the design. Once we download
our design to the FPGA we will be able to test the first part of this exercise. This will ensure that the Quartus software
is installed correctly, including the drivers for the DE0-CV board, and that the pins are assigned correctly before moving
onto the next parts. You should not connect the DE0-CV board to your breadboard in this step.
Install the Quartus Lite Software (if not already installed on your computer)
The Quartus Lite software can be downloaded for free from www.altera.com. This will take you to an intel website,
which purchased Altera Inc. in 2016. Once on this page, click on “Support” and then “Downloads”. You will need to
create a free account. There you’ll be given the option of downloading various versions of Quartus. You want to
download the “Lite” version. Click on the “Download” icon next to the Lite version. In the next screen you’ll be given
options on what all should be downloaded. You want to select three items:
Then click “Download Selected Files”. It will ask you where to download the files. Choose your Desktop and select
“OK”. It will then proceed to download three files. The files are large so it will take a while. Once they are downloaded
to your desktop, double click on the Quartus install file (named something similar to “QuartusLiteSetup-17.0.0.595-
windows.exe”). This will automatically install the ModelSim software and the Cyclone V drivers that you downloaded
as long as they are in the same location (i.e., the Desktop). Accept the defaults for all options in the install.
When complete, it will ask if you want to install desktop icons, launch Quartus, and/or launch the driver install tool.
Select the option to launch the driver install tool. Follow the instructions to install the drivers for the DE0-CV board.
When you plug in the DE0-CV board in the next few steps, the driver installation will complete.
Create a Folder for to Hold All of your VHDL Projects (if not already created)
For each Quartus project, you will manually create a folder and then direct Quartus to put all design files into that
directory. We want to first create a main folder that will hold all of the project folders that will be created throughout this
manual to help us stay organized. We will create a folder on the Desktop called “Logic_Lab”. Right click on the Desktop
of your computer and select “New Folder”. Give it the name “Logic_Lab”.
Launch Quartus
On a windows 10 or equivalent machine, the Quartus application can be launched at: Start Intel FPGA version
Lite Edition Quartus (Quartus Prime version). Figure 5.3 shows the Quartus startup window that will appear.
58 • Chapter 5: VHDL (part 1)
Figure 5.3
Quartus Startup Window
Figure 5.4
Quartus New Project Wizard (Introduction)
Click on “Next” to go the next window. If you don’t want the introduction window to show up next time you run New
Project Window, you can check the box. The Directory, Name, Top-Level Entity window shown in Figure 5.5 will appear.
Lab 5.1: 4-Input Prime Number Detector in VHDL • 59
Figure 5.5
Quartus New Project Wizard (Directory, Name, Top-Level Entity)
For the working directory, click on the “…” button and browse to the “Logic_Lab/Lab_05p1_PrimeNumDet” folder
you created on your desktop. This project folder will contain all of the Quartus design files.
For the name of the project, enter “Lab_05p1_PrimeNumDet”. Note that as you type this name, Quartus
automatically enters the same name for the top-level entity. You do not want to use this name as your top-level
entity.
For the top-level design entity, enter “top”. The term top is the standard naming convention for the VHDL file that
is at the highest level of hierarchy in the system. At the top level, the ports of the entity will be the physical pins of the
device. For this exercise, we will only have one top-level file. We will create this file (top.vhd) in a later step.
Click on the “Next” button. The Project Type window shown in Figure 5.6 will appear.
Figure 5.6
Quartus New Project Wizard (Project Type)
Leave the project type as “Empty” and click “Next”. The Add Files window shown in Figure 5.7 will appear.
60 • Chapter 5: VHDL (part 1)
Figure 5.7
Quartus New Project Wizard (Add Files)
This window is where we can add existing design files. For this exercise we do not have any existing design files.
Instead, we will be creating a new file called top.vhd. We will do this later outside of the New Project Wizard. Do not
do anything in this window except click “Next”. The Family, Device & Board Settings window shown in Figure 5.8 will
appear.
Figure 5.8
Quartus New Project Wizard (Family, Device & Board Settings)
In this window we tell the Quartus synthesizer which device we will be targeting. Since we only installed the
Cyclone V FPGA family, only those devices will be shown. Notice that there are many different Cyclone V devices that
can be selected. We want to select the FPGA device that is on our DE0-CV board. We can begin filtering down the
selection by typing in the “Name filter” field on the right side of the pain. Begin typing 5CEBA4F23C7. After each
character is typed, it will reduce the number of devices that are available. Once you type the last character, there will
only be one device available. Highlight this device and click “Next”. The EDA Tool Settings window shown in Figure
5.9 will appear.
Lab 5.1: 4-Input Prime Number Detector in VHDL • 61
Figure 5.9
Quartus New Project Wizard (EDA Tool Settings)
In this window you can direct Quartus to read files from various CAD tools from other vendors. For this exercise,
we will be using the Quartus tool by itself. Leave all the settings at <None> and click “Next”. The Summary window
shown in Figure 5.10 will appear.
Figure 5.10
Quartus New Project Wizard (Summary)
Review the settings in this window and if correct, click “Finish”. If any of the settings are incorrect, you can click
the “Back” button to go back and change them. You will now see a new blank project window with all of your settings
as shown in Figure 5.11.
62 • Chapter 5: VHDL (part 1)
Figure 5.11
New Blank Project for the Cyclone V on the DE0-CV FPGA Board
• SW (3 downto 0) This is the 4-bit input vector for the 4x slider switches on the DE0-CV board.
• LEDR (3 downto 0) This is the 4-bit output vector for the 4x red LEDs on the DE0-CV board.
• Prime This is the output will go to pin 2 on the GPIO_1 connector and jumper-wired to
your breadboard.
Enter the following VHDL entity into your top.vhd. Notice that the entity name matches the file name in addition to
the name of the top-level of the design in Quartus. This tells Quartus that any ports that are declared will be connected
to pins on the FPGA board.
entity top is
port (SW : in bit_vector (3 downto 0);
LEDR : out bit_vector (3 downto 0);
Prime : out bit);
end entity;
At this point your project should look like Figure 5.12. Notice that Quartus recognizes the VHDL syntax and will
color code based on the construct type.
Lab 5.1: 4-Input Prime Number Detector in VHDL • 63
Figure 5.12
VHDL Entity for Prime Number Detector
begin
end architecture;
Save your file using the pull-down menus File Save. At this point, your project should look like Figure 5.13.
Figure 5.13
VHDL Architecture for Switch-to-LED Circuit
“Compile Design” there are a handful of other tasks (i.e., Analysis & Synthesis, Fitter, etc.). When you click on “Compile
Design”, Quartus will run all of the lower-level tasks. If it encounters an error, it will stop at the task where the error
was found. If the task completes successfully, it will turn green. We typically allow Quartus to run as many tasks as it
can when we compile to attempt full synthesis of the design. To launch the compiler and synthesizer, double click on
“Compile Design”. This will take longer than a simple syntax check as Quartus is performing synthesis. The status of
the task will appear in the Messages window at the bottom of the pane. You will also see a status bar for each of the
tasks being performed. Once you have fixed any errors that have occurred and successfully completed the Compile
Design tasks, you will see the status in Figure 5.14.
Figure 5.14
Quartus Window After Successful Compile and Synthesis
• LED[3] PIN_Y3
• LED[2] PIN_W2
• LED[1] PIN_AA1
• LED[0] PIN_AA2
• Prime PIN_A12
• SW[3] PIN_T12
• SW[2] PIN_T13
• SW[1] PIN_V13
• SW[0] PIN_U13
Also change the “I/O Standard” setting for the output ports to “3.3-LVCMOS” and the “Current Strength” setting to
“Maximum” for Prime. Once you are complete, you should see the results in Figure 5.15.
Lab 5.1: 4-Input Prime Number Detector in VHDL • 65
Figure 5.15
Quartus Pin Planner for the Prime Number Detector
Pin Planner does not have a save option. Instead, you simply close it using the drop-down menus: File – Close.
Back in Quartus you’ll notice that the tasks are no longer green. This indicates that the design needs to be compiled
and synthesized again to take the new pin assignments into account. Double click on “Compile Design” and let it run
until all tasks have been completed successfully.
If the programmer does not automatically find the device, you can press the “Auto Detect” button on the left of the
programmer window. Once it finds the device, you need to assign the top.sof file. Highlight the device, right-click, and
select “Add File”. Browse to the output_files folder and select top.sof.
When using the programmer for the first time, it may say “No Hardware” next to the hardware setup button. This
means that the programmer is not using the correct drivers for the DE0-CV board. Click on the “Hardware Setup”
button. For the “Currently Selected Hardware”, use the drop-down menus to select “USB-Blaster [USB-x]”. Click
“Close”. Now the programmer will use the proper drivers to communicate with the DE0-CV board.
At this point we are ready to download the top.sof file to the FPGA in order to program it. Click on the “Start” button
on the left side of the programmer window. The status of the programming will be displayed in the status bar in the
upper-right corner of the window. When successful, it will say “100% (Successful)”.
Test your Design to Drive the Switches to the LEDs of the DE0-CV
Your design is now on the FPGA. You should be able to toggle the four slider switches on the DE0-CV and see
the red LEDs turn on/off accordingly. If you are experiencing issues, you will need to go back and check each step in
the Quartus design flow. The first place to start is in pin planner. Sometimes the pin locations will get dropped if you
are still in edit mode when you close the pin planner window. Take a short video (<3 s) showing the proper operation
of your switch-to-LED design. You should toggle through each of the four slider switches and verify that each red LED
turns on. This video satisfies the requirements for deliverable #1.
Enter the VHDL for the detector in your top.vhd file in Quartus. You can choose whichever modeling method you’d
like (i.e., conditional or selected). You’ll need to complete the signal assignments given in the examples above for each
input condition. Note that the above syntax uses single apostrophes and not the back ticks. If you try to copy/paste
the above syntax directly into Quartus, it may paste incorrectly.
After you are done, close your project using the pull-down menus: File Close Project. Exit Quartus using the
pull-down menus: File Exit.
CONCEPT CHECK
6.1.1 Objective
The objective of this lab is to gain further experience with implementing combinational logic circuits using hardware
description languages, implementing the systems on programmable logic devices, and interfacing two digital systems
together. This lab will also demonstrate how to create a new Quartus project by copying a prior project so that design
components can be reused.
• Create a new Quartus project by copying your prime number detector project from lab 5.1 so that you
can reuse components of its design.
• Create a 4-input, 7-segment display decoder (016 to F16) on an FPGA using VHDL.
6.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a 4-input, 7-segment display decoder + 4-input prime number detector implemented with
VHDL on an FPGA (90% of exercise).
2. Provide your top.vhd design file (10% of exercise).
69
70 • Chapter 6: MSI Logic
Figure 6.1
Block Diagram of the 7-Segment Decoder System
Figure 6.2
Picture of the 7-Segment Decoder System on the DE0-CV Board + Breadboard Interface
Lab 6.1: 4-Input, 7-Segment Decoder in VHDL • 71
Figure 6.3
Truth Table for 4-input, 7-Segment Display Logic
72 • Chapter 6: MSI Logic
Create a New Quartus Project by Copying your Prior Prime Number Project
In lab 5.1, we created a Quartus project for a 4-input prime number detector. We want to reuse many of the design
aspects of this prior project including the FPGA selection, the logic to drive the slider switches to the LEDs, and the pin
assignments for the slider switches and LEDs. Quartus provides the ability to create a new project by copying over a
prior one.
Launch Quartus and then open your project for lab 5.1 using the pull-down menus: File Open Project. You’ll
want to browse to the project file at: “Desktop\Logic_Lab\Lab_05p1_PrimeNumDet/Lab_05p1_PrimeNumDet.qpf” and
select “Open”.
Now you can copy the open project to a new project using the pull-down menus: Project – Copy Project. The Copy
Project window allows you to give the new project a different name and create a folder for its location at the same time.
Give the name of the project and folder “Lab_06p1_SevenSegDecoder”. Also check the box to open the project. Your
Copy Project settings window should look like Figure 6.4.
Figure 6.4
Quartus Copy Project Settings
Click “OK” to copy the project. Quartus will prompt you to verify that you want a new folder created for this project.
Click “Yes”.
• SevenSeg(6 downto 0) This is a 7-bit vector that will drive the individual LEDs on the 7-segment
display. The MSB of this vector will correspond to the “a” LED while the
LSB of this vector will correspond to the “g” LED.
Update the VHDL entity to reflect the new output port SevenSeg(6 downto 0). Figure 6.5 shows how the entity
should look.
Figure 6.5
VHDL Entity for 7-Segment Decoder
Lab 6.1: 4-Input, 7-Segment Decoder in VHDL • 73
Enter the Functionality for the 7-Segment Decoder to the VHDL Architecture
Now you will enter the functionality for the 7-segment decoder. Leave all of the VHDL functionality from lab 5.1 in
your architecture. You can enter the functionality for the 7-segment decoder directly from the table in Figure 6.3. You
can use either a conditional or selected signal assignment to model the decoder. Consider the following two code
examples to get you started.
Example of a conditional signal assignment:
SevenSeg <= “1111110” when (SW = “0000”) else
“0110000” when (SW = “0001”) else
“1101101” when (SW = “0010”) else -- remaining functionality goes below…
After completing your model for the 7-segment display, save your design and perform a “Compile All”. Fix any
syntax errors you may have and repeat compiling until all of the tasks complete 100%.
• Prime PIN_J11
• SevenSeg[6] PIN_A12
• SevenSeg[5] PIN_B12
• SevenSeg[4] PIN_B13
• SevenSeg[3] PIN_D13
• SevenSeg[2] PIN_G17
• SevenSeg[1] PIN_J18
• SevenSeg[0] PIN_G11
Also change the “I/O Standard” settings for the output ports to “3.3-LVCMOS” and the “Current Strength” settings
to “Maximum” for Prime and SevenSeg. When complete, your assignments should look like the settings in Figure 6.6.
74 • Chapter 6: MSI Logic
Figure 6.6
Pin Assignments for 7-Segment Decoder
Close the Pin Planner tool using the pull-down menus: File Close. Recompile your design with the new pin
assignments using the “Compile All” task.
• If an LED segment in your display is not lighting up, ensure it is wired correctly. You can do this by
taking the wire that is to be attached to the FPGA pin and instead plug it into the power rail of your
breadboard. This will drive the LED directly and ensure that you have the resistor and character display
pin correctly wired.
Lab 6.1: 4-Input, 7-Segment Decoder in VHDL • 75
• If an LED segment still doesn’t light up, check pin planner in Quartus.
Take a short video (<5 s) showing the proper operation of your 7-segment display decoder. You should show that
the correct character is displayed for the corresponding input code on the slider switches. You should also show that
the LED and buzzer on your breadboard assert for each prime number on the input. This video satisfies the
requirements for deliverable #1.
When you are done, close your project using the pull-down menus: File Close Project. Exit Quartus using the
pull-down menus: File Exit.
CONCEPT CHECK
7.1.1 Objective
The objective of this lab is to introduce discrete sequential logic circuits. This lab will cover the design of a ripple
counter using discrete D-flip-flops. This lab will then examine the behavior of mechanical switches and introduce
debounce circuitry that helps provide clean edges from a switch by taking advantage of the storage capability of an
S’R’ latch.
7.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a 4-bit ripple counter implemented with discrete D-flip-flops. The counter will be clocked
by the AWG and the outputs will be observed on LEDs. (40% of exercise).
2. Take a logic analyzer measurement of the 4-bit ripple counter (20% of exercise).
3. Demonstrate the break-before-make and contact bounce behavior found in mechanical switches. You
will clock your counter using a simple push button switch and observe the unclean clock edges into your
counter using a single-shot measurement on the oscilloscope. (20% of exercise).
4. Demonstrate a NAND-debounce circuit that produces clean logic transitions for the clock of your ripple
counter. This will be implemented on your push button switch and observed using a single-shot
measurement on the oscilloscope (20%of exercise).
77
78 • Chapter 7: Sequential Logic
binary counter and can be scaled to whatever size is desired by adding more D-flip-flops. Figure 7.1 shows the logic
diagram of a 4-bit ripple counter.
Figure 7.1
Logic Diagram of a 4-bit Ripple Counter Created with Discrete D-flip-flops
Connect the power and GND of the Analog Discovery to the power and ground rails of your breadboard. Also
connect the AWG channel 1 (W1) of the Analog Discovery to the clock input of the ripple counter. Finally, connect
logic channels 0, 1, 2, and 3 to the outputs of the ripple counter. Your connection should look like Figure 7.2.
Figure 7.2
Breadboard Connections for the 4-Bit Ripple Counter
Lab 7.1: Ripple Counter and Switch Debouncing • 79
Next, configure channel 1 of the AWG to output a square wave with the following settings:
• Type = Square
• Frequency = 4 Hz
• Amplitude = 1.7 V
• Offset = 1.7 V
• Symmetry = 50%
• Phase = 0°
Enable the AWG by pressing the “Run” button.
Figure 7.3
Logic Analyzer Measurement of 4-Bit Ripple Counter
Take a screenshot of the logic analyzer measurement of the ripple counter. Save the image in JPG format with a
descriptive file name. This image satisfies the requirements for deliverable #2.
transitions. These include the break-before-make characteristic of a SPDT switch and bounce associated with the
mechanical contact within the part. Refer to the section on switch bounce in Chapter 7 of the textbook describing these
issues. In this part of the lab exercise, we will observe these issues with an oscilloscope.
Figure 7.4
Generating a Clock Directly from a Mechanical Switch
Clock your Ripple Counter with the “Bad” Clock Generation Circuit
Breadboard the bad clock generation circuit in Figure 7.4 and drive the input clock of your 4-bit ripple counter with
it. You will need to first disconnect the AWG. In waveforms, turn off the AWG and then disconnect it from your
breadboard. Connect oscilloscope channel 1+ of the Analog Discovery to the clock signal being generated by your
switch circuit. Connect the channel 1 reference (1-) to the ground rail of your breadboard. Your connection will look
like Figure 7.5.
Figure 7.5
Breadboard Connections for the Mechanical Switch Clock Generator
You should now be able to press the switch and see your ripple counter change patterns. Notice that it will not
always increment by 1 on every press. Instead, it may jump 2 or 3 counts per press. This is because the switch is not
producing a clean clock edge. The break-before-make behavior and bouncing of the contact can cause multiple clock
edges to be produced for each press.
• Position = 0 s
• Base = 0.5 us/div
Configure the Channel 1 settings to position the waveform in the middle of the screen vertically as follows:
• Offset = -1.5 V
• Range = 0.5 V/div
Now configure the trigger to take a single shot measurement. This type of measurement will only acquire data
when it sees the trigger condition. Once the trigger condition is observed, the oscilloscope will fill the screen with data
and then stop. This allows you to measure events that are not periodic or that occur infrequently. The trigger settings
for the scope tool are along the top of the measurement screen. Configure these as follows:
• Mode = Normal
• Source = Channel 1
• Condition = Rising
• Level = 1.7 V
Now press the “Single” button. You will see the status of the oscilloscope is now Armed and waiting for the trigger.
Once you press the switch on your breadboard, the oscilloscope will see the rising edge, trigger, fill the screen with
data, stop, and display its status as Done. Press the switch and observe the waveform. You should repeat this
measurement (i.e., press “Single”, then press the switch) until you get a rising edge that exhibits both the break-before-
make behavior and switch bounce. An example measurement showing both behaviors is shown in Figure 7.6.
Figure 7.6
Oscilloscope Measurement of Switch showing Break-Before-Make and Bouncing Behaviors
Take a screenshot of the oscilloscope measurement of your switch output. Save the image in JPG format with a
descriptive file name. This image satisfies the requirements for deliverable #3.
initial issue observed in Figure 7.7 as the output will hold a zero when the switch contact enters the no-contact portion
of the transition. This circuit also handles the final issue observed in Figure 7.7 because once the switch contacts VCC,
it will then bounce between VCC and open. The NAND-debounce circuit will hold a one in this situation as the switch
contact bounces between VCC and no-contact.
Figure 7.7
NAND-Debounce Circuit for SPDT Mechanical Switches
Breadboard the circuit in Figure 7.7 and use its output to drive your ripple counter. Repeat the single-shot
oscilloscope measurement to observe the new clean clock edge. Your clock edge will now look similar to Figure 7.8.
Figure 7.8
Oscilloscope Measurement of Debounced Switch Output
Take a screenshot of the oscilloscope measurement of your debounced switch output. Save the image in JPG
format with a descriptive file name. This image satisfies the requirements for deliverable #4.
Lab 7.1: Ripple Counter and Switch Debouncing • 83
CONCEPT CHECK
7.2.1 Objective
The objective of this lab is to gain experience implementing finite state machines using discrete parts. You will
design and implement a 3-bit binary up/down counter.
• Design and implement a 3-bit binary up/down counter using discrete parts.
• Use a push button circuit to provide the reset to your counter.
7.2.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Provide a final logic diagram for the 3-bit counter (10% of exercise).
2. Demonstrate a 3-bit binary up/down counter FSM with discrete components. The counter will be
clocked by the AWG, the outputs will be observed on LEDs, and the reset will be provided by a SPDT
switch. (90% of exercise). If you are unable to get a 3-bit counter working, you can implement a 2-bit
binary up/down counter that is worth 60%.
• Your breadboard will be provided power and ground from the Analog Discovery. Connect the Analog
Discovery’s power and GND to the power rails of your breadboard. When you are ready to test your
design, you will need to configure the power supply in Waveforms to output +3.4 v and enable.
• Your counter will receive its clock from the AWG of the Analog Discovery. You should connect channel
1 (W1) of the Analog Discovery’s AWG to the clock inputs of your counter. Remember that all three D-
flip-flops need to receive the same clock. When you are ready to test your design, you will need to
configure the AWG to output a 4 Hz square wave with an amplitude of +1.7 v and an offset of +1.7 v.
• Your “Up” input will come from one of the slider switches in your LED driver circuit. You can access the
switch output by adding a wire to the node where one of the paths connects to the 10 kΩ pull-down
resistor. The Up is used in your next state logic circuits.
• You will need to create a reset line for your D-flip-flops using your push button SPDT switch. You do
not need to debounce the switch. You will simply have it drive a logic 1 to all resets in your counter (i.e.,
reset is deasserted) when the switch is not pressed. When the switch is pressed, it should drive a logic
0 to all resets in your counter (i.e., reset is asserted) to put the FSM into its reset state.
• You will drive the 3-bit output of your FSM (Count) to three discrete red LEDs. Each of the LEDs will be
connected in series with a 150 Ω resistor. The cathode of the LED should be connected to ground.
Take a short video (<5 s) showing the proper operation of your counter. You should show that you can reset the
FSM and also change the direction of the counter output. This video satisfies the requirements for deliverable #2.
CONCEPT CHECK
Lab 7.3: 4-Bit Binary Up/Down Counter Finite State Machine (in VHDL)
7.3.1 Objective
The objective of this lab is to gain experience designing finite state machines using VHDL. The state machine will
implement a 4-bit binary, up/down counter using a combination of structural VHDL and concurrent signal assignments.
The counter will be implemented on an FPGA where its output will be displayed on LEDs in addition to serving as inputs
to the 7-segment decoder and prime number detector from prior labs.
• Design a finite state machine using a combination of structural VHDL for the state memory and
concurrent signal assignments for the next state and output logic.
• Instantiate a pre-designed VHDL file into a Quartus project to be instantiated as a component
(dflipflop.vhd).
7.3.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a finite state machine implemented in VHDL to create a 4-bit, binary, up/down counter.
The counter will be displayed on red LEDs of the DE0-CV board in addition to drive the inputs to a 7-
segment display decoder + 4-input prime number detector (90% of exercise).
2. Provide your top.vhd design file (10% of exercise).
Figure 7.9
Block Diagram of the 4-Bit Binary, Up/Down Counter System
Figure 7.10
Picture of the 4-Bit Binary, Up/Down Counter System on the DE0-CV Board + Breadboard Interface
Figure 7.11
State Transition / Output Table for the 4-Bit Counter FSM
Project – Copy Project. You should name the folder and project “Lab_07p3_4bit_Cnt_FSM”. After clicking “OK”, make
sure to verify that you want to create the new folder for this project.
Figure 7.12
Adding Files to a Project in Quartus
Click on the browse button (the “…”) and browse to the dflipflop.vhd file in your project directory. Select the file
and press “Open”. The dflipflop.vhd file will be added to your project. You need to move it down so that top.vhd is
above it in the list, indicating that top is still the highest level in the hierarchy. Highlight the dflipflop.vhd file, and press
the “Down” button the right. Once your settings are identical to Figure 7.12, click “OK”.
Figure 7.13
The VHDL Entity for the 4-Bit Counter FSM
Declare the Next State and Output Logic Variables in your Architecture
Next, you need to declare signals to hold the current state, next state, and the output variables. These will all be
4-bit vectors. We’ll call the current state variable Q_cur and the next state variable Q_nxt. The individual bits of these
vectors will be wired to the D-flip-flops components when instantiated. We should also create a vector for the Qn output
of the D-flip-flop called Qn_cur. We will create a 4-bit vector for the FSM output called Count. Recall that signal
declarations also go before the begin statement in the architecture. Your VHDL signal declaration should look like:
signal Q_nxt, Q_cur, Qn_cur : bit_vector (3 downto 0); -- FSM State Variables
signal Count : bit_vector (3 downto 0); -- FSM Outputs
depends on both the current state (Q_cur) and the input (Up). A conditional signal assignment makes handling the
input variables straightforward as a Boolean and condition can be used. Consider the following approach to modeling
the next state logic for this FSM. Notice how both Q_cur and Up are considered in the assignment.
Q_nxt <= "0001" when (Q_cur="0000" and UP='1') else
"0010" when (Q_cur="0001" and UP='1') else
"0011" when (Q_cur="0010" and UP='1') else -- rest of the logic goes below
Since there are 5 bits of inputs in this statement (4x for Q_cur and 1x for Up), your full conditional signal assignment
will have 32 separate conditions. These conditions can be entered directly from the table in Figure 7.11. Complete the
VHDL model for your next state logic.
At this point your FSM model is complete. You have created the three portions of the FSM using a combination of
structural design (i.e., instantiating D-flip-flops for the state memory) and concurrent signal assignments (i.e., the
assignments for the next state and output logic).
Update the Prime Number Detector Model to use Count as its Input
In the prime number detector model that was copied from lab 6.1, the signal assignments were based on the input
SW. In this lab, we want the prime number detector to base its outputs on Count. Update the VHDL model to reflect
this change.
• Up PIN_U13 (2.5 V)
• Reset PIN_P22 (2.5 V)
• Clock PIN_H16 (3.3-V LVCMOS)
When complete, your assignments should look like Figure 7.14.
98 • Chapter 7: Sequential Logic
Figure 7.14
Pin Assignments for the 4-Bit Counter FSM
Close the pin planner tool using the pull down menus: File Close
• Type = Square
• Frequency = 4 Hz
• Amplitude = 1.7 V
• Offset = 1.7 V
• Symmetry = 50%
• Phase = 0°
Enable the AWG by pressing the “Run” button. Note that we are not providing power to the breadboard using the
Analog Discovery so no other tools are needed other than the AWG.
Lab 7.3: 4-Bit Counter FSM in VHDL • 99
CONCEPT CHECK
8.1.1 Objective
The objective of this lab is to begin modeling combinational logic using a VHDL process and conditional
programming constructs. You will create the decoder logic in VHDL to drive one of the 7-segment displays on the DE0-
CV board (HEX0).
Note: As this lab exercise is commonly used as the starting point for the 2nd course in the logic design sequence,
the steps to create a Quartus project from scratch will be repeated. These are the same steps that were covered in lab
5.1 Also of note is that all lab exercises from this point on will only use the DE0-CV board and the Analog Discovery.
• Use the Quartus toolchain to synthesize, technology map, place/route and implement a VHDL model on
an FPGA.
• Create a 4-input, 7-segment display decoder (016 to F16) on an FPGA using a VHDL process and
conditional programming constructs.
• Use the std_logic_vector data type from the STD_LOGIC_1164 library.
8.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a VHDL design on an FPGA that drives the HEX0 7-segment display on the DE0-CV
board using the slider switches (SW3:SW0) as inputs (90% of exercise).
2. Provide your top.vhd design file (10% of exercise).
101
102 • Chapter 8: VHDL (part 2)
Figure 8.1
Block Diagram of the 7-Segment Decoder System
Figure 8.2 shows the I/O on the DE0-CV that you will be using.
Figure 8.2
Picture of the 7-Segment Decoder System on the DE0-CV Board
Lab 8.1: 7-Segment Display Decoder using a Process • 103
Figure 8.3
Table for HEX0 Display Logic
104 • Chapter 8: VHDL (part 2)
Install the Quartus Lite Software (if not already installed on your computer)
The Quartus Lite software can be downloaded for free from www.altera.com. This will take you to an intel website,
which purchased Altera Inc. in 2016. Once on this page, click on “Support” and then “Downloads”. You will need to
create a free account. There you’ll be given the option of downloading various versions of Quartus. You want to
download the “Lite” version. Click on the “Download” icon next to the Lite version. In the next screen you’ll be given
options on what all should be downloaded. You want to select three items:
Create a Folder for to Hold All of your VHDL Projects (if not already created)
For each Quartus project, you will manually create a folder and then direct Quartus to put all design files into that
directory. We want to first create a main folder that will hold all of the project folders that will be created throughout this
manual to help us stay organized. We will create a folder on the Desktop called “Logic_Lab”. Right click on the Desktop
of your computer and select “New Folder”. Give it the name “Logic_Lab”.
Launch Quartus
On a windows 10 or equivalent machine, the Quartus application can be launched at: Start Intel FPGA version
Lite Edition Quartus (Quartus Prime version). Figure 8.4 shows the Quartus startup window that will appear.
Lab 8.1: 7-Segment Display Decoder using a Process • 105
Figure 8.4
Quartus Startup Window
Figure 8.5
Quartus New Project Wizard (Introduction)
Click on “Next” to go the next window. If you don’t want the introduction window to show up next time you run New
Project Window, you can check the box. The Directory, Name, Top-Level Entity window shown in Figure 8.6 will appear.
106 • Chapter 8: VHDL (part 2)
Figure 8.6
Quartus New Project Wizard (Directory, Name, Top-Level Entity)
For the working directory, click on the “…” button and browse to the “Logic_Lab/
Lab_08p1_7segment_decoder_using_process” folder you created on your desktop. This project folder will contain all
of the Quartus design files.
For the name of the project, enter “Lab_08p1_7segment_decoder_using_process”. Note that as you type this
name, Quartus automatically enters the same name for the top-level entity. You do not want to use this name as
your top-level entity.
For the top-level design entity, enter “top”. The term top is the standard naming convention for the VHDL file that
is at the highest level of hierarchy in the system. At the top level, the ports of the entity will be the physical pins of the
device. For this exercise, we will only have one top-level file. We will create this file (top.vhd) in a later step.
Click on the “Next” button. The Project Type window shown in Figure 8.7 will appear.
Figure 8.7
Quartus New Project Wizard (Project Type)
Leave the project type as “Empty” and click “Next”. The Add Files window shown in Figure 8.8 will appear.
Lab 8.1: 7-Segment Display Decoder using a Process • 107
Figure 8.8
Quartus New Project Wizard (Add Files)
This window is where we can add existing design files. For this exercise we do not have any existing design files.
Instead, we will be creating a new file called top.vhd. We will do this later outside of the New Project Wizard. Do not
do anything in this window except click “Next”. The Family, Device & Board Settings window shown in Figure 8.9 will
appear.
Figure 8.9
Quartus New Project Wizard (Family, Device & Board Settings)
In this window we tell the Quartus synthesizer which device we will be targeting. Since we only installed the
Cyclone V FPGA family, only those devices will be shown. Notice that there are many different Cyclone V devices that
can be selected. We want to select the FPGA device that is on our DE0-CV board. We can begin filtering down the
selection by typing in the “Name filter” field on the right side of the pain. Begin typing 5CEBA4F23C7. After each
character is typed, it will reduce the number of devices that are available. Once you type the last character, there will
only be one device available. Highlight this device and click “Next”. The EDA Tool Settings window shown in Figure
8.10 will appear.
108 • Chapter 8: VHDL (part 2)
Figure 8.10
Quartus New Project Wizard (EDA Tool Settings)
In this window you can direct Quartus to read files from various CAD tools from other vendors. For this exercise,
we will be using the Quartus tool by itself. Leave all the settings at <None> and click “Next”. The Summary window
shown in Figure 8.11 will appear.
Figure 8.11
Quartus New Project Wizard (Summary)
Review the settings in this window and if correct, click “Finish”. If any of the settings are incorrect, you can click
the “Back” button to go back and change them. You will now see a new blank project window with all of your settings
as shown in Figure 8.12.
Lab 8.1: 7-Segment Display Decoder using a Process • 109
Figure 8.12
New Blank Project for the Cyclone V on the DE0-CV FPGA Board
• SW (3 downto 0) This is the 4-bit input vector for the 4x slider switches on the DE0-CV board.
• LEDR (3 downto 0) This is the 4-bit output vector for the 4x red LEDs on the DE0-CV board.
• HEX0 (6 downto 0) This is the 7-bit output vector that will drive the 7x LEDs within the HEX0 display
on the DE0-CV board.
Enter the following VHDL entity into your top.vhd. Notice that the entity name matches the file name in addition to
the name of the top-level of the design in Quartus. This tells Quartus that any ports that are declared will be connected
to pins on the FPGA board.
entity top is
port (SW : in std_logic_vector (3 downto 0);
LEDR : out std_logic_vector (3 downto 0);
HEX0 : out std_logic_vector (6 downto 0));
end entity;
At this point your project should look like Figure 8.13. Notice that Quartus recognizes the VHDL syntax and will
color code based on the construct type.
110 • Chapter 8: VHDL (part 2)
Figure 8.13
VHDL Entity for 7-Segment Display Decoder using a Process
begin
end architecture;
Figure 8.14
Quartus Window After Successful Compile and Synthesis
Figure 8.15
Quartus Pin Planner for the HEX0 7-Segment Decoder Project
112 • Chapter 8: VHDL (part 2)
Pin Planner does not have a save option. Instead, you simply close it using the drop-down menus: File – Close.
Back in Quartus you’ll notice that the tasks are no longer green. This indicates that the design needs to be compiled
and synthesized again to take the new pin assignments into account. Double click on “Compile Design” and let it run
until all tasks have been completed successfully.
If the programmer does not automatically find the device, you can press the “Auto Detect” button on the left of the
programmer window. Once it finds the device, you need to assign the top.sof file. Highlight the device, right-click, and
select “Add File”. Browse to the output_files folder and select top.sof. When using the programmer for the first time, it
may say “No Hardware” next to the hardware setup button. This means that the programmer is not using the correct
drivers for the DE0-CV board. Click on the “Hardware Setup” button. For the “Currently Selected Hardware”, use the
drop-down menus to select “USB-Blaster [USB-x]”. Click “Close”. Now the programmer will use the proper drivers to
communicate with the DE0-CV board.
At this point we are ready to download the top.sof file to the FPGA in order to program it. Click on the “Start” button
on the left side of the programmer window. The status of the programming will be displayed in the status bar in the
upper-right corner of the window. When successful, it will say “100% (Successful)”.
CONCEPT CHECK
Lab 8.2: Design Re-Use and Binary Characters on the 7-Segment Displays
8.2.1 Objective
The objective of this lab is to gain experience creating and using lower-level subsystems. This will be accomplished
by creating a 7-segment decoder component and instantiating it numerous times within the top level entity. This lab
will also give experience using signal concatenation within a port map, creating a new Quartus project from a prior
project, and importing signal assignments from an external file.
8.2.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a design that uses multiple instantiations of a 7-segment decoder component to drive all
the HEX character displays on the DE0-CV FPGA board (50% of exercise).
2. Demonstrate a design that displays the binary values of the four slider switches on the character
displays (40% of exercise)
3. Provide your top.vhd design file (10% of exercise).
Figure 8.17
Block Diagram of the System to Drive Each Character Display with its own Decoder Component
Figure 8.18 shows a picture of the I/O on the DE0-CV board that will be used in this part of the exercise.
Lab 8.2: Design Re-Use and Binary Characters on the 7-Segment Displays • 117
Figure 8.18
Picture of the System to Drive Each Character Display with its own Decoder Component on the DE0-CV Board
Figure 8.19
Copy Project Settings in Quartus
118 • Chapter 8: VHDL (part 2)
The first step is designing the subsystem is including the necessary libraries. We will be using the std_logic and
std_logic_vector data types from the std_logic_1164 library. To include this library, add the following VHDL statements
to the beginning of your char_decoder.vhd file.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
We are now ready to enter the VHDL entity for the design. The decoder subsystem will have the following ports:
• BIN_IN (3 downto 0) This is the 4-bit binary input vector to the decoder.
• HEX_OUT (6 downto 0) This is the 7-bit output vector to drive a character display.
Enter the following VHDL entity into your char_decoder.vhd.
entity char_decoder is
port (BIN_IN : in std_logic_vector (3 downto 0);
HEX_OUT : out std_logic_vector (6 downto 0));
end entity;
Now create the architecture for the decoder. You will copy your process from the current top.vhd file. You’ll need
to rename the architecture and all signals to reflect the new entity declaration (i.e., SW will be replaced with BIN_IN,
LEDR will be replaced with HEX_OUT). Save your char_decoder.vhd file.
You are now ready to alter the architecture. In the existing architecture that was copied over, you can leave the
signal assignment of LEDR <= SW; but you should delete the decoder process. You will implement six decoders by
instantiating six versions of the char_decoder.vhd component. To use the decoder it must first be declared before the
begin statement. The syntax for the component declaration will look like:
component char_decoder
port (BIN_IN : in std_logic_vector (3 downto 0);
HEX_OUT : out std_logic_vector (6 downto 0));
end component;
Lab 8.2: Design Re-Use and Binary Characters on the 7-Segment Displays • 119
Once declared, you can instantiate the subsystem after the begin statement. You will need to instantiate it six
times, once for each of the displays on the DE0-CV board. Remember that each of the subsystems will have an input
of SW. The syntax for instantiating the subsystem is:
C0 : char_decoder port map (BIN_IN => SW, HEX_OUT => HEX0);
C1 : char_decoder port map (BIN_IN => SW, HEX_OUT => HEX1);
C2 : char_decoder port map (BIN_IN => SW, HEX_OUT => HEX2);
C3 : char_decoder port map (BIN_IN => SW, HEX_OUT => HEX3);
C4 : char_decoder port map (BIN_IN => SW, HEX_OUT => HEX4);
C5 : char_decoder port map (BIN_IN => SW, HEX_OUT => HEX5);
Notice that the above text defines the pin assignments for the HEX0 port, which you have already manually entered
in the pin planner tool. When this file is imported, it will overwrite the values in pin planner. Save the CSV file in your
project directory and name it “pin_assignments.csv”. Use the DE0-CV user’s manual to look up the pin numbers for all
of the ports used in this design. You will need to add the assignments for the existing I/O SW and LEDR in addition to
the new I/O HEX1, HEX2, HEX3, HEX4, and HEX5.
Once the CSV file is created, it can be imported into Quartus. In Quartus, use the pull down menus to import the
pin assignments using: Assignments Import Assignments. Browse to your CSV file and click “OK”. This should
have imported in all of the assignments for your design. To verify that everything was imported correctly, run the Pin
Planner tool and scroll through the assignments. If you made any syntax errors in your CSV file, the assignments in
Pin Planner will be blank. If you entered the wrong pin, you won’t be able to find the mistake until you download your
design. Re-Compile your design.
Figure 8.20
Picture of System to Drive Binary Characters to the 7-Segment Displays
There are multiple ways to concatenate signals in VHDL. You could create a new 4-bit signal and then use a
signal assignment and the concatenation operator (&). A faster way to accomplish this when driving component inputs
Lab 8.2: Design Re-Use and Binary Characters on the 7-Segment Displays • 121
is to put the concatenation directly in the port mapping. VHDL supports this type of concatenation using the following
syntax:
C0 : char_decoder port map (BIN_IN => "000" & SW(0), HEX_OUT => HEX0);
Modify your architecture to implement this behavior for each of the four char_decoder.vhd subsystems. Save your
design.
CONCEPT CHECK
9.1.1 Objective
The objective of this lab is to gain experience designing and using sequential storage devices in VHDL. You will
create a D-flip-flop model using a process and then instantiate it multiple times to build a 38-bit ripple counter. The
most significant bits of the counter (i.e., the slowest toggling bits) will be used to drive the LEDs and HEX character
displays on the DE0-CV FPGA board. This lab will also give experience using a logic analyzer to measure the frequency
of a counter.
9.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a 38-bit ripple counter made of D-flip-flops where the most significant bits drive the HEX
displays and LEDs on the DE0-CV FPGA board (70% of exercise).
2. Measure the frequency of the counter using a logic analyzer (20% of exercise).
3. Provide your top.vhd design file (10% of exercise).
123
124 • Chapter 9: Behavioral Modeling of Sequential Logic
Figure 9.1
Block Diagram of the Ripple Counter System
Figure 9.2 shows the I/O that will be used in this exercise.
Figure 9.2
Picture of the Ripple Counter System on the DE0-CV Board
Lab 9.1: Ripple Counter and the Character Displays • 125
9.1.5.1 Implement the Ripple Counter System in VHDL on the DE0-CV Board
Create a New Quartus Project by Copying Lab 8.2
We want to re-use many of the I/O that were used in lab 8.2 so we’ll create a new Quartus project for this exercise
by copying lab 8.2. Open lab 8.2 in Quartus. Use the Copy Project feature to create the project for this lab. Name the
folder and project “Lab_09p1_ripple_counter”.
Note that when you copy the project, the pin_assignments.csv file will not automatically copy over. You
should manually copy this file into your new project directory.
Modify your top.vhd file Entity to Support the Additional I/O that will be Used in this Exercise
In this lab you will be using additional ports beyond the entity definition from lab 8.2. These signals include Clock
and Reset to drive the synchronous circuitry in the design in addition to widening the LEDR vector to 10-bits to drive all
of the red LEDs on the DE0-CV board. You will also be adding the lower 8-bits of the GPIO_1 header. All ports should
be declared as types std_logic or std_logic_vector. Make the entity modifications to your top.vhd file. Once complete,
your entity definition should look like Figure 9.3.
Figure 9.3
Entity Definition for the 38-Bit Ripple Counter System
Figure 9.4
Ripple Counter Architecture
The clock for the ripple counter will come from the 50 MHz oscillator on the DE0-CV board. This will result in the
LSB of the counter running at 25 MHz. This is much too fast to observe on an LED. In order to be able to observe
some of the bits of the counter on LEDs, we need to observe bits that are toggling in the Hz range. Since each
subsequent bit in the counter will run at ½ the frequency of the preceding bit, we can continue to add bits to the counter
until the most significant bits are slow enough to be observed. This will require 38 bits in the counter. To create a 38-
bit counter, you will need to instantiate your D-flip-flop 38 times and wire them in the ripple counter configuration shown
in Figure 9.4. You will need to create internal signals to connect to the D, Q, and Qn ports of the D-flip-flops. Create
two, 38-bit signal vectors called CNT and CNTn.
Connect the Ripple Counter Outputs to LEDR, HEX, and GPIO_1 Outputs
Connect the most significant 24-bits of the counter to your 6x instantiations of your char_decoder.vhd component
to drive the 6x HEX displays. You’ll connect the bits in groups of four. For example, CNT(37 downto 34) will drive
HEX5, CNT(33 downto 30) will drive HEX4, etc. Connect the most significant 10-bits of your counter directly to the 10x
red LEDs on the DE0-CV board. Connect the least significant 8-bits of your counter to the GPIO_1 port.
Assign the Pins for the Additional I/O used in this Exercise
Locate the pin assignments for the Clock, Reset, additional LEDR I/O, and GPIO_1 pins used in this lab using the
DE0-CV User’s Guide. Add these locations to your pin_assignments.csv document and then import into Quartus.
Verify that the pin assignments are correct by launching the Pin Planner tool. Once they are verified, close the Pin
Planner tool and recompile.
Connect the Analog Discovery’s Logic Channels to the GPIO_1 port on the DE0-CV
The logic analyzer channels on the Analog Discovery are labeled as numbers (i.e., 0, 1, 2…). You should connect
the lower 8 channels of the logic analyzer to the GPIO_1 header pins labeled D0 D7 in the DE0-CV user’s manual.
The block diagram in Figure 9.1 shows how the channels between the GPIO_1 header are mapped to the logic analyzer.
Also connect one of the grounds of the Analog Discovery to a ground pin on the GPIO_1 header. The grounds of the
Analog Discovery are labelled with the ↓ symbol. After the connection to the DE0-CV board is complete, plug in the
Analog Discovery to your computer using the USB cable. Your connection should will look like Figure 9.2.
Launch Waveforms
The Analog Discovery is controlled using an application called Waveforms. If Waveforms isn’t installed on the
computer you are using, you can download it for free from Digilent.com (http://store.digilentinc.com/). Once on this
website, on the left select “Scopes, Instruments, & Circuits”, and then on the “Waveforms 2015 (Download Only)”
product. On the next screen, select “Download Here”. On the next screen you will find “Latest Downloads” where you
can choose “Windows”. The 65MB download will then commence. Once downloaded, run the *.exe file and the
software will be installed.
Launch Waveforms (Start –Digilent – Waveforms). The software will automatically recognize the Analog Discovery
and connect. The Waveforms startup window shown in Figure 9.5 will appear. From this window, you can launch all
of the tools associated with the Analog Discovery. Each tool brings up a new tab within the workspace window. Multiple
tools can be launched and ran at the same time.
Figure 9.5
Waveforms 2015 Startup Window
In the options window that appears, name the bus CNT. On the left side of the window there is a list of available
logic analyzer channels to include in the bus. Highlight the eight channels “DIO 7” through “DIO 0” by selecting them
while holding down the Shift key. Once selected, click on the + sign to add them to the box on the right. Your settings
should look like Figure 9.6. Once the bus looks correct, click the “Add” button.
Figure 9.6
Logic Analyzer Bus Setup
Figure 9.7
Logic Analyzer of Ripple Counter with No Trigger
Lab 9.1: Ripple Counter and the Character Displays • 129
Figure 9.8
Logic Analyzer Measurement of CNT with Trigger set to x"00"
Click “Run” and allow the analyzer to free run. When using the “Run” button (instead of the “Single” button), the
analyzer will continually take measurements and replace the data on the screen. Since we have the trigger set to
CNT=x”00”, each measurement will mostly look the same and the screen should appear somewhat static. To prove to
yourself that the data is actually live, unplug the D0 channel from the DE0-CV board and observe that the signal goes
flat in the analyzer.
CONCEPT CHECK
9.2.1 Objective
The objective of this lab is to gain experience designing finite state machines (FSMs) in VHDL using a behavioral
modeling approach. You are going to design a FSM that will produce a walking 1 pattern on the red LEDs of the DE0-
CV board. You will also drive the walking 1 pattern to the pins of the GPIO_1 connector for observation with a logic
analyzer measurement. You will also gain experience using a divided down clock to trigger your FSM.
9.2.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a walking 1 pattern on the red LEDs of the DE0-CV board (70% of exercise).
2. A logic analyzer measurement of the walking 1 pattern (20% of exercise).
3. Provide your top.vhd design file (10% of exercise).
In this lab exercise you are going to create a FSM that will produce a walking 1 pattern within a 10-bit vector. The
10-bit output vector will drive the 10x red LEDs and lower 10x pins on the GPIO_1 header. This FSM will require 10x
states and use Moore-type outputs. The direction of the walking 1 pattern will be dictated by SW(0). When SW(0)=1,
the pattern will walk from LEDR(0) to LEDR(9) and repeat. When SW(0)=0, the pattern will walk from LEDR(9) to
LEDR(0) and repeat. Figure 9.5 shows a graphical depiction of the walking 1 patterns as seen on the red LEDs.
132 • Chapter 9: Behavioral Models of Sequential Logic
Figure 9.9
Walking 1 Patterns on the Red LEDs
The FSM will need to be clocked using a frequency that is slow enough so that the walking 1 pattern can be seen
with the human eye on the red LEDs. One of the ways to create a slower clock signal is to continually divide the
incoming 50 MHz clock by two using a series of toggle flops. You have already implemented this type of clock divider
in lab 9.1 in the form of a 38-bit ripple counter. In this lab you will use bit 21 of your 38-bit ripple counter to clock your
FSM. This bit has a frequency of 11.9 Hz.
After observing the walking 1 pattern on the red LEDs, you will take a logic analyzer measurement on the 10-bit
vector on the GPIO_1 header. Figure 9.10 shows the block diagram for the walking 1 FSM system.
Figure 9.10
Block Diagram of the Walking 1 FSM System
Figure 9.11 shows the I/O that will be used in this lab.
Lab 9.2: A “Walking 1” FSM • 133
Figure 9.11
Picture of the Walking 1 System on the DE0-CV Board
Modify your top.vhd file Entity to Support the Additional I/O that will be Used in this Exercise
In this lab you will have a slightly different entity definition from lab 9.1. First, we want to change the name of the
incoming 50 MHz clock signal to differentiate it from the internal divided down clock we will use to clock our FSM. Call
the incoming clock port Clock_50. You also need to expand the GPIO_1 output port to 10-bits so that the entire walking
1 pattern can be measured by the logic analyzer. Once complete, your entity definition should look like Figure 9.12.
Figure 9.12
Entity Definition for the Ripple Counter System
134 • Chapter 9: Behavioral Models of Sequential Logic
Assign the Pins for the Additional I/O used in this Exercise
You will now need to update your pin_assignments.csv file to reflect the changes and additions for this lab. Open
your pin_assignment.csv file. First, you will need to change the name of the incoming clock from “Clock” to “Clock_50”.
Next, you will need to add the pin assignments for the additional pins that you are using on the GPIO_1 header. The
pin locations can be found in the DE0-CV User’s Guide. Import the assignments into Quartus and verify they are correct
by looking in the Pin Planner tool.
Note that when you change the name of a signal, it will leave the old assignment in Pin Planner. You should
manually delete the signal Clock from the pin assignment table. Otherwise there will be a conflict with both Clock and
Clock_50 being assigned to PIN_M9. In Pin Planner, right-click on the Clock signal, select Edit, and then Delete. Once
the assignments are verified, close the Pin Planner tool.
Assign the Output of your FSM to the LEDR and GPIO_1 Ports
After your FSM is designed, you should make signal assignments from the output Walking1_Out to both LEDR
and GPIO_1. Since all of these vectors are 10-bits, the assignments can be made directly.
measurements of the walking 1 pattern running in both directions to verify its functionality. Use the HotTracks tool to
measure the pulse width of one of the walking 1s. It should have a pulse width of 0.084 s, which corresponds to a FSM
clock rate of 11.9 Hz.
Figure 9.13
Logic Analyzer Measurement of Walking 1 Pattern
Take a screenshot of the logic analyzer measurement displaying the HotTrack pulse width value. Save the image
in JPG format with a descriptive file name. This image satisfies the requirements for deliverable #2.
Save your Analog Discovery workspace in your Quartus project directory so that you can recreate this
measurement in the future if needed. Close Waveforms.
CONCEPT CHECK
9.3.1 Objective
The objective of this lab is to gain experience designing counters with a single process in VHDL. This lab will also
give experience building a selectable, 2n clock divider based on a ripple counter. The clock divider will allow the counter
to be run at a speed that can observed on the LEDs of the DE0-CV board. This lab will also give experience using a
logic analyzer to measure the frequency of a counter.
9.3.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstrate a counter implemented with a single process and displayed on the HEX displays and red
LEDs of the DE0-CV board (70% of exercise).
2. A logic analyzer measurement of the frequency of the counter (20% of exercise).
3. Provide your top.vhd design file (10% of exercise).
You are also going to create a new subsystem that will selectively divide the frequency of the incoming 50 MHz
clock so that rate of your counter can be changed in real-time. This new system will be called “clock_div_2ton.vhd”
and will create the internal clock (Clock_div) that will be used by your 24-bit counter process. Figure 9.14 shows the
block diagram for this exercise.
138 • Chapter 9: Behavioral Models of Sequential Logic
Figure 9.14
Block Diagram of the Counter System with 2n Clock Divider
Figure 9.9 shows the I/O that will be used in this exercise.
Figure 9.15
Picture of the Counter System with 2n Clock Divider on the DE0-CV Board
Lab 9.3: Counters using a Single Process and a 2n Clock Divider • 139
Figure 9.16
Package and Entity Definition for the One-Process Counter System
Figure 9.17
Selectable, 2n Clock Divider Architecture
Designing the 2n clock divider subsystem will require creating a new VHDL file in Quartus called
clock_div_2ton.vhd. Within this new file, use the entity definition provided in Figure 9.17. You will insert your 38-bit
ripple counter from prior labs into this file and clock it using the input port “Clock_In”. You will then create a 4-to-1
multiplexer process that will choose one of the output bits of the ripple counter to drive the output port “Clock_Out”.
The selection will be made based on the input “Sel”. Since Sel is a 2-bit vector, it can select one of four bits of the
counter. Choose the counter bits for the multiplexer so that they give the clock frequencies 25 MHz, 191 Hz, 6 Hz, or
1.5 Hz based on an incoming clock of 50 MHz. Note that your clock divider requires the dflipflop.vhd subsystem. If
this system isn’t in your project directory, add it. Save your design.
Back in your top.vhd file, declare your clock_div_2ton.vhd design as a component and instantiate it. Drive the
divider component with the input port Clock_50. The output of the divider will be an internal signal called “Clock_div”.
The signal Clock_div will be the signal that drives the main 24-bit counter process that you will design next. Use the
input port “Reset” to drive the Reset input of your clock divider. Finally, use the SW(1) and SW(0) input ports to drive
the “Sel” inputs of the clock divider.
Assign the Pins for the Additional I/O used in this Exercise
Since you copied this project from lab 9.2 and are using a subset of the ports, you should not have to import any
signal assignments. Launch the Pin Planner tool and verify that all of your ports have the correct assignments. If they
do not, correct them.
Note that it is OK for the Pin Planner to have locations for ports that are not being used in your entity. The
synthesizer will automatically remove them from your design. Once the assignments are verified, close the Pin Planner
tool.
measure the pulse width of the counter. With your clock divider configured to provide a 191 Hz clock to your counter,
the pulse width should be around 5.2 ms. Your measurement will now look like Figure 9.18.
Figure 9.18
Logic Analyzer Measurement of CNT with Trigger set to x"00"
Take a screenshot of the logic analyzer measurement displaying the HotTracks measurement of your pulse width.
Save the image in JPG format with a descriptive file name. This image satisfies the requirements for deliverable
#2.
Save your Analog Discovery workspace in your Quartus project directory so that you can recreate this
measurement in the future if needed. Close Waveforms..
CONCEPT CHECK
9.4.1 Objective
This objective of this lab is to provide more practice modeling counters in VHDL using single processes. In the
first part of the lab, you will create a precision clock divider that is capable of outputting four different clock frequencies:
1 Hz, 10 Hz, 100 Hz, and 1 kHz. This will be accomplished using a counter process and selectable range checking.
You will measure the frequency of the divided down clock using the Analog Discovery’s oscilloscope tool. In the second
part of the exercise, you will be designing a 6-symbol, binary coded decimal (BCD) counter that will be driven to the six
character displays on the DE0-CV board. This will be accomplished using six separate, but interdependent processes.
• Implement a precise timing event using a counter modeled with a VHDL process and range checking.
• Create a multi-symbol BCD counter using interdependent VHDL counter processes.
9.4.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Oscilloscope measurement of the output of a precision clock divider (45% of the exercise).
2. Demonstration of a 6-symbol, BCD counter displayed on the character displays of the DE0-CV FPGA
board (45% of exercise).
3. Provide your top.vhd design file (10% of exercise)
Figure 9.19
Block Diagram of the BCD Counter System
Figure 9.20 shows a picture of the I/O that will be used in this exercise.
Figure 9.20
Picture of the BCD Counter System on the DE0-CV Board
Lab 9.4: Precision Clock Divider and a BCD Counter • 145
As an example, let’s say you wanted to create a divided down clock with a frequency of 5 Mhz. This clock has a
period of Tdiv=200 ns. Using a precision clock divider approach, we want to design a counter that toggles the output
clock signal every 100 ns. Remember that to toggle a signal means if it was a 1, it will be changed to a 0, and if it was
a 0, it will be changed to a 1. In the DE0-CV system, the incoming clock is 50 MHz, which has a period of Tin=20ns. If
you create a counter based on the incoming clock, it will increment every 20ns. If you create a counter that increments
up to 5 and then is set back to 0, the setback event will occur every 5x20ns=100ns. Each time the counter reaches its
maximum value and needs to be manually set back to zero, you can also have it toggle the output clock signal. This
will result in an output signal with a HIGH time of 100ns, a LOW time of 100ns, and an overall period of 200ns. In this
way, you have created a divided down clock with a frequency of 5 MHz. Figure 9.21 shows a graphical depiction of
this example.
Figure 9.21
Graphical Depiction of the Operation of the Precision Clock Divider
146 • Chapter 9: Behavioral Modeleling of Sequential Logic
You are going to create a precision clock divider that outputs four different clock frequencies: 1 Hz, 10 Hz, 100 Hz,
and 1 kHz. This will be accomplished using the counter approach described above. The first step is to determine the
maximum range of the your counter to accomplish these frequencies. Using the approach above, determine the upper
values of your counter to achieve the four frequencies. Remember that when the counter reaches its maximum value,
it will toggle the clock frequency. This means your maximum value represents how long the clock will be HIGH or LOW.
Said another way, you are trying to find the number of times that the period of a 50 MHz clock (i.e., 20ns) will go into
half of the desired clock period.
You will now enter the architecture for the precision clock divider. Your counter will output one of four different
clock frequencies (1 Hz, 10 Hz, 100 Hz, and 1 kHz) depending on the values of Sel. You will create a process that
increments a counter on the rising edge of Clock_In (note that Clock_In will be connected to Clock_50 in the top.vhd).
Your counter should increment up to a maximum value and then be setback to 0. Every time your counter reaches its
maximum value, you should toggle Clock_out. The maximum value that your counter will increment to depends on the
inputs Sel(1) and Sel(0). You calculated the maximum values for these four frequencies above.
Some tips:
• You are going to have a single process to implement your counter. This process will have Clock_in and
Reset in the sensitivity list. Consider having a second process that will be used to assign the maximum
value for the counter based on Sel. You will need to create an internal signal to hold the maximum
value. In this way, you can simply compare your current count value to this new signal as if it was a
constant. Anytime Sel changes, the signal will be updated independent of your main counter process.
The process to make the maximum value assignment will only have Sel in the sensitivity list.
• Consider using the type integer for your counter. This way you can set the maximum value in integer
format instead of hex. Since the internal counter doesn’t get assigned to any ports, it does not have to
be of type std_logic_vector.
• In your main counter process, you will want to update Clock_out whenever the system is reset, or when
the counter reaches its maximum value. Since Clock_out is an output port, it can’t exist on the right-
hand-side of an assignment. This means you can’t directly do the assignment:
Clock_out <= not Clock_out. Consider creating an internal signal to hold the value of the divided clock.
This will allow the signal to exist on the right-hand-side of the assignment. Outside of the process, you
can then assign this internal signal to the output port Clock_out.
Save your design. Back in your top.vhd file, declare your clock_div_prec.vhd design as a component and
instantiate it. Note that since you copied lab 9.2, you already have a component declaration for clock_div_2ton.vhd
with the exact same entity definition. All you need to do is change the name of this component to clock_div_prec to
use your new divider system.
• Offset = -1.45 V
• Range = 0.5 V/div
On the right side of the screen you’ll also see zoom controls for time. Again, both a scaling per division is given
(base) and a horizontal offset (position). Oscilloscope are usually used for signals that are fast enough that they can’t
be observed with the human eye. In this part, we will be measuring a 1 kHz signal so we need to configure the time
zoom accordingly. Configure the time control to:
• Position = 0 s
• Base = 1 ms/div
When signals are too fast to be seen with the human eye, simply displaying what the oscilloscope is measuring on
the screen would result in the entire screen being lit up. To handle displaying fast repetitive signals, an oscilloscope
uses a trigger. A trigger represents an event that occurs on the incoming signal, such as a rising edge passing through
a certain voltage level. When this occurs, the oscilloscope positions all of its recorded data on the screen with the
trigger moment located at time=0s. As the oscilloscope continues to run, it will continually trigger and overwrite the
data on the screen with the new set of data positioned with the trigger at time=0s. If the signal is repetitive, the resulting
screen will show a steady waveform in which the characteristics of the signal can be determined. We want to setup
the trigger so that every time Channel 1 has a rising transitions that passes through 1.7v, the oscilloscope will trigger.
Along the top of the measurement screen there are a variety of trigger settings. Configure these as follows:
• Mode = Auto
• Source = Channel 1
• Condition = Rising
• Level = 1.7 V
Now we are ready to take an oscilloscope measurement. Press the “Run” button (the green triangle). You will see
the waveform in Figure 9.22. Note that the background can be changed from Dark to Light using the setup gear button
in the upper right corner of the waveform. You can also change the thickness of the line. Making the background light
and the line thicker makes taking and printing screenshots easier.
148 • Chapter 9: Behavioral Modeleling of Sequential Logic
Figure 9.22
Oscilloscope Measurement of 1 kHz Divided Down Clock
Turn on the HotTracks measurement tool (the ruler in the upper right corner of the waveform pane). As you drag
your mouse over the waveform, you’ll see a variety of different measurements. When you place your marker in the
vertical center of the waveform, you’ll see the period measurement and corresponding frequency. If your clock divider
is operating correctly, you should see a 1 kHz square wave. Verify that your clock divider works for the 100 Hz, 10 Hz
and 1 Hz settings. When you change SW(1) and SW(0), you’ll need to zoom in/out to get a visible square wave on the
screen. Note that the 1 Hz measurement will take ~10 seconds to fill up the screen.
After verifying that all four clock frequencies operate as expected, change SW(1) and SW(0) back to the 1 kHz
setting and take a screenshot showing that HotTracks is measuring a 1 kHz signal (+ or – a few Hz). Save the image
in JPG format with a descriptive file name. This image satisfies the requirements for deliverable #1. Save your
Waveforms workspace so you can recreate this measurement in the future.
of letting it go higher than 9. Refer to section 9.4.2 in the textbook to see an example of a counter implemented with
an integer data type and range checking.
Another complexity of BCD counters comes when more than one digit is used. Each digit is driven with its own
process, but each higher position process depends on the lower position values relative to its own position. There are
two considerations when implementing the process for a digit that isn’t in the lowest position. The first consideration is
when to set it back to 0. It does not simply setback to 0 when it reaches its maximum value. Instead, it is only setback
to 0 when itself and all lower position digits are at their maximum value. As an example, let’s look at a 2-digit number.
When this number reaches 9010, it does not set the digit in p=1 back to zero, even though it has reaches its maximum
value of 910. Instead, it is setback to zero when it reaches 9910 because itself and all lower position digits have reached
their maximum values. This is handled within the process in the same way that the maximum range is handled, except
that the condition for when to set it back to 0 must include all lower position values. This can be handled by including
a Boolean AND operation within the if clause for the range checking.
The second consideration is that the higher order digit doesn’t increment on every edge of the triggering clock.
Instead, it only increments when all of the lower position digits have reached their maximum value. As an example,
let’s again consider a 2-digit decimal number. For the first 9 counts, only the least significant digit is incrementing (0010
0110 0210 …). Only when the least significant digit reaches its maximum value of 910 and is setback to 0 does
the digit in the higher position increment (0810 0910 1010). This means the process implementing the incrementing
behavior of the counter must have an additional if clause that checks whether the lower position bits are at their
maximum values. Only if they are is the higher order counter incremented.
Implement the 6x separate processes for the BCD counter. It is recommended that you implement and test each
process before moving to the next higher order digit. The counter result of each process will be driven into the
char_decoder.vhd components in order to drive each HEX display.
CONCEPT CHECK
10.1.1 Objective
This objective of this lab is to gain experience modeling read only memory (ROM) in VHDL. You will design a
synchronous, 64x8 ROM array and pre-populate it with known values. You will then create an address counter that
will cycle through all 64 addresses in order to continually read the contents of the ROM. You will observe the address
and output of the ROM on the HEX displays and using the logic analyzer.
10.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstration of a ROM system that continually reads the values of the array and displays the input
address and output data on the HEX displays (70% of exercise).
2. A logic analyzer measurement showing the operation of the ROM system (20% of exercise).
3. Provide your top.vhd design file (10% of exercise).
151
152 • Chapter 10: Memory
Figure 10.1
Block Diagram of the ROM Memory System
Figure 10.2 shows a picture of the ROM memory system implemented on the DE0-CV board.
Figure 10.2
Picture of the ROM Memory System on the DE0-CV Board
Lab 10.1: ROM Memory • 153
Figure 10.3
Entity for ROM System
Figure 10.4
ROM Array Contents and Entity Definition
Back in your top.vhd file, declare your rom_64x8_sync.vhd design as a component and instantiate it. You should
create two internal signal vectors called address and ROM_data_out to connect to the component. You will drive the
component’s clock with Clock_div coming out of your clock_div_prec.vhd.
Assign the Pins for the Additional I/O used in this Exercise
You will need to provide pin locations for the additional GPIO_1 signals used in this exercise. Locate these in the
DE0-CV user’s manual. Update your pin_assignments.csv file. Import the assignments into Quarts.
On the DE0-CV board, set the frequency of your counter to 1 kHz using the SW(1) and SW(0) switches. While
there are a variety of settings that will need to be configured, go ahead and click on the “Single” button to take a
measurement. After the measurement, you will see values for address, ROM_data_out, and Clock_div. Set the
Position to 0.02 s and the Base to 5 ms/div. Set the trigger to address=”000000”. Run the logic analyzer continuously
You should see the contents of the ROM being read out. Your measurement should look like Figure 10.5.
Figure 10.5
Logic Analyzer Measurement of ROM System
Take a screenshot of the logic analyzer measurement. Save the image in JPG format with a descriptive file name.
This image satisfies the requirements for deliverable #2.
Save your Analog Discovery workspace in your Quartus project directory so that you can recreate this
measurement in the future if needed. Close Waveforms.
CONCEPT CHECK
10.2.1 Objective
This objective of this lab is to gain experience modeling read/write memory (R/W) in VHDL. You will design a
synchronous, 32x8 R/W memory. You will then create an address counter with enable that will provide the 32
addresses for the array. You will create a control finite state machine that will facilitate writing information to the memory
and also reading information to verify it is storing correctly. You will observe all of the critical signals using the logic
analyzer.
10.2.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstration of your R/W system displaying read and write operations on the HEX displays and red
LEDs (50% of exercise).
2. A logic analyzer measurement showing a write operation to the R/W array (20% of exercise).
3. A logic analyzer measurement showing a series of read operations from the R/W array (20% of
exercise).
4. Provide your top.vhd design file (10% of exercise).
Figure 10.6
Block Diagram of the R/W Memory System
Figure 10.7 shows a picture of the R/W memory system implemented on the DE0-CV board.
Lab 10.2: Read/Write Memory • 159
Figure 10.7
Picture of the R/W Memory System on the DE0-CV Board
Figure 10.8
Entity for R/W Memory System
160 • Chapter 10: Memory
Figure 10.9
R/W Ports and Entity Definition
Back in your top.vhd file, declare your rw_32x8_sync.vhd design as a component and instantiate it. You should
create an internal signal called write and two internal signal vectors called address and RW_data_out to connect to the
component. The data_in port of the rw_32x8_sync.vhd component will be connected to SW(9 downto 2). You will
drive the component’s clock with Clock_div coming out of your clock_div_prec.vhd.
Figure 10.10
State Diagram for R/W Memory Control FSM
Assign the Pins for the Additional I/O used in this Exercise
You will need to provide pin locations for the KEY(0) and KEY(1) inputs and the additional GPIO_1(15) pin used
in this exercise. Locate these in the DE0-CV user’s manual. Update your pin_assignments.csv file. Import the
assignments into Quartus.
Set the clock frequency to 10 Hz so that the system runs fast enough to quickly respond to a button press but slow
enough so that the values can be observed on the HEX displays. Set SW(9 downto 2)=x”AA” and press KEY(0). You
will see the address increment to x”01” and RW_data_out change to x“AA”. You have just stored x”AA” at address
location x”01” in the R/W array. There are a few things to consider about this operation. First, there is a delay between
when the address increments and when RW_data_out updates. This is because it takes a few clock cycles to complete
the write. The FSM first increments the address to x”01” by asserting addr_EN. It then asserts write to store the
information. The data appears on RW_data_out one clock cycle after it was written because the write and read can’t
occur simultaneously in the memory system.
Change the slider switches to x”EE” and press KEY(0). You will see the address increment to x”02” and
RW_data_out change to x“EE”. You have just stored x”EE” at address location x”02” in the R/W array. Continue to
write different data to the R/W array by changing the switches and pressing KEY(0). Record the values that you are
storing so that you can verify they were correctly written during the read operation. You don’t need to fill up the array,
but you should write at least 10 values so that you have something significant to view during the read operation (next).
Now press the “FPGA_RESET” button to put the address back to x”00”. Remember that a reset has no impact on
the values within the R/W memory array. Resets only alter sequential circuits created with D-flip-flops (i.e., the FSM
state memory, the address counter, and clock_div_prec.vhd). This means that at any time you can put the address
counter back to x”00” by pressing reset. Press and hold KEY(1). You will see the address begin to increment and the
associated data be displayed. Verify that the values displayed are what you stored. If necessary, you can slow down
the clock to 1 Hz so you can see the values more clearly. You will notice that as soon as the RW_data_out is updated,
the address counter increments to the next value. This is the correct functionality; however, this means you will not
see the current address location corresponding to the displayed data at the same time. The address will always be
one more than the location being displayed.
Set the clock back to 10 Hz, press reset, and take a short video (<5 s) showing the values on the HEX displays
when holding down KEY(1). Since the only way for data to get into the R/W array is through the store operation
associated with a KEY(0) press, a video showing a sequence of read operations will inherently prove data was written.
The only constraint on this demonstration is that x”AA” must reside at address x”01” and x”EE” must reside at address
x”02”. This video satisfies the requirements for deliverable #1.
10.2.5.2 Take a Logic Analyzer Measurement of your R/W System During a “Store”
Now you are going to take a logic analyzer measurement of the R/W system during a store. Connect the logic
channels 0 15 of the Analog Discovery to the GPIO_1 header as shown in Figure 10.6 and Figure 10.7. Make sure
to connect a ground of the Analog Discovery to a ground on the GPIO_1 header. Launch Waveforms and click on the
Logic tool. In the logic analyzer tool, add new busses for “address” and “RW_data_out” and assign the logic channels
accordingly. Set the format for these busses to Hexadecimal. Add new signals for Clock_div, addr_EN, and write and
assign the logic channels accordingly. Configure the following logic analyzer settings:
• Set the trigger to “Rising Edge” of addr_EN. Leave all other signals as “Don’t Care”.
• Buffer = 100
• Run = Repeated
• Mode = Normal (This is critical! If left at Auto, measurement will not trigger correctly)
• Source = Digital
• Position = 0.02 s
• Base = 5 ms/div
Press the “Run” button on the logic analyzer tool. The analyzer will display “Armed” as it waits for the trigger (i.e.,
a rising edge on addr_EN).
On the DE0-CV board, set the frequency of your counter to 1 kHz using the SW(1) and SW(0) switches. Press
the reset button to put the address back to x”00”. Now set SW(9 downto 2)=x”AA” and press KEY(0). The logic analyzer
will trigger. You should see the measurement in Figure 10.11.
Lab 10.2: Read/Write Memory • 163
Figure 10.11
Logic Analyzer Measurement of R/W System – Storing x”AA” to Address Location x”01”
Take note of the synchronous behavior of the system. First, observe how the address does not update until one
clock cycle after addr_EN is asserted. This is because the addr_EN is produced by the FSM, which is triggered by the
edge of a clock. The counter process does not see the enable being asserted on the same clock edge because it takes
a small amount of the time for addr_EN to reach its final asserted value. Instead, it is seen on the next clock edge.
Even though it appears that addr_EN is deasserted when the next clock edge occurs, it is actually still present due to
the small amount of delay that exists as it moves to its deasserted state.
Second, notice how the data x”AA” does not appear on the R/W component until two clock cycles after write is
asserted. The first clock period delay is due to the same behavior described for the addr_EN signal. The second clock
period delay is due to the output not being able to display the data on the same edge that it is stored on.
Now change SW(9 downto 2)=x”EE” and press KEY(0). The logic analyzer will trigger. You should see the
measurement in Figure 10.12.
Figure 10.12
Logic Analyzer Measurement of R/W System – Storing x”EE” to Address Location x”02”
Now store x”BB” to address location x”03”. Take a screenshot of this logic analyzer measurement. Save the
image in JPG format with a descriptive file name. This image satisfies the requirements for deliverable #2.
10.2.5.3 Take a Logic Analyzer Measurement of your R/W System During a “Read”
Now you are going to take a logic analyzer measurement of the R/W system during a read. Press the reset button
to put the address back to x”00” and then press the KEY(1) button once. The logic analyzer will trigger. Note that the
clock of the system is running at 1 kHz. This means that no matter how fast you try to remove your finger from KEY(1),
it will still be slow enough that hundreds of values will be read out of the R/W array due to having addr_EN asserted
while KEY(1) is pressed. You should see a measurement similar to Figure 10.13. Your values will differ depending on
what you stored in the address locations beyond x”03”.
164 • Chapter 10: Memory
Figure 10.13
Logic Analyzer Measurement of R/W System – Reading Contents of Array
Take a screenshot of this logic analyzer measurement. Save the image in JPG format with a descriptive file name.
This image satisfies the requirements for deliverable #3.
Save your Analog Discovery workspace in your Quartus project directory so that you can recreate this
measurement in the future if needed. Close Waveforms.
CONCEPT CHECK
11.1.1 Objective
This objective of this lab is to gain experience with some of the most used reporting and viewing options associated
with modern digital design tools. You will use the Quartus tool to view the resource utilization and maximum frequency
reports for an FPGA design. You will also view the RTL, state machine, and chip planner views of the design.
11.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. A screenshot of the device utilization report for a VHDL design in Quartus (20% of exercise).
2. A screenshot of the maximum clock frequency report for a VHDL design in Quartus (20% of exercise).
3. A screenshot of the RTL view for a VHDL design in Quartus (20% of exercise).
4. A screenshot of the state diagram view for a VHDL FSM in Quartus (20% of exercise).
5. A screenshot of the chip planner view for a VHDL design in Quartus (20% of exercise).
165
166 • Chapter 11: Programmable Logic
There are two general types of utilization reports. The first report is in the Analysis & Synthesis step. In this
step, Quartus has synthesized your VHDL designed and performed the first mapping of logic into its available
resources, however, it has not yet done the final placement and routing of your design into the FPGA. Quartus does
this first step to ensure your design has a chance of fitting within the selected FPGA before going to the next, more
detailed implementation step.
In the task pane of Quartus, expand the Analysis & Synthesis step and double click on View Report. You will see
a “Compilation Report – top” window appear in the main window. On the left side of report window, there is a table of
contents. This table of contents contains all of the reports for the implementation. It can sometimes be difficult to find
what you are looking for in the table of contents. By double clicking on the View Report step in the task pane, it will
automatically bring you to the corresponding location in the table of contents. By default, double clicking on Analysis
& Synthesis View Report in the task pane will take you to the Analysis & Synthesis Summary report. In the table of
contents, four items down from the summary report is the Resource Usage Summary. Click on this report. You should
see the report in Figure 11.1.
Figure 11.1
Analysis & Synthesis - Resource Usage Summary
This report gives a variety of useful information including the number of LUTs and registers needed, the number
of I/O pins, and the number of memory bits required. This report does not provide information about what percentage
of resources of your selected FPGA are being consumed. To see the percentage, you need to look at the usage report
after it has been placed and routed.
In the Task pane of Quartus, expand the Fitter (Place & Route) step and double click on View Report. You will
see the Fitter Summary Report in Figure 11.2.
Lab 11.1: Details of an FPGA • 167
Figure 11.2
Fitter Summary
This summary shows the number of resources being used by the design on the Cyclone V 5CEBA4F23C7 FPGA.
Notice for this design, the Logic Utilization, Total block memory bits, and Total RAM Blocks usage are all under 1%.
This gives an indication of how vast the resources available are on a modern FPGA.
A more detailed breakdown of the resource utilization can be found in Fitter Resource Section Resource
Usage Summary. Open this report and get a feel for the level of detail that is provided by Quartus for the resource
usage. While, this level of detail is interesting, usually the fitter summary information will suffice for determining how
close a design is to exceeding a device’s maximum capacity.
Go back to the Fitter Summary and take a screenshot of the report (the window similar to Figure 11.2). Save the
image in JPG format with a descriptive file name. This image satisfies the requirements for deliverable #1.
Figure 11.3
Fmax Summary for Slow 1100mV 85C Model
Notice that this report gives Fmax for all clocks in the system. In this design, there are two clocks, Clock_50 and
CLK_div (CLK_div is the signal name within clock_div_prec.vhd). Notice that CLK_div can run faster than Clock_50.
This is likely due to the additional path that the Click_50 signal must traverse to enter the FPGA and be routed to the
clock_div_prec.vhd logic.
Take a screenshot of the Fmax summary. Save the image in JPG format with a descriptive file name. This image
satisfies the requirements for deliverable #2.
Figure 11.4
RTL View of the Top Level of R/W Memory System
In this view you are able to see the major groupings of logic. Any block with a + can be expanded into in order to
see more details of the design. Expand the char_decoder to see how the combinational logic is mapped by clicking on
the “+” on the “char_decoder:C0” block. You will see the RTL view in Figure 11.5.
Figure 11.5
RTL View of char_decoder:C0
170 • Chapter 11: Programmable Logic
Notice that each bit of the 7x output bits of the char_decoder is driven by a multiplexer. This is showing the lookup
table (LUT) approach used to implement combinational logic on FPGAs. Click the icon in the upper left corner of
the RTL viewer to go back to the top level.
Now expand the rw_32x8_sync:RW1 block. You will see the RTL view in Figure 11.6.
Figure 11.6
RTL View of rw_32x8_sync:RW1
The RTL view of the R/W system shows two items of interest. First, the block labeled “RW” is a built in block RAM
(BRAM) within the FPGA. Notice that this block actually has more functionality than our design uses. This includes a
clear (CLR1) and an enable (ENA1). When a VHDL model is created that only uses a subset of the features of a built-
in block within the FPGA, Quartus will automatically wire the unused inputs to logic values so that they don’t impact the
desired functionality. In this case, Quartus wired CLR1=0 and ENA1=1 so they have no effect on our design.
The second item to notice is that to get the rising edge sensitivity for the R/W memory that we designed into our
VHDL model, Quartus needed to attach 8x D-flip-flops to the output of the BRAM. Notice how the FPGA D-flip-flops
also have additional functionality beyond what we typically include in our D-flip-flop model. This includes an enable
(ENA) and a synchronous clear (SCLR). The synchronous clear is different from a reset in that it is only acknowledged
on the rising edge of the clock. The reset on the FPGA is considered a global net, so it is not shown as it is implicitly
connected to all D-flip-flops on the device. Click the icon in the upper left corner of the RTL viewer to go back to the
top level.
Take a screenshot of the top level RTL view (similar to Figure 11.4). Save the image in JPG format with a
descriptive file name. This image satisfies the requirements for deliverable #3. Close the RTL viewer.
Figure 11.7
State Machine View of Control FSM
This view shows the state diagram that Quartus produced based on your FSM VHDL model. This is a useful tool
as it allows you to see how Quartus interpreted the behavior you intended to model in VHDL. If the state diagram does
not match your desired behavior, you have an issue in your VHDL that must be fixed. You can also view the encoding
scheme that the synthesizer chose for your FSM states by clicking on the “Encoding” tab.
Take a screenshot of the state machine view. Save the image in JPG format with a descriptive file name. This
image satisfies the requirements for deliverable #4. Close the state machine viewer.
Figure 11.8
Chip Planner View of Top Level of R/W Memory System
The chip planner shows all of the available logic resources and memory blocks. The logic resources are grouped
into what Quartus called logic array blocks (LABs). These are the light blue rectangles in the chip planner view. There
are also columns of BRAMs (light red) and dedicated hardware blocks for digital signal processing (light yellow). Each
of these blocks can be selected to view the available resources.
The chip planner will highlight any block that is used by the design. In Figure 11.8 you’ll notice there are a handful
of highlighted blocks in the lower right corner of the chip plan. Zoom in on this region using either the zoom icon or by
using the mouse scroll wheel while holding down the CNTL key. As you zoom in, you’ll start to see that each block
contains more resources that are also highlighted if used. Zoom in until you see a block that is used and click on it.
The details of the internal resources will show up in the upper right pane of the chip planner window. You should see
a window similar to Figure 11.9.
Lab 11.1: Details of an FPGA • 173
Figure 11.9
Chip Planner View of Top Level of R/W Memory System (Zoomed)
Doube click on one of the used LABs. A new window will appear that shows the resources within a LAB. You
should see the window in Figure 11.10.
Figure 11.10
Chip Planner Details of Logic Array Block
Within the LAB, you’ll notice that the resources used are again highlighted. Take notice of all of the resources
available. Each LAB contains multiple LUTs (labeled F0, F1, etc.), multiple D-flip-flops, and numerous multiplexers to
174 • Chapter 11: Programmable Logic
handle how the resources are configured. Understanding the FPGA resources at this level can sometimes be exploited
to create more optimized designs.
Take a screenshot of the chip planner view of the LAB (your window similar to Figure 11.10). Save the image in
JPG format with a descriptive file name. This image satisfies the requirements for deliverable #5. Close all of the
chip planner windows. Save your project and close Quartus.
After you are done, close your Quartus project.
CONCEPT CHECK
12.1.1 Objective
This objective of this lab is to give experience implementing adders that are modeled in VHDL. You will create a
4-bit unsigned adder. The inputs for your adder will come from the slider switches on the DE0-CV FPGA board. The
inputs, sum, and carry out will be displayed on the HEX character displays. The inputs and carry will also be displayed
on the red LEDs.
• Design a 4-bit, unsigned adder using the “+” operator from the numeric_std package.
• Type cast between types unsigned and std_logic_vector.
12.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstration of an unsigned adder that displays its inputs, sum, and carry on the displays of the DE0-
CV board (90% of exercise).
2. Provide your top.vhd design file (10% of exercise).
175
176 • Chapter 12: Arithmetic Circuits
Figure 12.1
Block Diagram for the 4-Bit Unsigned Adder System
Figure 12.2 shows a picture of the I/O on the DE0-CV board used in this exercise.
Figure 12.2
Picture of the Unsigned Adder System on the DE0-CV Board
Lab 12.1: Unsigned Adders • 177
Figure 12.3
Entity for the Unsigned Adder System
Take a short video (<5 s) showing the proper operation of your design. You should show a 2-3 additions with at
least one asserting the carry bit. This video satisfies the requirements for deliverable #1.
CONCEPT CHECK
12.2.1 Objective
This objective of this lab is to give more experience implementing adders that are modeled in VHDL. You will
create a 4-bit signed adder. The inputs for your adder will come from the slider switches on the DE0-CV FPGA board.
The inputs and sum will be displayed on the HEX character displays. This will require creating a new decoder that will
drive two HEX displays for each 4-bit input, one for the sign of the number and one for the magnitude
(twos_comp_decoder.vhd). The inputs will also be displayed on the red LEDs. You will also display whether two’s
complement overflow occurred by asserting LEDR(9).
• Design a 4-bit, signed adder using the “+” operator from the numeric_std package.
• Type cast between types signed and std_logic_vector.
• Create a decoder to display the decimal value of a 4-bit signed number on two character displays.
• Create the logic to determine if two’s complement overflow occurred.
12.2.4 Deliverables
The deliverable(s) for this lab are as follows:
1. Demonstration of a signed adder that displays its inputs and sum on the displays of the DE0-CV board
and also indicates whether two’s complement overflow occurred by asserting LEDR(9) (90% of
exercise).
2. Provide your top.vhd design file (10% of exercise).
Figure 12.4
Block Diagram for the 4-Bit Signed Adder System
Figure 12.5 shows a picture of the I/O on the DE0-CV board used in this exercise.
Figure 12.5
Picture of the Signed Adder System on the DE0-CV Board
Lab 12.2: Signed Adders • 181
Hint: Use the “+” operator from the numeric_std package to perform the addition. Be aware the “+” operation is
only supported for types unsigned and signed n this package. This means you’ll need to create internal vectors of type
signed to implement the inputs and output of your adder. You can first type cast your inputs SW(7:4) and SW(3:0) into
your new signed vectors. You can then perform the addition with a resulting sum that are of type signed. You’ll then
need to type cast back the sum from signed to std_logic_vector to drive the HEX displays. Note that when performing
an addition using two’s complement number, the carry is ignored. This means the inputs and sum can both be 4-bits
and the carry is non-existent.
Figure 12.6
Port and Entity Definition for Two’s Complement Character Decoder
Recall that the operation for adding signed numbers is identical to adding unsigned numbers. The only exception
is that the carry bit is ignored. The main difference when using two’s complement numbers is how we interpret and
display them. When the number is displayed on a character display, it takes two displays, one for the sign and one for
the magnitude. For the 4-bit code in this exercise, the decimal symbols to be displayed are {-8, -7, -6, -5, -4, -3, -2, -1,
0, 1, 2, 3, 4, 5, 6, 7}. This type of decoder can be created in a similar manner to your unsigned decoder
char_decoder.vhd. The difference is that the output will drive two, 7-bit ports and the values sent to displays will need
to reflect the decimal symbols corresponding to the 4-bit input. Create the logic for this decoder. Save your file.
Back in your top.vhd, declare the twos_comp_decoder.vhd component. Instantiate it three times. The three inputs
to the decoders will be SW(3:0), SW(7:0), and your internal sum. The outputs will be the six HEX displays. The details
of the signal connections are given in Figure 12.4.
Cycle through the majority of input codes on the slider switches and ensure that the adder is producing the correct
result. When testing the overflow condition, you will want to provide two inputs that result in a sum that is outside of
the range possible for a 4-bit two’s complement code. Examples of these are:
• 7+7=14. Overflow has occurred because 14 can’t be represented with a 4-bit two’s complement code.
• (-8)+(-8)=(-16). Overflow has occurred because 14 can’t be represented with a 4-bit two’s complement
code.
Take a short video (<5 s) showing the proper operation of your design. You should show conditions that have both
positive and negative numbers on the inputs and output and conditions that show no overflow and with overflow. This
video satisfies the requirements for deliverable #1.
CONCEPT CHECK
13.1.1 Objective
The objective of this lab is to gain experience implementing computer systems. You will design and implement a
fully functional, 8-bit, computer system. The computer will be designed incrementally to verify that smaller portions of
the computer are verified before moving onto the next step in the design. Ultimately, the computer will be implemented
on the DE0-CV board.
13.1.4 Deliverables
The deliverable(s) for this lab are as follows:
1. “VHDL Shell” - Provide the 8x VHDL design files that represent the structural shell for the
microcomputer and a screenshot of your simulation transcript verifying that there are no broken
connections (10% of exercise).
2. “Functional Simulation of the Four Basic Instructions” - Provide simulation waveforms that verify the
proper execution of the LDA_IMM, LDA_DIR, STA_DIR, and BRA instructions (40% of exercise).
3. “Implementation of Basic Instructions on the FPGA” – Demonstration of the proper operation of the
LDA_DIR, STA_DIR, and BRA instruction on the DE0-CV Board (20% of exercise).
4. “Additional Instruction Implementation” – Provide simulation waveforms and demonstration of
implementation on the DE0-CV board of additional instructions you wish to include in your computer
(30% of exercise).
183
184 • Chapter 13: Computer System Design
Figure 13.1
Structure of computer.vhd
Lab 13.1: 8-Bit Computer Implementation • 185
Figure 13.2
Structure of cpu.vhd
186 • Chapter 13: Computer System Design
Figure 13.3
Structure of memory.vhd
before any behavioral modeling is inserted in the architecture. Compiling your models will reveal any syntax errors in
your structure. Running a simulation will load all of your files and check that each component call has the appropriate
port mappings. The simulation will not have any waveform outputs, but it will verify there are no port mismatches in
your structure. This will allow you to get all of your connections correct before moving onto the behavioral modeling of
the computer. The simulation will only run if all of the component port mappings are correct. Once the simulation runs
successfully, you will get a message in the transcript window similar to Figure 13.4. You will get a series of warnings,
but that is OK for now. If there is a port mapping mismatch, you will get an error loading the design and text describing
where the mismatch is.
Figure 13.4
Transcript Window for Computer System showing Successful Load
Run the simulation on your VHDL shell using the computer_TB.vhd test bench provided. Fix any errors you
encounter. Take a screenshot of your transcript window indicating that the simulation loaded successfully (just like
Figure 13.4). Save the screenshot in JPG format with a descriptive name. This screenshot image and your eight
VHDL files created in this part satisfy the requirements for deliverable #1.
Figure 13.5
Memory Map for the 8-Bit Computer System
Figure 13.6
State Diagram for the LDA_IMM Instruction
190 • Chapter 13: Computer System Design
Figure 13.7
Simulation Waveforms for the LDA_IMM Instruction
Figure 13.8
State Diagram for the LDA_DIR Instruction
192 • Chapter 13: Computer System Design
Figure 13.9
Simulation Waveforms for the LDA_DIR Instruction
Figure 13.10
State Diagram for the STA_DIR Instruction
194 • Chapter 13: Computer System Design
Figure 13.11
Simulation Waveforms for the STA_DIR Instruction
Figure 13.12
State Diagram for the BRA Instruction
196 • Chapter 13: Computer System Design
Figure 13.13
Simulation Waveforms for the BRA Instruction
Take screenshots of each of the four simulation waveforms verifying that each instruction is executing as expected.
These should look very similar to Figure 13.7, Figure 13.9, Figure 13.11, and Figure 13.13. Save the screenshots in
JPG format with descriptive names. These four screenshot images and the three relevant VHDL files
(memory.vhd, data_path.vhd, and control_unit.vhd) satisfy the requirements for deliverable #2.
Lab 13.1: 8-Bit Computer Implementation • 197
Figure 13.14
Top-Level for Computer System Implementation on the DE0-CV Board
198 • Chapter 13: Computer System Design
You should create a program that continually reads from SW(7:0) and writes to LEDR(7:0), HEX(1:0), HEX(3:2),
and HEX(5:4). You can accomplish this using the instructions you have already implemented in part 3. Note that the
FPGA block diagram uses your clock_div_prec.vhd with select lines coming from SW(9:8) instead of SW(1:0) as in
prior labs. Also notice that the character decoders are instantiated outside of the computer system.
Take a short video (<5 s) showing the proper operation of your design. You should run your clock at 10 Hz so that
it is noticeable that a change on the slider switches doesn’t appear on the LEDs and HEX displays instantaneously due
to the way the computer instructions are executed as a series of states. This video and your top.vhd file satisfy the
requirements for deliverable #3.
ALU Instructions
CONCEPT CHECK