SKEE2263 Mini Project Guide
SKEE2263 Mini Project Guide
Release 2020
Mun’im Zabidi
Administrivia
Objectives of the Mini-Project
■ To build a complete digital system design containing a datapath unit and control unit
■ To perform top-down design and bottom-up implementation of a digital system
■ To implement and test the design on a FPGA/CPLD board with all relevant I/O devices
■ To manage a team project with the aid of a Gantt Chart
The mini project contributes 30% of your overall marks. At the end of semester, you must
implement a complete digital system a FPGA/CPLD board. To ensure you successfully complete
the project, the mini project has six different stages, so that you build the complete system
incrementally. The following Gantt Chart outlines the tasks.
Project Scheduling
Lecture Weeks
Milestone Deliverable
1 2 3 4 5 6 7
1 Quartus familiarization
2 CPLD familiarization
3 Basic Input/Output
4 Finite State Machines
5 Datapath Unit
6 System Integration & Demo
What to Submit
1. Plagiarism Declaration — hardcopy
4. References — hardcopy
Required Equipment
Equipment Source
Quartus II Download at http://fpgasoftware.intel.com/13.0/?edition=web
EPM240 CPLD board
Ask your lecturer or find on Internet
USB Blaster
DuPont wires
Breadboard
LEDs Should be easy to find locally
DIP switches
Resistors
i
Tutorials
Application notes at http://raden.fke.utm.my/appnotes.
Additional Instructions
1. Your circuit must be modular
2. PLO8 Compliant
3. PLO11 Compliant
ii
PLAGIARISM DECLARATION
1. I know that plagiarism means taking and using the ideas, writings, works or inventions of
another as if they were one’s own. I know that plagiarism not only includes verbatim copy-
ing, but also the extensive use of another person’s ideas without proper acknowledgement
(which includes the proper use of quotation marks). I know that plagiarism covers this sort
of use of material found in textual sources and from the Internet.
3. I understand that my research must be accurately referenced. I have followed the rules and
conventions concerning referencing, citation and the conventions concerning referencing
and citation.
4. This assignment is my own work, or my group’s own unique group assignment. I acknowl-
edge that copying someone else’s assignment, or part of it, is wrong, and that submitting
identical work to others constitutes a form of plagiarism.
5. I have not allowed, nor will I in the future allow, anyone to copy my work with the intention
of passing it off as their own work.
Team Name
Name
Matric Number
Signature
Date
Name
Matric Number
Signature
Date
Name
Matric Number
Signature
Date
iii
MILESTONE 1
Quartus Familiarization
Objectives
■ Familiarization with Altera Quartus for entering, compiling and simulating a logic design.
■ Describing a complex digital system using hierarchy, modularity and regularity
■ Creation of several low-level reusable subsystems to build a module library
Pre-Requisites
Download and follow the Quartus checkout procedure in Application Note AN03 Getting Started
with Quartus:
http://raden.fke.utm.my/appnotes/AN03%20Getting%20Started%20with%20Quartus.pdf
1.1.1 Half-Adder
Step 1
Step 2
Compile the design. If there are no errors, print compilation report as PDF.
Step 3
Simulate by giving all 4 input combinations for a and b : 00, 01, 10 and 11. Maintain each input
combination for 100ns. That means the End Time for the simulation should be 400ns. Check the
result with the expected output. When the circuit is error-free, proceed to Step 4.
Step 4
1
Milestone 1 Quartus Familiarization
Step 5
Print the following 3 pages as PDF. You must choose landscape orientation.
Page 1: Schematic of half adder: Printscreen then convert to PDF.
Page 2: Compilation report
Page 3: Annotated simulation output waveform: This is not the same as the simulation input.
Printscreen first, then in MSPaint or similar software, highlight the important information. Save
as PDF.
Use Quartus schematic entry to input two instances of half adder symbols from Part 1 Step 4.
Combine the two half adders with an or2 gate to build a full adder.
Half adder
Half adder
ai
bi si
c i+1
ci
Step 2
Compile the design. If there are no errors, print compilation report as PDF.
Step 3
Simulate using all 8 input combinations 000 through 111. Maintain each input combination for
100ns. That means the End Time for the simulation should be 800ns. Check the result with the
expected output. When the circuit is error-free, proceed to Step 4.
Step 4
Step 5
Print the following 3 pages as PDF. You must choose landscape orientation.
Page 4: Schematic of full adder..
Page 5: Compilation report
Page 6: Annotated simulation output waveform..
2
1.1 4-bit Ripple Carry Adder
Use Quartus schematic entry to input four instances of full adder symbols from Part 2 Step 4.
Combine to build the ripple carry as follows.
a3 b3 a2 b2 a1 b1 a0 b0
FA FA FA FA
c4 c3 c2 c1 c0
s3 s2 s1 s0
Step 2
Compile the design. If there are no errors, print compilation report as PDF.
Step 3
In Table 1.1, fill in columns COU T and S[3 : 0] so you know what is the expected output for each
input combination. Columns A, B and S are in hex.
In the simulation waveform input, use bus groups for A, B and S signal. (A bunch of related
signals are called a bus.) Use hexadecimal system. Simulate using the given test data. Then mark
with the adder complies with the expected results. Simulate using the 10 input combinations
given below. Maintain each input combination for 100ns. That means the End Time for the
simulation should be 1000ns. When the circuit is error-free, proceed to Step 4.
Step 4
Print the following 4 pages as PDF. You must choose landscape orientation.
Page 7: Schematic of ripple carry adder..
Page 8: Compilation report
3
Milestone 1 Quartus Familiarization
Step 5
Combine all 10 PDF pages into 1 PDF document. Add the plagiarism declaration as the front
cover. Upload to elearning.utm.my.
4
1.2 Bus Multiplexer
4. Convert the module into symbol file. Call it busmux4bit.bsf. It should like Fig. 1.6.
5
Milestone 1 Quartus Familiarization
6
1.3 Data Register
4. Convert the module into symbol file. Call it reg4bit.bsf. It should like Fig. 1.11.
7
MILESTONE 2
CPLD Familiarization
Objectives
■ Getting started with EPM240 CPLD
■ Familiarization with various methods of design entry
■ Creation of more modules for design reuse
2.1 Pre-Requisites
Download and follow the EPM240 Board checkout procedure in AN04 EPM240 Board:
http://raden.fke.utm.my/appnotes/AN04%20EPM240%20Board.pdf
After going through the example in AN04, you should get a blinking LED driven by the EPM240
CPLD.
VDD
50 1 Hz 4 10
mapper
We will create all low level modules first. Afterwards, they are integrated at the top level
schematic diagram.
9
Milestone 2 CPLD Familiarization
Section Objective
Using the Library of Parameterized Modules (LPM) in the block diagram/schematic editor.
2. Save the blank file as knightrider (or milestone2 etc) and set it as Top-Level Entity.
3. Call up the New Symbol dialog and type lpm_counter in the Name field.
4. On Page 2c, click Next > .
5. On Page 3, set the width of the ’q’ output bus to 4 bits. Click Next > .
6. On Page 4, set counter type to Modulus, with a count modulus of 10. Click Finish .
7. On Page 7, click Finish .
10. Add a bus at the output of the counter and label it q[3..0]. Refer Figure 2.3.
10
2.4 BCD Decoder
Section Objective
Using traditional TTL IC equivalent symbols in the block diagram/schematic editor.
A 7442 BCD decoder has 10 outputs and accepts a value in the range of 0..9. The output is active
low. A value greater than 9 causes all outputs to be high.
1. Still in the schematic diagram from Section 2.3, call up the New Symbol dialog and type
7442 in the Name field.
2. Add regular wires to all inputs of the 7442. Label the inputs as q0, q1, q2, and q3. The BCD
counter is now connected to the BCD decoder. Refer to Figure 2.5.
11
Milestone 2 CPLD Familiarization
2.5 Mapper
Section Objective
Design entry using primitives.
.
Figure 2.6: Mapper schematic.
4. Save it as mapper.bdf.
Figure 2.7: Mapper symbol. Note: you can see this symbol by opening another block diagram document and
importing it.
12
2.6 Simulating the Circuit
Section Objective
Simulating a partially-complete circuit.
2. Insert the mapper symbol and connect with the 7442 BCD decoder.
3. Add one input port to the BCD counter, and 6 output ports from the mapper.
The top level schematic should look like Figure 2.8.
7. Using the default setting for end time, set the clock period so that you can see at least 10
clock cycles in the simulation window. You should see something like Figure 2.9.
8. Save a copy the top-level bdf file so that you have two copies of the same file. Give them
distinct names such as knight_partial.bdf and knight_final.bdf or something similar. Keep
the first file as a “fallback” schematic in case something goes wrong when you add extra
modules later. Modify only the second file in the following steps.
13
Milestone 2 CPLD Familiarization
2.7 Prescaler
Section Objective
Design entry using Verilog HDL.
The prescaler module slows the clock from 50 MHz to exactly 1 Hz.
2. Save as prescaler.v.
Figure 2.10: Prescaler symbol. Note: you can see this symbol by opening another block diagram document
and importing it.
5. In the top-level schematic diagram, add the prescaler module. The circuit now look like
Figure 2.11. Set the top-level module back to this diagram.
Note
After the prescaler is added, the circuit can no longer be simulated.
14
2.8 Programming the CPLD
Section Objective
Programming the CPLD.
1. From the Assignments å Device menu verify that you have chosen the EPM240T100C5
device.
3. Assign 6 more pins for the output ports. You can use any I/O bank. For example, you can
use the settings from Figure 2.13 to use pins closest to ground pin on the EPM240 connector
block. However, any other combination can be used.
(The two I/O bank can theoretically use different supply voltages for interfacing. On the
red EPM240 board, this is not possible because the power supply rails are tied together.
Therefore, any I/O bank can be used.)
4. Recompile the design. After recompilation, the assigned pins should appear at the top level
schematic. The final schematic should be like Fig. 2.14.
15
Milestone 2 CPLD Familiarization
16
MILESTONE 3
Accumulator Based Vending Machine
Objectives
Implement a vending machine simulator illustrated in Fig. 3.1 on CPLD and circuit board. The
major components are:
The vending machine is based on a 4-bit accumulator which keeps tracks of how much money
has been deposited. The accumulator value equals multiples of 10 sens. It has two button inputs:
button 1 for 20 sen, button 2 for 50 sen. Pressing a button adds 2 or 5 to the accumulator.
The 7 segment display shows the current value of accumulator in BCD up to 15. When the
accumulator contains 12 or more, the Knight Rider LEDs (from Milestone 2) will display one round
of lights (as opposed to unlimited rounds in Milestone 2).
Implementation steps:
1. Prepare all modules in Table 3.1. Simulate all independently, except the prescaler (module
4).
2. Integrate/combine all modules, except the prescaler, and simulate.
3. Prepare an I/O board consisting of two seven-segment displays, and two switches and
the necessary resistors. It is highly recommended to use a stripboard for the 7-segment
display to avoid connectivity problems. The switch can be on the same stripboard or on a
breadboard; it is less critical due to fewer wires required.
4. Add the prescaler, connect the I/O board with the CPLD and program the CPLD.
The following sections describes the module functions, grouped by level of reuse.
17
4
3.3V 7
SW1 4 4 4
Accumulator Binary-to-BCD
7
Input filter
3.3V 4 Clear
Milestone 3 Accumulator Based Vending Machine
Selector 3.3V
SW2
Input filter
4
A Knight
A>B
Comparator Rider
4
1011 B lights
CLK2(approx.100Hz)
50MHz Prescaler
CLK1(approx.1Hz) DONE
Figure 3.1: Block diagram of vending machine
18
3.2 Modules from Previous Milestones
3.2.1 Adder
The 4-bit ripple carry adder from Milestone 1 can be used directly without modification. No
simulation is necessary for this circuit as it is completely reusable.
3.2.2 Accumulator
The procedure to build the accumulator from Milestone 1 can be followed. However, the function
is different. In this accumulator, the control line is called Clear.
Clear Function
0 Loads data at D0-D3
1 Register is cleared (Q←0) on next clock edge
D3 D0
D Q D Q
Clear
Clk
Q3 Q0
Figure 3.2: First and last cells of the register with synchronous clear.
Build and simulate one cell first. Then combine 4 cells to build the accumulator. Show the
compilation report, schematic and simulation of the 4-cell accumulator only.
■ Add a control signal circuitry to enable/disable the lights, so that the LEDs runs only when
this input is high.
■ Add a status signal (DONE) that indicates when the lights have run a complete round.
Simulate to check if the circuit can be enabled/disabled on demand, and the DONE is activated
at the correct time.
3.2.4 Prescaler
This prescaler generates two outputs:
■ CLK1: a signal approximately 1 Hz. This speed is required so that the Knight Rider light can
run slowly and visible to humans.
■ CLK2: a signal approximately 100Hz. This speed is required to eliminate contact bounce
that happens when a button is pressed.
Implement the prescaler using a 26-bit up counter from LPM_COUNTER. Use bit 25 as CLK1
and another bit as CLK2. Do not use the Verilog version.
Do not simulate the prescaler. Do not integrate it with the main system yet. We will add it at the
final construction stage.
19
Milestone 3 Accumulator Based Vending Machine
3.3.1 Comparator
The comparator gives a high output when the accumulator contains a value more than 11.
Choose a combinational or iterative comparator from Section 6.4. For the comparator, show the
compilation reports, schematics and simulation.
d4 to segments b, c
d4
0
d3
b3
cadd3 d2
b2 7-segment codes
d1 7447
b1 to ones display
b0 d0
pulse out
switch in D Q D Q
100 Hz
You will need two copies of the filter, one for each button. The buttons are active low, meaning
that it is high when not pressed, and low when pressed. The circuit is Fig. 3.4 produces a single
pulse when a high-to-low transition is detected at its input.
20
3.4 Selector
3.4 Selector
The adder add the current value of the accumulator (first input) and the value chosen by the
selector circuit (second input). The selector chooses a value to place at the second adder input
based on this table:
The selected value is presented for exactly one clock cycle for every button press. This is a
combinational circuit which your team must design.
21
MILESTONE 4
Finite State Machines
Objectives
■ Basics of finite state machine
4.1 Preliminaries
Read the following application notes
After the LEDs have finished running, the machine returns to the intial state. Do not reset the
CPLD to return to the initial state.
1. On paper, sketch the state diagram to detect the sequence given to your group. Solve it
using both Moore and Mealy approaches. Keep this sketch as your documentation.
2. Enter one state diagram (either Moore or Mealy) using the State Machine Editor in Quartus.
5. When simulation is successful, add the Input Filter, Prescaler and Knight Rider (from
Milestones 2 and 3).
23
Milestone 4 Finite State Machines
7. Test it. The Knight Rider lights should run once when the correct sequence is entered on
the pushbuttons.
If you’re submitting the milestone by video, record the process of building and testing this circuit.
Show that entering the correct button sequence turns on the Knight Rider.
1. Based on the Moore version of the state diagram, get the next state equations and output
equation.
1. Based on the Mealy version of the state diagram, derive the state table. Use straight/se-
quential binary encoding.
24
MILESTONE 5
Datapath Unit Implementation
Objectives
For Milestones 5 and 6, each group will be specified a complex digital system. The options are
in Table 5.1. The list is not exhaustive. Your lecturer may have extra topics available. You can also
propose your own topic.
The steps for building the datapath for a naïve multiplier is shown in this handout. Follow the
same procedure for the circuit assigned to you.
Every datapath unit solves an algorithm. Writing the algorithm in C lets us simulate the algorithm
at a very high level to verify its correctness.
Evry CU+DU has a different algorithm. Although the top-level function is the same, the circuits
to solve the function can be very different.
Multiplication in digital systems can be done many ways. The naïve method is by repeated
25
Milestone 5 Datapath Unit Implementation
0 + 2 + 2 + 2 + 2 + 2 = 10
P = 0;
while ( N != 0) {
P = P + M;
N = N - 1;
}
return P ;
}
CU
Go Valid
Init Work Zero
DU
M 4 A[7..4]
0000
A
Init Load A[3..0] 8
M + P
Init Clear
4-bit Register B Work Load
N
Zero
8-bit Adder
P
4
8-bit Accumulator
Init Load
Work Count 4
N 8
4-bit Down counter
26
5.2 Identify and Construct the Building Blocks
■ Adder
Extend the adder from Milestone 1 from 4 bit to 8 bit.
■ M register
4-bit register with enable. This register must have 4-bit input, 4-bit output and Load control
input.
■ N register
This “register” is actually a 4-bit down-counter with load capability. The register must
have 4-bit data input, Load control input, Count down enable input and Zero output. The
Zero output is high when the counter reaches 0000. The actual value of the register is not
important except for debugging.
■ P register
8-bit register with enable. This register must have 8-bit input, 8-bit output and Load control
input.
Design and build each component and test independently. This is a design course. As a digital
designer, you are expected to be able to design each module yourself, individually. You are free
to use lpm built-in modules, create your own module using schematics or write Verilog code to
implement the modules.
5.3 Integration
lpm_ff1 lpm_add_sub0
DFF
M[3..0] INPUT
VCC data[3..0] dataa[7..0] acc
d[3..0] A
clock result[7..0] OUTPUT P[7..0]
q[3..0] d[7..0] A+B D[7..0] Q[7..0]
enable datab[7..0]
B Load
inst3 d[7..4] inst
Clear
Clock
GND
inst4
Clock INPUT
VCC
lpm_counter0
down counter
Init INPUT
sload
VCC
N[3..0] INPUT
data[3..0]
VCC
inst5
Figure 5.2: Naive multiplier datapath. The signal group Q[3..0] shows the current value of the counter. It is
not used in the final system because the controller only needs to know whether the counter has
reached zero (cout=Zero=1).
27
Milestone 5 Datapath Unit Implementation
Figure 5.3: Simulation of naive multiplier datapath. The Work signal enables the counter to count down and
the acccumulator to load a new value. When the controller is added later, Work can be stopped
automatically when Zero = 1.
28
MILESTONE 6
Controller Implementation
Objectives
■ Implementing the control unit to manage the datapath unit from the previous milestone
■ Integrating the control unit with the datapath unit
■ Demonstrating the complete system in hardware
6.1 Procedure
Fig. 6.1 illustrates the procedure for controller design.
State Machine
Editor
One-hot controller
Verilog
Text Editor
VHDL
■ Algorithm describes the problem at high level. This is usually given as C code fragment or
pseudo-code.
■ High-level ASM converts the algorithm to an ASM chart that closely follows the algorithm
using the Register Transfer Language (RTL) notation. All variable names used in the
algorithm are maintained.
■ Low-level ASM replaces the RTL statements to control and status signals as defined in the
datapath unit.
■ The controller is finally implemented using one-hot or one of the highly encoded state
assignments. For full marks, submit a implementation based on the one-hot approach. For
quick prototyping and for partial marks, you can use the State Machine Editor. The highly
encoded state assignment is not recommended because the large number of inputs to the
next state logic.
29
Milestone 6 Controller Implementation
Reset
S0
0
Go
1
0
P ← 0,
M ← multiplicand, 1
N ← multiplier Go
S1 S2
P←P+M
Valid ← 1
N←N-1
0 1
N=0
Reset
S0 001
0
Go
1 0
1
Init Go
S1 010 S2 100
Work Valid
0 1
Zero
From the low-level ASM chart, you can complete the design directly or you can experiment with
State Machine Editor for first.
30
6.3 Low-Level ASM
S 0+ = S 0 · Go0 + S 2 · Go0
S 1+ = S 1 · Zero0 + S 0 · Go
S 2+ = S 1 · Zero + S 2 · Go
Init = S 0 · Go
Work = S 1 · Zero0
Valid = S 2
The controller can now be entered using the schematic editor. The result is shown Fig. 6.4.
Go
S0
+
S0 S0 Init
D Q
S2
S0
+
S1 S1
D Q
S1 Work
S1
+
S2 S2
D Q Valid
S2
Zero
Clock
Figure 6.4: Controller for naïve multiplier. The inverted first flip-flop method is used to automatically start the
one-hot controller upon power-on-reset.
31
Milestone 6 Controller Implementation
inst
datapath
Figure 6.6: Simulation of 4 × 3 and 15 × 7 at the module level. Annotations helps the reader look at the
important parts of the waveform.
32
6.5 Demonstration
6.5 Demonstration
After the simulations have shown the circuit to work correctly, add the necessary input and output
modules such as in Fig. 6.7. The number of DIP switches and LED displays depends on the bit
width used in your particular circuit.
3.3V
Go 1 EPM240
board 7
A Result displayed
Operand1 4
in hex or decimal
B 4
7
Operand2
Figure 6.7: Demonstrating the CU+DU with decimal output. Shown here, A = 4, B = 3 and P = 4 × 3 = 12.
To demonstrate, enter the operands using the DIP switches, and press Go. After some
processing, the output should be visible on the displays. You may want to use a slow clock so
that intermediate results can be made visible.
You can also use the hexadecimal number system to display the output. For example, the
biggest value generated by the multiplier is 15×15 = 225 which requires three digits in decimal, but
only two digits in hexadecimal. However, you must replace the 7447 decimal-to-seven-segment-
display code converter with your own converter.
33