Académique Documents
Professionnel Documents
Culture Documents
Mini-projet en VHDL
I. Conception de lUAL
- Conception du comparateur 4 bits ...4
- Conception de lUAL ..8
2
Conception dun mini-calculateur
R0
A 4
CE
UAL
R1
B 4 CE
R2 Res
3
CE
R3
Contrleur CE
clk
Instructon
8
3
I. Conception de lUnit arithmtique et logique :
1. Conception du comparateur 4 bits :
a. Table de vrit
Entres Sorties
A3, B3 A2, B2 A1, B1 A0, B0 A_SUP_B A_INF_B A_EGAL_B
A3>B3 x x x 1 0 0
A3<B3 x x x 0 1 0
A3=B3 A2>B2 x x 1 0 0
A3=B3 A2<B2 x x 0 1 0
A3=B3 A2=B2 A1>B1 x 1 0 0
A3=B3 A2=B2 A1<B1 x 0 1 0
A3=B3 A2=B2 A1=B1 A0>B0 1 0 0
A3=B3 A2=B2 A1=B1 A0<B0 0 1 0
A3=B3 A2=B2 A1=B1 A0=B0 0 0 1
b. Fichier compar_4b :
4
c. Fichier compar_4b_TB :
5
6
La simulation donne les rsultats suivants:
2. Conception de lUAL :
4
Enntree_A
4 resultat
S_A_SUP_B
S_A_INF_B
S_A_EGAL_B
4 S_OVFL
Enntree_B S_ZERO
3 S_NEG
CodeOP
a. Fichier Oprations.vhd :
7
Le champ CodeOp sert indiquer la nature de lopration
raliser :
b. Fichier Indications.vhd :
8
S_NEG : sortie permettant dindiquer sur le rsultat est
ngatif.
9
c. Fichier Unite.vhd : description complte de lUAL :
10
force CodeOp 000 0,001 40,010 80,011 120,100 160,101 200,110 240,111 360
run 400
La simulation donne les resultats suivants :
11
12
La simulation donne les rsultats suivants :
13
II. Conception des registres :
(Registre de mmorisation : Il s'agit en fait d'un ensemble de bascules
D flip-flop formant un mot binaire de 4 bits)
D
Clock_enable Q
CE
CLR
1. Fichier Registre.vhd :
Commentaire : Si CE=1,lentre de registre sera recopi dans la sortie ,si non la sortie est un
tat inconnu fort
14
2. Fichier REGISTRE_TB :
15
16
- La simulation donne les rsultats suivants :
18
b. Fichier MUX1_TB.vhd :
19
La simulation donne les rsultats suivants :
2
a. Fichier MUX2.vhd :
Sc2e
s
20
- On tape les lignes de commande suivantes dans la fentre transcript :
force S_R0 0000 0,0001 20
force S_R1 0010 0,0011 10
force S_R2 0100 0,0101 15
force S_R3 0111 0,1000 10
force Sc2 00 0,01 5,10 10,11 15
run 20
21
b. Fichier MUX2_TB :
22
La simulation donne les rsultats suivants :
23
2. Conception de dmultiplexeur :
E_R0
Sc3 E_R0 E_R1 E_R2 E_R3
E_R1 00 1 0 0 0
S_UAL DEMUX 01 0 1 0 0
E_R2
14 10 0 0 1 0
11 0 0 0 1
E_R3
2
Sc3e
s
a. Fichier DEMUX.vhd :
24
b. Fichier DEMUX_TB :
25
La simulation donne les rsultats suivants :
Sc1
Sc2
Sc3
Instr 8 Contrleur CE1
CE2
CE3
CE4
Code_OP
Fichier CONTROL1.vhd :
26
27
- On tape les lignes de commande dans le transcript :
force Instr 01011111 0,01010000 10,11111010 20,10101010 30,01100110
40,11111111 50,00000000 60
run 70
- La simulation donne les rsultats suivants :
28
- Fichier mini_calcul.vhd :
29
30
Exercices en VHDL
31
I. Modlisation dun dcodeur 7 segments :
1. Table de vrit :
2. Fichier dec7seg.vhd
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity dec7seg is
port( BCD: in std_logic_vector (3 downto 0);
SEGS: out std_logic_vector(6 downto 0));
end dec7seg;
architecture bhv of dec7seg is
begin
with BCD select
SEGS <= "1111110" when "0000",
"0110000" when "0001",
"1101101" when "0010",
"1111001" when "0011",
"0110011" when "0100",
"1011011" when "0101",
"1011111" when "0110",
"1110000" when "0111",
"1111111" when "1000",
"1111011" when "1001",
"-------" when others;
end bhv;
32
On tape les lignes de commande suivantes dans la fentre transcript :
- force bcd 0000 0,0001 20,0010 40,0011 60,0100 80,0101 100,0110 120,0111
140,1000 160,1001 180,1010 200,1011 220
- run 240
La simulation donne les rsultats suivants :
library ieee;
use ieee.std_logic_1164.all;
entity dec7seg_TB is
end dec7seg_TB;
33
--case 3
BCD <= "0010";
wait for 2 ns;
assert(SEGS = "1101101")
report "SEGS error!" severity error;
if ( SEGS /= "1101101") then
C:= C +1;
end if;
--case 4
BCD <= "0011";
wait for 2 ns;
assert(SEGS = "1111001")
report "SEGS error!" severity error;
if ( SEGS /= "1111001") then
C:= C +1;
end if;
--case 5
BCD <= "0100";
wait for 2 ns;
assert(SEGS = "0110011")
report "SEGS error!" severity error;
if ( SEGS /= "0110011") then
C:= C +1;
end if;
--case 6
BCD <= "0101";
wait for 2 ns;
assert(SEGS = "1011011")
report "SEGS error!" severity error;
if ( SEGS /= "1011011") then
C:= C +1;
end if;
--case 7
BCD <= "0110";
wait for 2 ns;
assert(SEGS = "1011111")
report "SEGS error!" severity error;
if ( SEGS /= "1011111") then
C:= C +1;
end if;
--case 8
BCD <= "0111";
wait for 2 ns;
assert(SEGS = "1110000")
report "SEGS error!" severity error;
if ( SEGS /= "1110000") then
C:= C +1;
end if;
--case 9
BCD <= "1000";
wait for 2 ns;
assert(SEGS = "1111111")
report "SEGS error!" severity error;
if ( SEGS /= "1111111") then
34
C:= C +1;
end if;
--case 10
BCD <= "1001";
wait for 2 ns;
assert(SEGS = "1111011")
report "SEGS error!" severity error;
if ( SEGS /= "1111011") then
C:= C +1;
End if;
-- lorsque l'entree BCD dpasse 9
--case 11
BCD <= "1010";
wait for 2 ns;
assert(SEGS = "-------")
report "SEGS error!" severity error;
if ( SEGS /= "-------") then
C:= C +1;
end if;
--case 12
BCD <= "1011";
wait for 2 ns;
assert(SEGS = "-------")
report "SEGS error!" severity error;
if ( SEGS /= "-------") then
C:= C +1;
end if;
--case 13
BCD <= "1100";
wait for 2 ns;
assert(SEGS = "-------")
report "SEGS error!" severity error;
if ( SEGS /= "-------") then
C:= C +1;
end if;
--case 14
BCD <= "1101";
wait for 2 ns;
assert(SEGS = "-------")
report "SEGS error!" severity error;
if ( SEGS /= "-------") then
C:= C +1;
end if;
--case 15
BCD <= "1110";
wait for 2 ns;
assert(SEGS = "-------")
report "SEGS error!" severity error;
if ( SEGS /= "-------") then
C:= C +1;
end if;
--case 16
BCD <= "1111";
wait for 2 ns;
assert(SEGS = "-------")
report "SEGS error!" severity error;
35
if ( SEGS /= "-------") then
C:= C +1;
end if;
-- summury of test bench
if (C=0) then
assert false
report"Testbench of compara_4b completed successfully!"
severity note;
else
assert true
report " Something wrong,try again"
severity error;
end if;
wait;
end process;
end TB2;
36
II. Modlisation dun compteur synchrone :
1. Fichier compteur.vhd :
37
On change la valeur du N, et on lui donne cette fois la valeur 12 ,( generic(n:
natural := 12);)
Le rsultat de la simulation est le suivant :
2. Fichier compteur_TB.vhd :
38
Remarque : le testbench est fait pour N = 3
39
III. Modlisation dune bascule D flip flop:
D
Q
Clk
1. Fichier bascD.vhd :
2. Fichier bascD_TB.vhd :
40
Simulation :
J
Q
CLK JK
Qbar
K
reset
1. Fichier JK.vhd :
41
- On tape les lignes de commande suivante dans le transcript :
Force clk 1 0, 0 {50 ns} -r 100
force reset 1 0,0 20
force j 0 0,1 110
force k 0 0,1 40,0 110,1 210
run 300
- La simulation donne les rsultats suivants :
2. Fichier JK_TB.vhd :
42
43
44
Simulation :
45