VGU ECE DSDL Lab1 FundamentalsofLogicGates
VGU ECE DSDL Lab1 FundamentalsofLogicGates
Revision
Version Modified date Modified by Description
v0r0 03/02/2023 Thuyet N. New creation
Description
This lab is to design and implement the basic digital circuits (parity circuit, adders, counters etc.) on
an FPGA board by Verilog HDL (hardware description language).
Hardware
Files: Quartus lite + ModelSim-IntelFPGA setup files, Cyclone IV and Cyclone V device files
Note: Put all files in the same folder and then run Quartus set-up file.
LabDocs:Lab guidelines
Preparation:It has to be finished before each lab session
RefDocs:References
1) 00_fpgas_for_dummies_ebook.pdf: an book for beginners
2) 01_VGU_ECE_BasicsofFPGAandVerilog.pdf: basics of FPGA and Verilog HDL
3) 02_VGU_ECE_DigitalSystemsDesignLab_slides.pdf : introduction slides
4) 04_DE10-Nano_User_manual.pdf: hardware manual
Lab content
Important note:
This lab exercise helps students be familiar with FPGA design flow on Quartus tool by
implementing simple logic gates (AND, OR, XOR, NOT etc.). Besides, students learn how to design
an even parity circuit (generator+checker) with exclusive-OR (XOR) gates.
Prerequisite
Logic gates
x y
0 1
1 0
NOT gate
x y z
0 0 0
0 1 1
1 0 1
OR gate
1 1 1
x y z
0 0 0
0 1 0
AND gate 1 0 0
1 1 1
x y z
0 0 0
0 1 1
Ex-OR (XOR) gate 1 0 1
1 1 0
Based on the above truth tables, it can be easily seen that the output of an XOR gate is equal to ‘1’
only if a number of bits ‘1’ at inputs are an odd number. In conclusion, with XOR gates, a
number of bits ‘1’ at inputs and outputs are always an even number.
A parity circuit is used to generate an even/odd parity bit at a transmitter as well as to check data
correctness at a receiver. In this lab, an even parity circuit is considered.
From the generator side, the four-bit data is input to a 4-bit input XOR gate to generate an even
parity bit. The output value is calculated based on the below table.
Then, the four-bit data and parity bit are transferred to the receiver (parity checker).
Run Quartus
File → New Project Wizards… → Next
This step is to choose the location for the project as well as to set the project and top module name.
And click Next t→ Next → Next to go to the step of selecting FPGA device of DE10-Nano board
An empty Quartus project has been created, next the implementation of the logic gates is introduced.
This process includes following steps:
1) Make design documents for the logic (see the theory)
2) Write Verilog HDL code
3) Compile the code
4) Run simulation
5) Board test
a. Do pin assignments
b. Generate bit stream file
c. Program bit stream file to FPGA
d. Run and test
To write Verilog HDL code for logic gates, a ‘.v' file needs to be created by clicking File →
New→Verilog HDL File
lab1.v
module lab1(
x,
y,
z
);
input x;
input y;
output z;
assign z = x&y;
endmodule
From Simulation Waveform Editor window, click Edit → Insert → Insert Node or Bus
(If you cannot see any signals in Nodes Found, please run Compilation first)
Error (suppressible): (vsim-12110) The -novopt option has no effect on this product. -novopt option is
now deprecated and will be removed in future releases.
# Error loading design
Error loading design
lab1.v
module lab1(
x,
y,
z
);
input x;
input y;
output z;
assign z = x&y;
endmodule
Open DE10 user manual to find pin values of SW0, SW1 and LED0 to assign to the and gate pins
Choose LED0 (PIN_W15, refer to DE10-nano User Manual) to assign to and gate ‘z' pin.
To do pin assignments for counter, click Assignments → Assignment Editor, and complete the
table as below:
DC Power
HDMI
Click Hardware Setup… at the left conner, selection DE-SoC[USB-1] for Currently selected
hardware and click Close.
Right click on line 5CSEBA6 → Change File, double click on ‘output_files' folder, select lab1.sof
Check on Program/Configure column as below picture and the press Start button to
load bit file to FPGA
When finishing uploading a bit stream file, the process bar will show 100% successful.
After finishing the implementation of AND gate, execute the same steps to implement NOT, OR
and XOR.
Design
Block diagram
[Simulation]
evenparity_gen.v
module evenparity_gen(
din,
pout
);
output pout;
endmodule
evenparity_checker.v
module evenparity_checker(
din,
pin,
p_err
);
endmodule
parity.v
module lab1(
din,
p_err,
p_out
);
//port declaration
//signal declaration
// logic implementation
evenparity_gen evenparity_gen_00(
.din(din),
.pout(p_out)
);
evenparity_checker evenparity_checker_00(
.din(din),
.pin(p_out),
.p_err(p_err)
);
endmodule
evenparity_gen.v
module evenparity_gen(
din,
pout
);
output pout;
endmodule
evenparity_checker.v
module evenparity_checker(
din,
pin,
p_err
);
endmodule
parity.v
module lab1(
din,
p_out
p_err
);
//port declaration
output p_out;
output p_err;//0: no error; 1: error
//signal declaration
// logic implementation
evenparity_gen evenparity_gen_00(
.din(din),
.pout(pout)
);
evenparity_checker evenparity_checker_00(
.din(din),
.pin(p_out),
.p_err(p_err)
);
endmodule
No Description Completed
1 Create an empty Quartus project for task 1
2 Implement task 1
3 Simulate task 1
4 Test logic of task 1 on FPGA board (board test)
5 Create an empty Quartus project for task 2
6 Implement task 2
7 Simulate task 2
8 Test logic of task 2 on FPGA board (board test)