Académique Documents
Professionnel Documents
Culture Documents
1
Chapitre 1: La
Synthèse VHDL
ENTITY ARCHITECTURE
PACKAGE PACKAGEBODY
3
ENTITY/ARCHITECTURE
-- déclaration des ressources externes
library NOM_DE_LA_BIBLIOTHEQUE ;
use ELEMENT_DE_LA_BIBLIOTHEQUE ;
-- description de l’entité vue comme une « boite noire » avec des entrées et des sorties
entity NOM_DE_L’ENTITE is
port(NOM_DES_ENTREES_SORTIES : direction type) ;
end NOM_DE_L’ENTITE ;
5
TYPE
7
CONSTANT
8
SIGNAL
9
VRIABLE
10
DIRECTIONS
E2
E1
entity ET is entity ET is
port (E1,E2 : in std_logic ; port (E1,E2 : in bit ;
S :out std_logic) ; S :out bit) ;
end ET;
&
end ET;
if…then
While
case
SET
S Q
R CLR Q
13
DESCRIPTION VHDL
De type temporelle ou flot de données, c’est à dire réalisée à partir
d’équations booléennes.
Architecture
Flot de données
X<=a and b
Y<=w xor v
R CLR Q
X<=a and b
14
DESCRIPTION EN FLOT DE DONNÉES
X Sum X Y Ci Sum Cout
0 0 0 0 0
Y
Adder Cout
0 0 1 1 0
Ci 0 1 0 1 0
0 1 1 0 1
Figure1. additionneur 1 0 0 1 0
1 0 1 0 1
x et y: bit d’entrée
Ci : retenue à l’entrée 1 1 0 0 1
Cout : retenue à la sortie 1 1 1 1 1
Sum : bit de sortie table1. Table de vérité
Travail demandé :
Donner la table de vérité de cet additionneur.
Ecrire un code VHDL pour cet additionneur.
A partir de la table de vérité, on peut déduire les équations suivantes:
S=X⊕Y
Sum = S ⊕ Ci
Cout = X.Y + S.Ci 15
DESCRIPTION EN FLOT DE DONNÉES
library IEEE;
use IEEE.std_logic_1164.all;
entity adder is
port (x : in std_logic;
y : in std_logic;
ci : in std_logic;
sum : out std_logic;
cout : out std_logic);
end adder;
architecture rtl of adder is
signal s : std_logic;
begin
s<=x xor y;
sum <= s xor ci;
cout <= (x and y) or (s and ci);
16
end rtl;
DESCRIPTION STRUCTURELLE
SYNTAXE:
component NOM_DE_L’ENTITE_DECRIVANT_LE_COMPOSANT
end component ;
SYNTAXE:
U1 : NOM_DE_L’ENTITE_DECRIVANT_LE_COMPOSANT port
map (ENTREES SORTIES A UTILISER) ;
17
DESCRIPTION STRUCTURELLE
Utilisez une description de type structurelle pour réaliser
l’additionneur de 1 bit dont le schéma bloc est illustré par la Figure ci-
dessous.
X N1
Demi- Porte Cout
Y additionneur N2 N3 OU
Demi-
Ci Sum
additionneur
X N1
Demi- N2=X xor Y
Y additionneur N2
N1=X and Y
18
DESCRIPTION STRUCTURELLE
library IEEE;
use IEEE.std_logic_1164.all;
entity or_gate is
port (x : in std_logic;
y : in std_logic;
z : out std_logic);
end or_gate;
19
DESCRIPTION STRUCTURELLE
library IEEE;
use IEEE.std_logic_1164.all;
entity half_adder is
port (x : in std_logic;
y : in std_logic;
sum : out std_logic;
cout : out std_logic);
end half_adder;
package NOM_DU_PAQUETAGE is
Définition des types, sous-types, constantes ;
Déclaration des fonctions, procédures, composants, signaux.
end NOM_PAQUETAGE;
Travail demandé:
Ecrire un code VHDL du port AND à deux entrées.
Ecrire un code VHDL du port NAND à deux entrées.
Définir un paquetage (General_pkg) qui contient la
déclaration de composants AND et NAND.
En utilisant le paquetage General_pkg donner un code
VHDL pour la porte NAND4.
26
LES PAQUETAGES
27
LES PAQUETAGES
library IEEE;
use IEEE.std_logic_1164.all;
Package General_pkg is
Component AND2_RTL
Port ( A,B : in std_logic ;
S : out std_logic) ;
End component ;
Component NAND2_RTL
Port ( A,B : in std_logic ;
S : out std_logic) ;
End component ;
End General_pkg ;
28
LES PAQUETAGES
library IEEE;
use IEEE.std_logic_1164.all;
library work;
use WORK.General_pkg.all ;
Entity NAND4 is
Port ( A , B , C , D : in std_logic ;
S : out std_logic ) ;
End NAND4 ;
Architecture Structural of NAND4 is
signal N1,N2 : std_logic ;
Begin
B1 : AND2_RTL port map (A,B, N1) ;
B2 : AND2_RTL port map (C,D,N2) ;
B3 : NAND2_RTL port map (N1,N2,S);
End Structural; 29
Spécification d’un modèle de test
Entity Test is
-- entité sans port
End Test ;
Architecture NAND4_TST of Test is
-- déclaration du composant à tester
component NAND4
Port ( A , B , C , D : in std_logic ;
S : out std_logic ) ;
end component;
signal E1,E2,E3,E4,S: std_logic;
begin
model: NAND4 port map (E1,E2,E3,E4,S) ;
-- élaboration de signaux de test en entrée
E1 <= '1';
E2 <= '1', '0' after 4 ns;
E3 <= '1', '0' after 6 ns;
E4 <= '0', '1' after 8 ns, '0' after 12 ns; 30
end NAND4 test;
Identificateur
Exemple:
Fin0 , Boucle77 , Prog_principal
mauvais identificateurs : 12tr , _date ,fin0_ , acq__mes , bus , is
31
Mots Réservés
32
Littéraux
33
Opérateurs prédéfinis
Opérateurs logiques : sur des objets de types booléens ou Bit
AND, OR, NAND, NOR, XOR, NOT
Opérateurs relationnels:
=, /=, <, <=, >, >=
Opérateurs arithmétiques:
+, -, *, /, **, MOD, REM.
Exemple:
3**2=9 ;
(-5) MOD 2 = 1 A MOD B : Reste de la division qui a comme signe le signe de B
(-5) REM 2 =-1 A REM B : Reste de la division qui a comme signe le signe de A
35
Types énumérés
36
Types entiers
37
Types flottants
38
Types physiques
39
Types Tableaux
40
Types enregistrements
exemple:
signal date_de_naissance : date ;
Date_de_naissance<= (29, JUIN, 1963);
Date_de_naissance.jour<=29 ;
41
Type fichier
42
Les Alias
43
Les fonctions
Function NOM_DE_LA_FONCTION (PARAMETRE : type) return type du
paramètre retourné is
--Déclaration des variables
begin
--Instructions_Sequentielles;
Return NOM_OU_VALEUR_DU_PARAMETRE_DE_RETOUR;
End ;
Exemple:
Function Min(A, B : Int) return integer is
Begin
If A<B then
Return A ;
Else
Return B ;
End if ;
End Min ;
L’utilisation se fait ensuite par la syntaxe suivante:
NOM<=NOM_DE_LA_FONCTION(PARAMETRE_D’UTILISATION) ; 44
Les procédures
Procedure NOM_DE_LA_PROCEDURE(PARAMETRES : direction type) is
--declaration des variables
Begin
--Instructions_séquentielles ;
End ;
Exemple :
Procedure Min ( A,B : in Real, S : out Real ) is
Variable Temp : Real ;
Begin
If A<B then
Temp := A ;
Else
Temp := B ;
End if ;
S := Temp ;
End Min;
L’appel de la procédure se fait par :
NOM_DE_LA_PROCEDURE(PARAMETRE_d’UTILISATION) ; 45
Les instructions concurrentes
46
Affectation simple
NOM_D’UNE_GRANDEUR<=VALEUR_OU_NOM_D’UNE_GRANDEUR
Exemple:
Signal A : std_logic_vector(7 downto 0);
A<= “00011100 ”;
47
Affectation Conditionnelle
L’interconnexion est soumise à des conditions.
Syntaxe:
NOM_D’UNE_GRANDEUR<= Q1 when CONDITION1 else
Q2 when CONDITION2 else
…..
Exemple: Qn ;
library IEEE;
use IEEE.std_logic_1164.all;
Entity AND2_RTL is
Port (A,B : in std_logic ;
S : out std_logic) ;
End AND2_RTL ;
Architecture ARCH_ET of AND2_RTL is
Begin
S <= ‘1’ when (A=‘1’ and B=‘1’) else
‘0’;
48
End ARCH_ET ;
Affectation Sélective
Suivant la valeur d’une expression, l’interconnexion sera effectué.
Syntaxe:
With EXPRESSION select
NOM_D’UNE_GRANDEUR<= Q1 when valeur1 ,
Q2 when valeur2 ,
….
Exemple:
library IEEE; Qn when others ;
use IEEE.std_logic_1164.all;
Entity AND2_RTL is
Port (A,B : in std_logic ;
S : out std_logic) ;
End AND2_RTL ;
Architecture ARCH_ET of AND2_RTL is
Begin
With (A= ‘1’ and B= ‘1’) select
S<= ‘1’ when true,
‘0’ when others; 49
End ARCH_ET ;
La boucle for … generate
Syntaxe:
for i in MIN to MAX generate
INSTRUCTIONS;
end generate ;
50
Les instructions concurrentes
X Sum X Y Ci Sum Cout
0 0 0 0 0
Y
Adder Cout
0 0 1 1 0
Ci 0 1 0 1 0
0 1 1 0 1
Figure1. additionneur 1 0 0 1 0
1 0 1 0 1
x et y: bit d’entrée
Ci : retenue à l’entrée 1 1 0 0 1
Cout : retenue à la sortie 1 1 1 1 1
Sum : bit de sortie table1. Table de vérité
Travail demandé :
Ecrire un code VHDL pour cet additionneur en utilisant les
instructions concurrentes .
51
PROCESS
Syntaxe:
LABEL : process(LISTE_DE_SENSIBILITE)
-- Déclaration des variables.
NOM_DES_OBJET : type ;
begin
INSTRUCTIONS_SEQUENTIELLES ;
end process ;
52
Les instructions Séquentielles
Les instructions séquentielles sont utilisées uniquement à l’intérieur
d’un process et sont examinées dans l’ordre d’écriture.
53
L’instruction “if..then..elsif..else ..end if”
Syntaxe:
if CONDITION1 then
INSTRUCTION1;
elsif CONDITION2 then
INSTRUCTION2;
elsif CONDITION3 then
INSTRUCTION3;
…
else
INSTRUCTIONn;
end if;
54
L’instruction “if..then..elsif..else ..end if”
library IEEE;
use IEEE.std_logic_1164.all;
Entity AND2_RTL is
Port (A,B : in std_logic ;
S : out std_logic) ;
End AND2_RTL ;
Architecture ARCH_ET of AND2_RTL is
Begin
Process(A,B)
Begin
if (A=‘1’ and B=‘1’) then
S<= ‘1’;
else
S<= ‘0’;
end if;
end process;
end ARCH_ET ; 55
L’instruction « if..then..elsif..else ..end if »
library IEEE;
use IEEE.std_logic_1164.all;
Entity AND2_RTL is
Port (A,B,CLK : in std_logic ; S : out std_logic) ;
End AND2_RTL ;
Architecture ARCH_ET of AND2_RTL is
Begin
Process(CLK)
Begin
If (CLK'event and CLK ='1') then
If (A=‘1’ and B=‘1’) then
S<= ‘1’;
Else
S<= ‘0’;
End if;
End if;
End process;
End ARCH_ET ; 56
L’instruction « case..when..end case »
Syntaxe:
case EXPRESSION is
when ETAT1=>INSTRUCTION1;
when ETAT2=>INSTRUCTION2;
…
when others=>INSTRUCTIONn;
end case;
57
L’instruction « case..when..end case »
Exemple:
library IEEE;
use IEEE.std_logic_1164.all;
Entity AND2_RTL is
Port (A,B : in std_logic ;
S : out std_logic) ;
End AND2_RTL ;
Architecture ARCH_ET of AND2_RTL is
Begin
Process(A,B)
Begin
case (A= ‘1’ and B= ‘1’) is
when true => s<= ‘1’;
when others=> s<= ‘0’;
end case;
End process;
End ARCH_ET ; 58
L’instruction « for..in..to..loop..end loop »
Syntaxe:
For N in X to Y loop
INSTRUCTION;
End loop;
Exemple:
for i in 1 to 10 loop
tab(i):=i;
end loop;
59
L’instruction « while..loop..end loop »
Syntaxe:
While CONDITION loop
INSTRUCTION;
End loop;
Exemple:
i:=0;
While i<10 loop
tab(i):=i;
i:=i+1;
End loop;
60
Les instructions séquentielles
X Sum X Y Ci Sum Cout
0 0 0 0 0
Y
Adder Cout
0 0 1 1 0
Ci 0 1 0 1 0
0 1 1 0 1
Figure1. additionneur 1 0 0 1 0
1 0 1 0 1
x et y: bit d’entrée
Ci : retenue à l’entrée 1 1 0 0 1
Cout : retenue à la sortie 1 1 1 1 1
Sum : bit de sortie table1. Table de vérité
Travail demandé :
Ecrire un code VHDL pour cet additionneur en utilisant les
instructions séquentielles.
61