Vous êtes sur la page 1sur 61

Cours: Conception des

Circuits Numériques en VHDL

3ème Année LA: EEA-EII

1
Chapitre 1: La
Synthèse VHDL

L.A- EEA-EII 3ème Année


Unité de conception

Peuvent être compilées séparément


(un seul fichier *.vhd ou plusieurs)

ENTITY ARCHITECTURE

PACKAGE PACKAGEBODY

Vue Externe Définition

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 ;

--description de l’architecture à l’intérieure de l’entité


architecture NOM_DE_L’ARCHITECTURE of NOM_DE_L’ENTITE is
--Zone de déclaration (type, objet, constant,…)
begin
--Description
end NOM_DE_L’ARCHITECTURE ;
4
ENTITY/ARCHITECTURE

Le VHDL est un langage à instructions concurrentes :


•Les instructions sont évaluées en même temps.
•L’ordre dans lequel elles sont écrites n’a aucune importance.

Le langage VHDL ne fait pas de distinction entre majuscules et


minuscules.

En langage VHDL les commentaires sont précédés par « -- » et


s’arrêtent au retour à la ligne.

5
TYPE

integer : nombre entier pouvant aller de -2147483648 à


2147483647(32 Bits).

real : nombre réel pouvant aller de -1.0E308 à 1.0E308.(2.0 ,3.1,…).

boolean : ce type est utilisé pour les conditions et comprend deux


valeurs true (vrai) ou false (faux).

character : 256 caractères possibles (‘a’,’A’,…).

bit : deux valeurs possibles 0 ou 1.

bit_vector : un vecteur de bits est un bus déclaré par exemple pour


une largeur de N bits par bit_vector(0 to N) ou bien bit_vector(N
downto 0). 6
TYPE

std_logic : peut prendre 0,1, Z (haut impédance), U (non initialisé), X


(inconnu), W (indéterminé), L (0 faible), H (1 faible).

std_logic_vector : pour un bus composé de plusieurs bits déclaré pour


une largeur de N bits par std_logic_vector(0 to N) ou bien
std_logic_vector(N downto 0).

7
CONSTANT

Syntaxe : constant NOM_DES_OBJETS : type := {valeur initiale} ;

Exemple : constant PI : real := 3.1416 ;


constant Bits_Addr: integer := 12 ;

8
SIGNAL

Syntaxe : signal NOM_DES_OBJETS : type := {valeur initiale} ;

Exemple: signal data : bit_vector(7 downto 0):= “00000000” ;


signal compteur : integer:=0 ;
signal S,E1,E2: std_logic:=‘0’;

Affectation: S <= E1 and E2; (exemples avec des portes logique).

9
VRIABLE

Syntaxe : variable NOM_DES_OBJETS : type := {valeur initiale} ;

Exemple: variable data : bit_vector(7 downto 0):= “00000000” ;


variable compteur : integer:=0 ;
variable S,E1,E2: std_logic;

Affectation: S := E1 and E2; (exemples avec des portes logique).

10
DIRECTIONS

in : pour un signal en entrée.


out : pour un signal en sortie.
inout : pour un signal en entrée sortie.
buffer : pour un signal en sortie mais utilisé comme entrée dans la
description.

Syntaxe: NOM_DES_ENTREES_SORTIES : direction type;


Exemple: clock : in std_logic;
bus : out std_logic_vector(7 downto 0);
11
EXERCICE

Écrire le code VHDL du port ET dont le schéma bloc est


illustré par la figure ci-dessus.
library IEEE; library std;
use IEEE.std_logic_1164.all; use std.standard.all;

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;

architecture A_ET of ET is architecture A_ET of ET is


begin begin
S

S<=E1 and E2; S<=E1 and E2;


End A_ET; End A_ET; 12
DESCRIPTION VHDL

Comportementale, sans référence à des structures ou des équations.


Architecture
Comportementale

if…then
While
case

Structurelle c’est à dire réalisée à partir de composants prédéfinis.


Architecture
structurelle

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

Mixte c'est-à-dire réaliser à partir de composants prédéfinis et


