Simulation de portes logiques VHDL
Simulation de portes logiques VHDL
ⵜⵉⵏⵎⵍⵜⴰⵏⴰⵎⵓⵔⵜⵏⵜⵎⴰⵙⵙⴰⵏⵉⵏⵜⵓⵙⵏⵉⵙⵉⵏ ⵜⴰⵙⴷⴰⵡⵉⵜⵙⵉⴷⵉⵎⵓⵃⵎⵎⴰⴷⴱⵏⵄⴱⴷⵓⵍⵍⴰⵀ
Ecole Nationale des Sciences Appliquées de Fès Université Sidi Mohamed Ben Abdellah
SIMULATION DES
PORTES LOGIQUES PAR
MODELSIM
1
المدرسة الوطنية للعلوم التطبيقية جامعة سيدي محمد بن عبدهللا
ⵜⵉⵏⵎⵍⵜⴰⵏⴰⵎⵓⵔⵜⵏⵜⵎⴰⵙⵙⴰⵏⵉⵏⵜⵓⵙⵏⵉⵙⵉⵏ ⵜⴰⵙⴷⴰⵡⵉⵜⵙⵉⴷⵉⵎⵓⵃⵎⵎⴰⴷⴱⵏⵄⴱⴷⵓⵍⵍⴰⵀ
Ecole Nationale des Sciences Appliquées de Fès Université Sidi Mohamed Ben Abdellah
I. Introduction
Réaliser les opérateurs de base de la logique combinatoire (les portes : Inverseur, ET, OU,
NON-ET, NON-OU).
Porte Inverseur :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_inverseur is
2
المدرسة الوطنية للعلوم التطبيقية جامعة سيدي محمد بن عبدهللا
ⵜⵉⵏⵎⵍⵜⴰⵏⴰⵎⵓⵔⵜⵏⵜⵎⴰⵙⵙⴰⵏⵉⵏⵜⵓⵙⵏⵉⵙⵉⵏ ⵜⴰⵙⴷⴰⵡⵉⵜⵙⵉⴷⵉⵎⵓⵃⵎⵎⴰⴷⴱⵏⵄⴱⴷⵓⵍⵍⴰⵀ
Ecole Nationale des Sciences Appliquées de Fès Université Sidi Mohamed Ben Abdellah
Port ( a : in STD_LOGIC;
s : out STD_LOGIC);
end porte_inverseur;
-- Déclaration de l’architecture avec une affectation simple.
architecture Behavioral of porte_inverseur is
begin
s<= not a;
end Behavioral;
Création d’un fichier test bench VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity test_port_invers_vhd is
end test_port_invers_vhd;
component porte_inverseur
port(
a : in std_logic;
s : out std_logic);
end component;
--inputs
signal a : std_logic := '0';
--outputs
signal s : std_logic;
begin
-- instantiate the unit under test (uut)
3
uut: porte_inverseur port map(
a => a,
s => s
);
tb : process
begin
a<='0';wait for 20 ns; a<='1';wait for 20 ns; wait;
end process;
end;
4
Porte AND :
Le fichier Test du VHDL : test_porte_et nommé dans file name on change juste la partie du
tb :process
tb : process
begin
a<= '0'; b<= '0'; wait for 20 ns;
a<= '1'; b<= '0'; wait for 20 ns;
a<= '0'; b<= '1'; wait for 20 ns;
a<= '1'; b<= '1'; wait for 20 ns;
wait;
end process;
end;
5
Porte OR :
Alors le programme de la porte_ou est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_ou is
Port ( a : in STD_LOGIC;
b: in STD_LOGIC;
s : out STD_LOGIC);
end porte_ou;
-- Déclaration de l’architecture avec une affectation simple.
architecture Behavioral of porte_ou is
begin
s<= a or b;
end Behavioral;
Le fichier Test du VHDL : test_porte_ou nommé dans file name on change juste la partie du
tb :process
tb : process
begin
a<= '0'; b<= '0'; wait for 20 ns;
a<= '1'; b<= '0'; wait for 20 ns;
a<= '0'; b<= '1'; wait for 20 ns;
a<= '1'; b<= '1'; wait for 20 ns;
wait;
end process;
end;
Porte NAND :
Le fichier Test du VHDL : test_porte_non_et nommé dans file name on change juste la partie
du tb :process
6
tb : process
begin
Le fichier Test du VHDL : test_porte_non_ou nommé dans file name on change juste la partie
du tb :process
tb : process
begin
a<= '0'; b<= '0'; wait for 20 ns;
a<= '1'; b<= '0'; wait for 20 ns;
a<= '0'; b<= '1'; wait for 20 ns;
a<= '1'; b<= '1'; wait for 20 ns;
wait;
end process;
end;
Réaliser la porte XOR en utilisant les trois descriptions (flot de données, comportementale,
structurelle) en faisant appel aux composants déjà réalisé en utilisant
: COMPONENT.
Porte XOR1 : flot de données
Alors le programme de la porte_xor1 est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_xor1 is
Port ( a : in STD_LOGIC;
b: in STD_LOGIC;
s : out STD_LOGIC);
7
end porte_xor1;
-- Déclaration de l’architecture avec une affectation conditionnelle.
architecture Behavioral of porte_xor1 is
begin
s<= '0' when a=b else '1';
end Behavioral;
Porte XOR2 : comportemental
Alors le programme de la porte_xor2 est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_xor2 is
Port ( a : in STD_LOGIC;
b: in STD_LOGIC;
s : out STD_LOGIC);
end porte_xor2;
-- Déclaration de l’architecture avec une structure de test.
architecture Behavioral of porte_xor1 is
begin
process (a,b)
begin
if a=b then s<= '0';
else s<= '1';
end if;
end process;
end Behavioral;
Porte XOR3 : structurelle
Alors le programme de la porte_xor3 est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_xor3 is
Port ( a : in STD_LOGIC;
b: in STD_LOGIC;
s : out STD_LOGIC);
end porte_xor3;
-- Déclaration de l’architecture en structurelle.
architecture Behavioral of porte_xor3 is
signal s1,s2,s3,s4:std_logic;
component porte_inverseur
port (a:in std_logic;
s:out std_logic);
end component;
component porte_et
port (a:in std_logic;
b:in std_logic;
s:out std_logic);
end component;
component porte_ou
port (a:in std_logic;
8
b:in std_logic;
s:out std_logic);
end component;
begin
u2:porte_inverseur port map (b,s2);
u1:porte_inverseur port map (a,s1);
u5:porte_ou port map (s3,s4,s);
u3:porte_et port map (s1,b,s3);
u4:porte_et port map (a,s2,s4);
end Behavioral;
Le fichier Test du VHDL : test_porte_xor 1,2 et 3 c’est le même on change juste la partie du
tb :process
9
tb : process
begin
a<= '0'; b<= '0'; wait for 20 ns;
a<= '1'; b<= '0'; wait for 20 ns;
a<= '0'; b<= '1'; wait for 20 ns;
a<= '1'; b<= '1'; wait for 20 ns;
wait;
end process;
end;
III. Multiplexeur
Réaliser un multiplexeur (2 vers 1) en utilisant les trois descriptions (flot de données,
comportementale, structurelle).
Porte Multiplexeur 1 : flot de données
Alors le programme de la porte_mux1 est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_mux1 is
Port ( in1 : in STD_LOGIC;
In2: in STD_LOGIC;
sel : in STD_LOGIC;
s : out STD_LOGIC);
end porte_mux1;
-- Déclaration de l’architecture avec une affectation conditionnelle.
architecture Behavioral of porte_mux1 is
begin
s<= in1 when sel = '0';
else s<= in2;
end Behavioral;
Porte Multiplexeur 2 : comportemental
Alors le programme de la porte_mux2 est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity porte_mux2 is
Port ( in1 : in STD_LOGIC;
In2: in STD_LOGIC;
sel : in STD_LOGIC;
s : out STD_LOGIC);
end porte_mux2;
-- Déclaration de l’architecture avec une structure de test.
architecture Behavioral of porte_mux2 is
begin
process (in1,in2, sel)
begin
if sel = '0' then s <=in1;
else s<= in2;
end if;
10
end process;
end Behavioral;
Porte Multiplexeur 3 : structurelle
Alors le programme de la porte_mux3 est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration du paquetage spécifique pour appeler les components.
use work.mes_composants.all;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
11
entity porte_mux3 is
Port ( in1 : in STD_LOGIC;
In2: in STD_LOGIC;
sel : in STD_LOGIC;
s : out STD_LOGIC);
end porte_mux3;
-- Déclaration de l’architecture en structurelle.
architecture Behavioral of porte_mux3 is
signal s1,s2,s3:std_logic;
begin
u1:porte_inverseur port map (sel,s1);
u4:porte_ou port map (s2,s3,s);
u2:porte_et port map (in1,s1,s2);
u3:porte_et port map (in2,sel,s3);
end Behavioral;
Le fichier Test du VHDL : test_porte_xor 1,2 et 3 c’est le même on change juste la partie du
tb :process
tb : process
begin
in1<='0'; in2<='0'; sel<='0'; wait for 20 ns;
in1<='0'; in2<='0'; sel<='1'; wait for 20 ns;
in1<='0'; in2<='1'; sel<='0'; wait for 20 ns;
in1<='0'; in2<='1'; sel<='1'; wait for 20 ns;
in1<='1'; in2<='0'; sel<='0'; wait for 20 ns;
in1<='1'; in2<='0'; sel<='1'; wait for 20 ns;
in1<='1'; in2<='1'; sel<='0'; wait for 20 ns;
in1<='1'; in2<='1'; sel<='1'; wait for 20 ns;
wait;
end process;
end;
IV. Demi-additionneur
Réaliser un demi-additionneur en utilisant les portes NAND (NON-ET) et l’inverseur dans une
description structurelle.
Demi-additionneur : structurelle
Alors le programme du demi_add est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration du paquetage spécifique pour appeler les components.
use work.mes_composants.all;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity demi_add is
Port ( a : in STD_LOGIC;
b: in STD_LOGIC;
s : out STD_LOGIC;
cb : out STD_LOGIC);
end demi_add;
-- Déclaration de l’architecture en structurelle.
architecture Behavioral of demi_add is
signal s1,s2,s3:std_logic;
begin
u1:porte_non_et port map (a,b,s1);
V. Additionneur complet
Réaliser un additionneur complet de 1 bit en utilisant le demi_additionneur de 1bit ainsi qu’une
retenue à l’entrée et sortie du système.
Additionneur complet 1bit: structurelle
Alors le programme du add_1bit est comme suite :
-- Déclaration de la bibliothèque et des paquetages.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Déclaration du paquetage spécifique pour appeler les components.
use work.mes_composants.all;
-- Déclaration de l’entité avec les entrées/sorties correspondants.
entity add_1bit is
Port ( a : in STD_LOGIC;
b: in STD_LOGIC;
Cin : in STD_LOGIC;
Sortie : out STD_LOGIC;
Cout : out STD_LOGIC);
end add_1bit;
-- Déclaration de l’architecture en structurelle.
architecture Behavioral of add_1bit is
signal s1,s2,s3:std_logic;
begin
u1:demi_add port map (a,b,s1,S2);
u2:demi_add port map (Cin,s1,sortie,s3);
u3:porte_ou port map (s3,s2,Cout);
end Behavioral;
Le fichier Test du VHDL : test_ add_1bit c’est le même on change juste la partie du
tb :process
tb : process
begin
a<='0'; b<='0'; Cin<= '0'; wait for 20 ns;
a<='0'; b<='0'; Cin<= '1'; wait for 20 ns;
a<='0'; b<='1'; Cin<= '0'; wait for 20 ns;
a<='0'; b<='1'; Cin<= '1'; wait for 20 ns;
a<='1'; b<='0'; Cin<= '0'; wait for 20 ns;
a<='1'; b<='0'; Cin<= '1'; wait for 20 ns;
a<='1'; b<='1'; Cin<= '0'; wait for 20 ns;
a<='1'; b<='1'; Cin<= '1'; wait for 20 ns;
wait;
end process;
Registre à N bits:
Réaliser un registre de N bits qui est constitué de bascules D avec un signal Reset asynchrone actif à
l’état haut, le circuit sera sensible au front montant de l’horloge Clk.
Entity Portes is
Port (A, B: in std_logic;
Y1, Y2, Y3, Y4, Y5, Y6, Y7: out std_logic);
end Portes ;
Exercice 2
B A S
0 0 1
0 1 1
1 0 1
1 1 0
1) Faire la description VHDL de ce circuit ?
2) De quel circuit s’agit-il ?
3) Dessiner le schéma bloc de ce circuit ?
Exercice 4
Soit la description VHDL suivante :
Library ieee ;
Use ieee.std_logic_1164.all;
Entity Fonction_mystere is
Port (e0, e1: in std_logic;
sel: in std_logic;
Sort: out std_logic);
end Fonction_mystere ;
Architecture V0 of Fonction_mystere is
begin
Sort <= e0 when sel= '0' else e1;
end V0;
Entity fct is
Port (a, b: in std_logic;
s: out std_logic);
end fct ;
Entity circuit is
Port (e1, e2, e3, e4: in std_logic;
s: out std_logic);
end circuit ;
R
XO
Entity fct1 is
Port (A, B: in std_logic;
S1, S2, S3, S4: out std_logic);
end fct1 ;
Exercice 3
Voici le schéma bloc d’un démultiplexeur 1à 4, une entrée de validation Enable (le
circuit est actif à l’état haut de ce signal), une entrée de sélection E et 4 sorties.
Y0
E Y1
DMUX1_4
Y2
Enable Y3
C
F
X
MU
A
X
MU
Y
R
NO
D Q
D_Latch
CLK Qb
clk
Q
Qb
Exercice 2
Réaliser un registre composé de 4 bascules D latch.
D1 D2 D3 D4
Reset
Q1 Q2 Q3 Q4
Exercice 3
Réaliser un registre à décalage à droite de 4bits avec un reset asynchrone :
1) Description simple.
2) Description en utilisant une boucle.
Exercice 1
Réaliser un compteur de 3 bits dans les cas suivants :
1) Compteur simple sans remise à zéro.
2) Compteur avec une Reset asynchrone.
Exercice 2
Réaliser un compteur décimal en langage VHDL avec une remise à zéro asynchrone
active à l’état bas.
Exercice 3
Réaliser un compteur/décompteur en langage VHDL avec une remise à zéro asynchrone
active à l’état haut. Le circuit fonctionnera comme compteur à l’état haut du signal E et
comme un décompteur à l’état bas du signal E.
Exercice 4
Réaliser un compteur modulo 6 en langage VHDL (le compteur compte de 0 à 5).
Exercice 5
Réaliser un décompteur modulo 12 en langage VHDL (le décompteur décompte de 11 à
0).