Foundation Verilog Course Exercises Manual_ver2.0
-
Upload
junaid-asad -
Category
Documents
-
view
47 -
download
3
Transcript of Foundation Verilog Course Exercises Manual_ver2.0
Comprehensive Verilog Course
Lab Manual v 2.0
Conducted by: Dr. Waqar Nabi / Nida Rasheed
Prepared by: Sohaib Ayyaz Qazi / Waqar Nabi
Page | 2
Session 1:
This lab session is designed to familiarize you with the use of the Xilinx ISE 10.1. After this lab you should be able to design a verilog module, synthesize it and simulate in Xilinx ISE 10.1.
Exercise 1.1: Getting Started
In this exercise you are going to start using Xilinx ISE 10.1. The top level modules and the testbench for exercise 1.1 are provided so that you can easily explore the Xilinx tool.
counter.v is a top level module, it is a 4 bit counter that counts from 0 to 15 and goes back to zero. testbench_counter.v is a testbench to test the counter.
Exercise 1.2: Design Half Adder
Complete the following steps
1. Complete/write the half adder module that was described in the lecture. The diagram of half adder is shown in figure 1.1.
Figure 1.1: Half Adder
2. Write a testbench for the half adder. 3. Check and verify the results for the counter.
Page | 3
Session 2:
In this session you will cover module and ports, primitives and gate‐level modeling, testbench, data types and hierarchy.
Exercise 2.1: Multiplexer 4‐to‐1
1. Complete the 4 to 1 multiplexer module that was described in the lecture. The diagram of multiplexer is shown in figure 2.1.
c_out
sum
Mux32_4_1data_3
data_4
c_out
s0
data_2
32
32
32
32
s1
data_1
32
Figure 2.1: Multiplexer 4‐to‐1
2. Write the testbench for the multiplexer. 3. Check and verify the results for the multiplexer.
Exercise 2.2: 4‐bit Ripple Carry Adder
Design a 4‐bit ripple carry adder according to the conditions specified in figure 2.2.
Figure 2.2: 4‐bit Ripple Carry Adder
Exercise
A 2‐bit cwhether Complete
1. Win
2. W
2.3: 2‐bit bi
comparator the decimae the follow
Write the codn figure 2.3. Write the tes
nary compa
compares tl equivalent ing steps
Fig
de for 2‐bit tbench for t
arator
two bit binaof word A is
gure 2.3: 2‐b
comparator
the top level
ary words, As less than, g
bit Binary Co
r using gate
l module and
A and B, angreater than
omparator
level mode
d verify the
d asserts oun, or equal to
ling, block d
results.
Pag
utputs indico that of wo
diagram is sh
ge | 4
cating ord B.
hown
Page | 5
Session 3:
In this session you will learn simulation control, behavioral modeling using continuous assignment, and procedural blocks for combinational logic.
Exercise 3.1: Behavioral models of 4‐to‐1 Multiplexer
As you have completed the lab exercise 2.1 now you have to design same 4‐to‐1 multiplexer using the behavioral modeling. Complete the following steps
1. Design 4‐to‐1 multiplexer using continuous assignment statements. 2. Design 4‐to‐1 multiplexer using always @ module. 3. Test and verify the results of both modules using the testbench of exercise 2.1.
Exercise 3.2: Full Subtractor using Boolean Equations
A full subtractor has three 1‐bit inputs x, y, and z (previous borrow) and two 1‐bit outputs D (difference) and B (borrow). The logic equations for D and B are as follows:
D = x' . y' . z + x' . y . z' + x . y' . z' + x . y . z
B = x' . y + x'.z + y.z
1. Write the full Verilog description of the full subtractor module, including I/O ports. 2. Instantiate the full subtractor inside a stimulus and test all possible inputs and verify
them from the table 3.1. Table 3.1: Truth table for full subtractor
x y z B D0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1
Page | 6
Exercise 3.3: 4‐bit Adder using dataflow operators.
In this lab you will design the dataflow description of the 4‐bit adder.
1. Write the verilog code for 4‐bit full adder using dataflow operators. 2. Write the testbench for the verilog module. 3. Verify the results.
Exercise 3.4: 1‐to‐4 de‐multiplexer.
You have designed the multiplexer in exercise 2.1. Now you have to De‐Multiplex the data. It takes
a single input and two selection inputs and sends the input data to a single line depending of the values of the selection inputs.
1. Write verilog code for the De‐multiplexer using assign statements. 2. Write verilog code for the De‐multiplexer using always.
Figure 3.1: 1‐to‐4 De‐Multiplexer
Exercise 3.5: testbench for 1‐to‐4 de‐multiplexer
In this exercise you have to write a testbench for the verilog code written in exercise 3.4. Verify the results using the testbench you have written.
Page | 7
Session 4:
After this session you should be able to do time‐based and event‐based control, synchronous sequential logic, blocking and non‐blocking assignments, tasks and functions.
Exercise 4.1: clock generation using always
All behavioral statements inside an always statement constitute an always block. The always statement starts at time 0 and executes the statements in the always block continuously in a looping fashion. This statement is used to model a block of activity that is repeated continuously in a digital circuit.
Design a clock generator that doesn’t have any input and a single output i.e. clock.
Exercise 4.2: +ve and –ve clocked flip flops
There is only one way to model either a positive edge‐triggered flip‐flop or negative edge‐triggered flip‐flop. In this lab you have to model two flip‐flops one with positive edge‐trigger and the other with negative edge‐trigger.
1. Write the code for the diagram shown in figure 4.1.
Y18
A0
Clock
Y28
A1
D1
D0 Q
Q’
Q
Q’
Figure 4.1: Positive and Negative edge‐triggered flip‐flops
2. Write testbench and also verify the results.
Page | 8
Exercise 4.3: Synchronous reset, A Synchronous reset and enable
Write a code to show the diagram as shown in figure 4.2. Also check the behavior of Synchronous reset, Asynchronous reset and enable signals. Follow the steps given below
1. Write verilog code for Synchronous reset. 2. Write verilog code for Asynchronous reset. 3. Add enable signal in the module.
Figure 4.2: Timing diagram of Synchronous and Asynchronous reset
4. Add a stimulus to show the diagrams similar (in behavior) to the figure 4.2.
Exercise 4.4: Behavioral 4‐bit counter
By completing the steps given below design a 4‐bit counter using behavioral statements.
1. Write verilog code for the behavioral 4‐bit counter with following port connections A single 4‐bit counter output signal. Clock and a reset as input signals.
2. Write a testbench to verify the output of the counter.
Page | 9
Exercise 4.5: Behavior of Blocking and non‐Blocking Statements
After this lab exercise you should be able to understand the behavior of blocking and non‐blocking statements.
Write a verilog code for the diagram given below and check the behavior of blocking and non‐blocking statements using stimulus.
Data_in
Clock
Data_outDD Q
Q’
Q
Q’
Dinternal
1 1
Figure 4.3: Blocking and non‐blocking behavior
You have to notice the behavior of both environments blocking and non‐blocking. Notice the change of data at output according to the input changed.
Session 5
In this labencoders
Exercise
1. Wth
aTd
2. W
Exercise
The sevapplicatio
5:
b you will des/decoders.
5.1: Priority
Write a codehe casex stat
Note nd that the he casex staon’t cares.
Write a stimu
5.2: BCD to
en‐segmentons using pr
esign using c
y Encoder
for priority tements.
that the concasex stateatements ig
ulus to check
seven segm
t light‐emittrototyping b
conditional s
encoder sh
nditional (if)ments combnores x and
Figure 5.1
k your result
ment display
ting diode oards.
statements,
own in figur
) statementbined with xd z in bits of
1: Priority En
ts.
(LED) disp
loops, mode
re 5.1. You c
s have an imx in the casef the case it
ncoder
lay is a ve
eling muxes,
can use if st
mplied priore items impltem and the
ery useful
Page
,
atements or
rity of execulied priority ey are treate
circuit in m
e | 10
r also
ution, also. ed as
many
Page | 11
Your module should take 4‐bit BCD input and give a 7‐bit output to display a digit on the seven‐segment. Assign your outputs for the seven‐segment LED display which is shown in figure 5.2.
Figure 5.2: Seven Segment LED Display
Session 6
In this seshift regi
Exercise
Design a
1. Sy2. P3. P4. B5. B6. B7. B
6:
ession of thesters.
6.1: Univers
4‐bit Univer
ynchronous arallel inputarallel outpuidirectional idirectional idirectional idirectional
lab you will
sal Shift Reg
rsal shift reg
reset. ts. uts. serial input serial input serial outpuserial outpu
l design a fin
gister
gister with fo
from LSB sidfrom MSB sut from LSB sut from MSB
Figure 6.3: U
nite state ma
ollowing feat
de. ide. side. side.
Universal Sh
achine. You
tures
hift Register
will model c
r
Page
counters and
e | 12
d also
Exercise
Design a Also writ
Exercise
Design a
1. It2. It
6.2: Finite S
state machite a testbenc
6.3: 3‐bit up
3‐bit counte
t should cout should load
State machin
ine of car spch for this FS
Figure 6.1
p/down cou
er as shown
nt in both did some data
ne (Car Spee
peed controlSM.
1: State diag
unter
in figure 6.2
irections i.e.to start cou
ed Control)
ler correspo
gram for car
2. The count
. up/down.unting from t
onding to the
r speed cont
er should in
that value.
e state mach
troller
clude follow
Page
hine in figure
wing features
e | 13
e 6.1.
s
3. E4. A
nable pin shA signal shou
Fi
hould be addld be added
igure 6.2: 3‐
ded to turn t to reset the
Data
‐bit up/dow
he counter oe counter.
a_in
n counter
on/off.
Pagee | 14
Page | 15
Session 7:
This is a very small session to allow you to complete earlier exercises and leave more time for the next session.
Exercise 7.1: ASMD counter
See example 13 which is an ASMD counter. Convert it to a count‐down counter. Note how you only need to change the funciton in the datapath and the rest of the circuit remains the same.
Page | 16
Session 8:
This session is over the RISC controller from Ciletti’s book, that was discussed in class.
Exercise 8.1: The RISC processor
First of all, open the RISC example, run it yourself and see that you have at least a reasonably good idea of how it works. (At this point there isnt enough time to look at each and every line of code, but that would be a good exercise for later)
Exercise 8.2: Carry flag in the RISC processor
Now modify the design so that the Processor’s ALU creates a carry flag, asserted when the result of an addition operation has a carry out.
You will need to add a Load signal that is created in Control_Unit, and is input to the Processor.
You will need to creat a ‘carry’ signal, that is created in ALU, loaded in a Register in Processor, and fed to the Control Unit.
Note: that all additions in the code for this carry flag will look very similar to the way the Zero flag is implemented, so you can use that as a reference.
Change the testbench to ensure that during the program execution, the carry flag is tested.
Page | 17
Session 9:
No new exercises in this session; please ensure you complete all previous exercises.
After that, open, run and synthesize the two different versions of the halftone image converter. You should at least fully understand the first (combinatorial) implementation. Then depending on time, see what you can make of the ‘concurrent’ implementation.
Page | 18
Session 10:
Exercise 10.1: The RMM guidelines
Open a design file that you have seen in this workshop. I recommend the Control_Unit of the RISC processor but you can chose something smaller if you please.
Now look at the chapter 5 of Re‐use Methodology Manual. Update this design to conform to the rules and guidelines of RMM.