d’équations booléennes.
Architecture
mixte
SET
S Q

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

port(NOM_DES_ENTREES_SORTIES : direction type) ;

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;

architecture desc_struct of or_gate is


begin
z <= x or y;
end desc_struct;

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;

architecture desc_struct of half_adder is


begin
sum <= x xor y;
cout <= x and y;
end desc_struct;
20
DESCRIPTION STRUCTURELLE
architecture desc_struct of adder is
component half_adder
library IEEE;
port ( x,y: in std_logic ;
use IEEE.std_logic_1164.all; sum,cout : out std_logic ) ;
end component ;
entity adder is
port (x : in std_logic; component or_gate
y : in std_logic; port ( x,y: in std_logic ;
ci : in std_logic; z : out std_logic ) ;
sum : out std_logic; end component ;
cout : out std_logic);
end adder; signal N1,N2,N3 : std_logic ;
begin
C1 : half_adder port map ( X,Y,N2,N1 ) ;
C2 : half_adder port map ( N2,Ci,sum,N3 ) ;
C3 : or_gate port map ( N1,N3,Cout ) ;
end desc_struct; 21
DESCRIPTION MIXTE
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 desc_struct of adder is
component half_adder
port ( x,y: in std_logic ;
sum,cout : out std_logic ) ;
end component ;
signal N1,N2,N3 : std_logic ;
begin
C1 : half_adder port map ( X,Y,N2,N1 ) ;
C2 : half_adder port map ( N2,Ci,sum,N3 ) ;
Cout<= N1 or N3;
22
end desc_struct;
LES PAQUETAGES

package NOM_DU_PAQUETAGE is
Définition des types, sous-types, constantes ;
Déclaration des fonctions, procédures, composants, signaux.
end NOM_PAQUETAGE;

package body NOM_DU_PAQUETAGE is


Description des fonctions et procédures ;
end NOM_DU_PAQUETAGE;

L’appel du paquetage se fait par l’instruction suivante:


use NOM_DE_LA_BIBLIOTHEQUE.NOM_DU_PAQUETAGE.all;
23
LES PAQUETAGES
package Adder_pkg is
component Half_adder
Port (x, y : in Bit ;
Cout, Sum : out Bit) ;
end component ;
component Or_gate
Port ( x, y : in bit ; z : out Bit) ;
end component ;
Type Int : Integer ;
Function Min ( A, B : Int) return Int ;
Function Max ( A, B : Int) return Int ;
End Adder_pkg ;
24
LES PAQUETAGES
Package body Adder_pkg is
Function Min(A, B : Int) return Int is
Begin
If A<B then
Return A ;
Else
Return B ;
End if ;
End Min ;
Function Max(A, B : Int) return Int is
Begin
If A<B then
Return B ;
Else
Return A ;
End if ;
End Max ;
25
End Adder_pkg ;
LES PAQUETAGES
N1
A A
B S
B
C NAND 4 S C
D D
N2

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

library IEEE; library IEEE;


use IEEE.std_logic_1164.all; use IEEE.std_logic_1164.all;

Entity AND2_RTL is Entity NAND2_RTL is


Port (A,B : in std_logic ; Port ( A,B : in std_logic ;
S : out std_logic) ; S : out std_logic) ;
End AND2_RTL ; End NAND2_RTL ;

Architecture COMP of AND2_RTL is Architecture COMP of NAND2_RTL is


Begin Begin
S <= A and B ; S <= A nand B ;
End COMP ; End COMP ;

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

composés de lettres, de chiffres ou d’_,


commencent par une lettre ( pas _),
de longueur inférieure à celle de la ligne,
pas deux _ à la suite, ni à la fin d’identificateur,
ne doivent pas être des mots réservés.

Exemple:
Fin0 , Boucle77 , Prog_principal
mauvais identificateurs : 12tr , _date ,fin0_ , acq__mes , bus , is

31
Mots Réservés

ABS ACCESS AFTER ALIAS ALL AND ARCHITECTURE ARRAY


