TP 02 VHDL
TP 02 VHDL
PS VHDL-FPGA
-..........................................
Student
-............................................
names
-..........................................
1. PS objectives:
At the end of this PS, you will be able to: use the ModelSim interface, write a
VHDL description of a comparator, compile and simulate a VHDL description,
and use conditional assignment.
2. The Comparator:
The comparator is a combinatorial circuit which makes it possible to compare
between two binary numbers. It has two inputs and three outputs.
a s : superior (a > b)
Comparator e : equal (a = b)
b
i : inferior (a < b)
The truth table of the comparator of two one-bit numbers is given by:
Inputs Outputs
a b s (a>b) i (a<b) e (a=b)
0 0 0 0 1
0 1 0 1 0
1 0 1 0 0
1 1 0 0 1
e <= ................................................
...............................................
............................. ;
i <= .................................................
...............................................
............................... ;
end rr;
1. Identify the inputs, the outputs, and their width.
Inputs Outputs
Name
a b s e i
Width
2 2 1 1 1
3. Compile and simulate the program on ModelSim with different inputs and check
the truth table.
architecture rr of comp2bit is
begin
s <= '1' when a > b else '0';
‘1’ when
e <= ... a = b else ‘0’
.......................;
Dr. A. Ganouche
i ...‘1’ when a < b else ‘0’
.......................
end rr;
.......................
.......................
6. Modify the program to make a comparator of two 4-bit numbers and the three
inputs for cascading.
s0, e0 et i0 are the result of another comparator which compare between two
numbers of higher weight (great significance).
a s : superior (a > b)
s0 e0 i0 Comparator e : equal (a = b)
b i : inferior (a < b)
In this case: the output 's' is worth 1 if and only if (s0=1) or (e0=1 and a>b)
The cascading of four comparator circuits is given by the following diagram:
b3 a3 b2 a2 b1 a1 b0 a0
s0 s0 s
0 s0 s0
e0 e
1 e0 Comp e0 Comp e0 Comp
i0
Comp
0 i0 i0 i0 i
....................... .......................
....................... .......................
....................... .......................
....................... .......................
....................... .......................
....................... .......................
....................... .......................
....................... .......................
.......................
Dr. A. Ganouche