Lab 2
Lab 2
Laboratory Exercise 2
Introduction to Verilog/Testbench
I. Objectives
Verilog is a hardware description language that describes the behavior of circuits. In this
laboratory, we are aimed to introduce Verilog and give some examples as exercise.
sum ab
overflow
1
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
2
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
Step 3: Search xc7a35tlcsg324-2L
1. Click “Next” three times
2. Search “xc7a35tlcsg324-2L”
3. Click “Next” and “Finish”
3
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
3. Select “Add or create design sources” → “Next” → “ADD Files” → “Source”
→ ”dont touch” → “Seg_7_Display.v” and ” lib.v” → “OK”
4. “ADD Files” → “Source” → “FA.v” and ” adder4.v” → “OK” → “Finish”
2
3
4
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
Step 7: PROJECT MANAGER, Add Simulation Source
1. In this step, you will add your simulation testbench file(.v) to Vivado. Simulation
Testbench files can test the correctness of your design
2. Click “Add Sources” under Project Manager
3. Select “Add or create simulation sources” → “Next” → “ADD Files” → “Source” →
.. → “dont touch”→ Select “tb_FA.v” → “OK” → “Finish”.
5
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
Step 8: Complete full adder.v (you only can use logic gates in lib.v)
1. Select “Hierarchy” under Sources -> “Design Sources” -> “f0:FA” under adder4
2. Complete FA.v by using verilog in gate-level
Reference your exercise C2. Just use logic gates to implement 1-bit full adder
6
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
3. Click “Run Simulation” under SIMULATION -> Run Behavioral Simulation
(Some antivirus softwares will block this operation. If so, shut down the software)
4. Select “Untitled 1” to see waveform. You can press “zoom fit” to see the whole
waveform
5. If correct signal is 1, it means your design is correct. Then you can go to the next step;
otherwise, you have to modify your “FA.v”
zoom fit
7
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
Step 10: Complete 4-bit ripple carry adder
1. Select “Hierarchy” under Sources -> “Design Sources”
2. Right click “adder4.v” -> Select “Set as Top” (If adder4.v is already a Top design, you
don’t need to do this)
3. Complete “adder4.v”. Connect four 1-bit full adders to implement a 4-bits full adder
8
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
Step 11: Generate Bitstream
1. Click “Generate Bitstream” under PROGRAM AND DEBUG. This includes synthesis
and implementation.
2. Click “Yes” and “OK”. Wait for Vivado running Design Flow (It may take some time).
3. If design flow is completed, the status of Synthesis and Implementation will show
“Complete” , and then it will pops out “Bitstram Generation Completed” window
(You can ignore all warnings in this step)
4. Select “Open Hardware Manager”, and then press “OK”.
9
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
Step 12: Program into FPGA
1. Press “Open Target”, and select “open new target”
10
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
4. Click “Program device”
5. Find your bit file. If no files, please find [Project_name].runs/impl_1/adder4.bit
6. Press “Program”.
11
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
a b cinc cout
carry sum
sum 0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
FA
0 1 1 1 0
cout cin 1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
a b
sum =
12
Electronic Circuits Experiment Department of Electrical Engineering
National Taiwan University
P2.Circuit diagram of FA
Use logic gates to draw a circuit that implements the function of the Boolean algebra you
write in problem 1. (Note: you can only use logic gates in lib.v )
Ans:
P3.Implement a one-bit FA
Implement a one-bit full adder in Verilog. (Finish Step 8 and paste your code in your
report)
P4.Plot waveform of your design
Use testbench and vivado to check the waveform of your design. (You can take a photo
in Step 9 to prove your design is correct!)
Ans:
13