ASSERT ATTRIBUTE BEGIN BLOCK BODY BUFFER BUS CASE
COMPONENT CONFIGURATION CONSTANT DISCONNECT
DOWNTO ELSE ELSIF END ENTITY EXIT FILE FOR FUNCTION
GENERATE GENERIC GUARDED IF IN INOUT IS LABEL
LIBRARY LINKAGE LOOP MAP MOD NAND NEW NEXT NOR
NOT NULL OF ON OPEN OR OTHERS OUT PACKAGE PORT
PROCEDURE PROCESS RANGE RECORD REGISTER REM
REPORT RETURN SELECT SEVERITY SIGNAL SUBTYPE
THEN TO TRANSPORT TYPE UNITS UNTIL USE VARIABLE
WAIT WHEN WHILE WITH XOR

32
Littéraux

Caractères: entre apostrophes: ‘0’, ‘X’, ‘a’, ‘%’.

Chaînes: entre guillemets: “1110101”, “XX”,


“bonjour”, “$^&@!”.

Chaînes de bits: B“00101101”, X“2D”, O“055”.

Décimaux : 27, -5, 4E3, 4.25.

Basés : 2#1001#, 8#65#, 16#C5#.

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

Opérateurs de la concatenation: &


Exemple
“bon” & “jour” produira “bonjour” ;
“101” & “10” produira “10110” ; 34
Opérateurs prédéfinis

Classement par priorité croissante :

logiques : and , or , nand , nor , xor,


relationnels : = , /= , < , <= , > , >=,
addition / concaténation : + , -, &,
signe : + , - ,
multiplication / division : * , / , mod , rem
divers : ** , abs , not.

 A priorité égale l’évaluation est faite de gauche à droite

35
Types énumérés

Type boolean is ( false, true);

Type bit is (‘0’, ‘1’);

Type type_etat is (init, debut, fin);

Type couleur is ( bleu, blanc, rouge);

36
Types entiers

Type INTEGER is range –2147 483 648 to 2 147 483 647 ;

Type petit_entier is range 0 to 15 ;

Type positif_8_bits is range 0 to 255 ;

37
Types flottants

Type REAL is range –1.0E38 to 1.0E38 ;

Type reel_perso is range 99.9 downto 0.0 ;

Type COSONUS is range -1.0 to +1.0 ;

38
Types physiques

Type CAPACITE is range 0 to 1E16


units
pF ; -- picoFarad
nF=1000pF ; -- nanoFarad
uF=1000nF ; -- microFarad
end units ;

39
Types Tableaux

Type Mot is array (1 to 8) of Bit;


Exp: s<=Mot(8);

Type Bit_vector is array (Natural range <>) of Bit ;


Rq: <>: intervalle défini lors de l’association avec l’objet

Type String is array (Positive range <>) of Character ;

Type matrice is array (1 to 4, 0 to 7) of bit;


Exp: s<=matrice(1,6);

40
Types enregistrements

Les enregistrements (RECORD) permettent de définir des collections de


valeurs elles-mêmes typées comme dans l´exemple suivant:

Type date is record


jour : natural range 1 to 31;
mois : string;
annee : integer range 0 to 4000;
end record;

exemple:
signal date_de_naissance : date ;
Date_de_naissance<= (29, JUIN, 1963);
Date_de_naissance.jour<=29 ;
41
Type fichier

Les fichiers (FILE) sont très utilisés par exemple pour


stocker des données telles que Mémoires ROM.

Type text is file of string;

42
Les Alias

Ils permettent de désigner sous un autre nom une partie d’une


grandeur. Par exemple appeler par signe le bit de poids fort
d’un mot de 16 bits.

Signal mot :std_logic_vector(15 downto 0) ;

Alias signe :std_logic is mot(15) ;

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

Il s’agit d’une interconnexion entre deux équipotentielles.

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

Une boucle est répétée plusieurs fois en fonction d’un indice.

Syntaxe:
for i in MIN to MAX generate
INSTRUCTIONS;
end generate ;

La suite d’instruction peut comprendre des grandeurs indexées par i


qui seront écrite par exemple D(i) et Q(i).

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

Vous aimerez peut-être aussi