Cours VHDL
Cours VHDL
Introduction au
langage VHDL pour la
Synthèse
12/16/2021 1
Qu’est ce qu’un circuit numérique
Assemblage intelligent de plusieurs
Transistor Switches
2
FPGA - Field Programmable Gate
Array
Programmable logic blocks (Logic Element “LE”)
a y
b N Input
LUT
c MUX D
SET
Q q
I/O
I/O
I/O
I/O
d
CLR Q
clk
rst
I/O
I/O
3
Les CLBs
◦ Les CLBs sont constitués de :
LUT (Look Up Table)
bascules D (Flip-Flop)
multiplexeurs
12/16/2021 4
Configuration de LUT
Ce sont de petits éléments de mémorisation, qui reflètent la table de vérité
d’une fonction logique
12/16/2021 6
I/O Blocs
Les blocs d’entrée/sortie (IOBs)
contrôlent le flot de données entre les
broches du FPGA et la logique interne
utilisateur; les I/O sont:
◦ Bidirectionnelles (entrée ou sortie)
◦ 3 états (haute impédance)
◦ A retards programmables
◦ Compatibles DDR (double-data rate) (dans
certaine architecture spartan 3E)
◦ Multi-standards (niveaux logiques,
différentiels…)
◦ Protégées ESD (…..)
12/16/2021 7
Horloge
Le signal d'horloge d'un FPGA vient généralement de l'extérieur. Il y a des
entrées spécialisées pour recevoir les signaux d'horloge et les distribuer
ensuite à l'intérieur du circuit. La distribution du signal d'horloge se fait par
le biais d'un arbre, minimisant ainsi les retards d'arrivée du signal aux flip-
flops les plus éloignés
12/16/2021 8
Organisation fonctionnelle de
développement d’un FPGA.
Entrée
Diagrammes
schématique
Entrée syntaxique d’états
langages:
- VHDL
9
Entrée syntaxique
Entrée Diagrammes
langages:
schématique d’états
- VHDL
VHDL VHDL VHDL
TESTBENCH
Vérification des erreurs Simulation
de schéma et de syntaxe comportementale
SYNTHETISEUR
SYNTHETISEURS CONNUS:
- FPGA Expres (Synosys). Il convertit en fonction du ciruit cible (CPLD ou
FPGA: suivant le modèle choisit) le projet en
- EXEMPLAR (Exemplar).
- SYNPLICITY (Synplicity). portes logiques et bascules de bases.
Simulation après
De plus on peut lui spécifier des contraintes de ou synthèse
technologies, par exemple la vitesse de
TESTBENCH
fonctionnement
La programmation du circuit
peut se faire soit:
- En utilisant un 10
programmateur.
Description
comportementale
Synthèse de haut
Comment faire?
niveau
Description RTL
Synthèse
RTL
Fonctions booléennes
Synthèse logique
Description en portes logiques
Placement
routage
11
[Link] d’une description
VHDL simple.
Une description VHDL est composée de 2 parties indissociables à
savoir :
Library
Library ieee;
ieee;
Use
Use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
Use
Use ieee.numeric_std.all;
ieee.numeric_std.all;
Use
Use ieee.std_logic_unsigned.all;
ieee.std_logic_unsigned.all;
--
-- cette dernière
cette dernière bibliothèque
bibliothèque est
est souvent
souvent utilisée
utilisée pour
pour l’écriture
l’écriture
de compteurs
de compteurs
13
2.2) Déclaration de l’entité et des
entrées / sorties (I/O).
Elle permet de définir le NOM de la description VHDL ainsi que les
entrées et sorties utilisées, l’instruction qui les définit c’est port :
Syntaxe:
entity NOM_DE_L_ENTITE is
port ( Description des signaux d’entrées /sorties …);
end NOM_DE_L_ENTITE;
Exemple :
entity SEQUENCEMENT is
port (
CLOCK : in std_logic;
RESET : in std_logic;
Q : out std_logic_vector(1 downto 0) );
end SEQUENCEMENT;
L’instruction port .
Syntaxe: NOM_DU_SIGNAL : sens type;
Exemple: CLOCK: in std_logic;
BUS : out std_logic_vector (7 downto 0);
On doit définir pour chaque signal : le NOM_DU_SIGNAL, le sens et le type.
14
2.2.1) Le NOM_DU_SIGNAL
15
2.2.2) Le SENS du signal.
- 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
Out
In
Entrée Inout
schématique
Buffer
16
2.2.3) Le TYPE.
Le TYPE utilisé pour les signaux d’entrées / sorties est :
- le std_logic pour un signal.
- le std_logic_vector pour un bus composé de plusieurs signaux.
17
3) Déclaration de l’architecture
correspondante à l’entité : description du
fonctionnement.
L’architecture décrit le fonctionnement souhaité pour un circuit
ou une partie du circuit.
En effet le fonctionnement d’un circuit est généralement décrit
par plusieurs modules VHDL. Il faut comprendre par module
le couple ENTITE/ARCHITECTURE. Dans le cas de simples
PLDs on trouve souvent un seul module.
L’architecture établit à travers les instructions les relations
entre les entrées et les sorties. On peut avoir un
fonctionnement purement combinatoire, séquentiel voire les
deux séquentiel et combinatoire.
Y7
19
Exemple 2
entity
entity DEC7SEG4
DEC7SEG4 is is
port LUT
port (DEC :in std_logic_vector(3 downto
(DEC :in std_logic_vector(3 downto 0);
0); DEC(3:0) SEG(6:0)
SEG
SEG :out std_logic_vector(6 downto 0));
:out std_logic_vector(6 downto 0));
end DEC7SEG4;
end DEC7SEG4;
architecture
architecture DESCRIPTION
DESCRIPTION of of DEC7SEG4
DEC7SEG4 isis
begin
begin Synthèse
SEG
SEG <=
<= "1111110“
"1111110“ when
when DEC
DEC =
=0 0
else "0110000" when DEC
else "0110000" when DEC = 1 = 1
else
else "1101101"
"1101101" whenwhen DEC
DEC =
=2 2
else
else "1111001“ when DEC = 3
"1111001“ when DEC = 3
else
else "0110011“
"0110011“ when
when DEC
DEC =
=4 4
else
else "1011011"
"1011011" whenwhen DEC
DEC =
=5 5
else "1011111" when DEC
else "1011111" when DEC = 6 = 6
else
else "1110000“
"1110000“ whenwhen DEC
DEC =
=7 7
else "1111111" when DEC
else "1111111" when DEC = 8 = 8
else
else "1111011"
"1111011" when
when DEC
DEC =
=99
else "-------";
else "-------";
end
end DESCRIPTION;
DESCRIPTION;
20
4) Les instructions de base (mode
« concurrent »), logique combinatoire.
Qu’est ce que le mode « concurrent » ? Pour une description VHDL toutes les instructions sont
évaluées et affectent les signaux de sortie en même temps. L’ordre dans lequel elles sont écrites n’a
aucune importance. En effet la description génère des structures électroniques, c’est la grande
différence entre une description VHDL et un langage informatique classique.
Dans un système à microprocesseur, les instructions sont exécutées les unes à la suite des autres.
Avec VHDL il faut essayer de penser à la structure qui va être générée par le synthétiseur pour
écrire une bonne description, cela n’est pas toujours évident
21
4.1) Les opérateurs.
4.1.1) L’affectation simple : <=
Dans une description VHDL, c’est certainement l’opérateur le plus utilisé. En effet il
permet de modifier l’état d’un signal en fonction d’autres signaux et/ou d’autres opérateurs.
S1
S1 <=
<= E2
E2 and
and E1
E1 ;;
Les valeurs numériques que l’on peut affecter à un signal sont les suivantes :
- ‘1’ ou ‘H’ pour un niveau haut avec un signal de 1 bit.
- ‘0’ ou ‘L’ pour un niveau bas avec un signal de 1 bit.
- ‘Z’ pour un état haute impédance avec un signal de 1 bit.
- ‘-’ pour un état quelconque, c’est à dire ‘0’ ou ‘1’. Cette valeur est très utilisée
avec les instructions : when … else et with …. Select ….
- Pour les signaux composés de plusieurs bits on utilise les guillemets
" … " , voir les exemples ci dessous :
- Les bases numériques utilisées pour les bus peuvent être :
BINAIRE, exemple : BUS <= "1001" ; -- BUS = 9 en décimal
HEXA, exemple : BUS <= X"9" ; -- BUS = 9 en décimal
OCTAL, exemple : BUS <= O"11" ; -- BUS = 9 en décimal
22
Exemple 3
Library
Library ieee;
ieee;
Use
Use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
entity
entity AFFEC
AFFEC is is
port
port ((
E1,E2
E1,E2 :: inin std_logic;
std_logic;
BUS1,BUS2,BUS3
BUS1,BUS2,BUS3 :: out out std_logic_vector(3
std_logic_vector(3 downtodownto 0);
0);
S1,S2,S3,S4
S1,S2,S3,S4 : out std_logic);
: out std_logic);
end
end AFFEC;
AFFEC;
architecture
architecture DESCRIPTION
DESCRIPTION of of AFFEC
AFFEC is is
begin
begin
S1
S1 <=
<= '1';
'1'; --
-- S1
S1 == 11
S2
S2 <= '0'; -- S2 =
<= '0'; -- S2 =0 0
S3 <= E1; -- S3
S3 <= E1; -- S3 = E1 = E1
S4
S4 <=
<= '1'
'1' when
when (E2(E2 ='1')
='1') else
else 'Z';
'Z'; --
-- S4
S4 == 11 si
si E1=1
E1=1 sinon
sinon S4--
S4-- prend
prend
--la valeur haute impédance
--la valeur haute impédance
BUS1
BUS1 <= <= "1000";
"1000"; -- -- BUS1
BUS1 == "1000"
"1000"
BUS2
BUS2 <= E1 & E2 & "10"; -- BUS2
<= E1 & E2 & "10"; -- BUS2 = = E1
E1 &
& E2
E2 & & 10
10
BUS3 <= x"A"; -- valeur en HEXA ->
BUS3 <= x"A"; -- valeur en HEXA -> BUS3 = 10(déc)BUS3 = 10(déc)
end
end DESCRIPTION;
DESCRIPTION;
23
4.1.2) Opérateur de concaténation : &.
Opérateur VHDL
Exemple 1:
ET AND
--
-- Soit
Soit A
A et
et B
B de
de type
type 33 bits
bits et
et S1
S1 de
de type
type 8
8 bits
bits
--
-- A
A== "001"
"001" et
et BB ="110"
="110" NON ET NAND
S1
S1 <=
<= A
A& &B
B& & "01"
"01" ;;
-- OU OR
-- S1
S1 prendra
prendra la
la valeur
valeur suivante
suivante après
après cette
cette affectation
affectation
--
-- S1
S1 =
= "001110
"001110 01"
01" NON OU NOR
OU EXCLUSIF XOR
Valeur
Valeur de
de A
A Valeur
Valeur de
de B
B
"001"
"001" "110"
"110" NON OU EXCLUSIF XNOR
NON NO
4.1.3) Opérateurs logiques :
DECALAGE A GAUCHE SLL
Exemple 2:
DECALAGE A DROITE SRL
S1
S1 <=
<= A
A sll
sll 2
2 ;; --
-- S1
S1 =
=AA décalé
décalé de
de 2
2 bits
bits à
à gauche.
gauche.
S2
S2 <=
<= A
A rol
rol 33 ;; --
-- S2
S2 ==A
A avec
avec une
une rotation
rotation de
de 3
3 bits
bits à
à ROTATION A GAUCHE ROL
-- gauche
-- gauche ROTATION A DROITE ROR
S3
S3 <=
<= not
not (R);
(R);
24
Décalage à droite :
--
-- Si
Si A
A est
est dede type
type std_logic_vector(7
std_logic_vector(7 downto
downto 0)
0)
S1
S1 <=
<= ‘0’
‘0’ &
& A(7
A(7 downto
downto 1);
1); --
-- décalage
décalage d’un
d’un bit
bit à
à droite
droite
S1
S1 <= "000" & A(7 downto 3); -- décalage de trois bits à
<= "000" & A(7 downto 3); -- décalage de trois bits à droite
droite
Décalage à gauche :
--
-- Si
Si A
A est
est de
de type
type std_logic_vector(7
std_logic_vector(7 downto
downto 0)0)
S1 Remarque N°1 : Pour pouvoir utiliser les
S1 <= A(6 downto 0) & ‘0’; -- décalage d’un bit à
<= A(6 downto 0) & ‘0’; -- décalage d’un bit à gauche
gauche
S1 opérateurs arithmétiques il faut rajouter les
S1 <= A(4 downto 0) & "000"; -- décalage de trois bits à
<= A(4 downto 0) & "000"; -- décalage de trois bits à gauche
gauche
bibliothèques suivantes au début du fichier VHDL:
Opérateur VHDL
S1
S1 <=
<= A
A –– 3
3 ;; --
-- S1
S1 ==AA –– 3
3
ADDITION + --
-- On soustrait 3 à la valeur de
On soustrait 3 à la valeur de l’entrée
l’entrée /
/ signal
signal A
A
SOUSTRACTION - S1 <= S1 + 1 ; -- On incrémente de 1 le signal
S1 <= S1 + 1 ; -- On incrémente de 1 le signal S1 S1
MULTIPLICATION * S1
S1 <=
<= A
A –– 3
3 ;; --
-- S1
S1 ==AA –– 3
3
--
-- On soustrait 3 à la valeur de
On soustrait 3 à la valeur de l’entrée
l’entrée /
/ signal
signal A
A
S1
S1 <=
<= S1
S1 ++1 1 ;; --
-- On
On incrémente
incrémente dede 1
1 le
le signal
signal S1
S1
DIVISION /
Remarque N°2 : Attention l’utilisation de ces
opérateurs avec des signaux comportant un nombre
de bits important peut générer de grandes
structures électroniques.
S
S11 <=
<= A
A**BB ;--
;-- S1
S1 =
=AA multiplié
multiplié par
par B
B :: A
A et
et B
B sont
sont codés
codés sur
sur 4
4 bits
bits
S2 <= A / B ;-- S2 = A divisé par B : A et B sont codés sur 4 bits
S2 <= A / B ;-- S2 = A divisé par B : A et B sont codés sur 4 bits
25
4.1.5) Opérateurs relationnels
Ils permettent de modifier l’état d’un signal ou de signaux suivant le résultat d’un test ou
d’une condition. En logique combinatoire ils sont souvent utilisés avec les instructions :
- when … else …
- with …. Select ….
Opérateur VHDL
Egal =
Non égal /=
Inférieur <
Supérieur >
26
4.2) Les instructions du mode «concurrent ».
4.2.1) Affectation conditionnelle :
Cette instruction modifie l’état d’un signal suivant le résultat d’une condition logique entre un ou des signaux,
valeurs, constantes.
SIGNAL
SIGNAL <=
<= expression
expression when
when condition
condition
[else
[else expression when condition]
expression when condition]
[else
[else expression];
expression];
Exemple 1: Exemple 2:
--
-- S1
S1 prend
prend la
la valeur
valeur de
de E2
E2 quand
quand E1=’1’
E1=’1’ sinon
sinon S1
S1 prend
prend la
la --
-- Structure
Structure évoluée
évoluée d’un
d’un multiplexeur
multiplexeur 4
4 vers
vers 11
-- valeur ‘0’
-- valeur ‘0’ S2
S2 <=
<= E1
E1 when
when (SEL="00"
(SEL="00" )) else
else
S1
S1 <=
<= E2
E2 when
when (( E1=
E1= ‘1’)
‘1’) else
else ‘0’;
‘0’; E2 when (SEL="01" ) else
E2 when (SEL="01" ) else
E3
E3 when
when (SEL="10"
(SEL="10" )) else
else
E4
E4 when (SEL="11"
when (SEL="11" ))
Schéma correspondant : else
else ‘0’;
‘0’;
27
4.2.2) Affectation sélective :
Cette instruction permet d’affecter différentes valeurs à un signal, selon les valeurs prises par un signal
dit de sélection.
with
with SIGNAL_DE_SELECTION
SIGNAL_DE_SELECTION selectselect
SIGNAL
SIGNAL <=
<= expression
expression when
when valeur_de_selection,
valeur_de_selection,
[expression
[expression when
when valeur_de_selection,]
valeur_de_selection,]
[expression
[expression when
when others];
others];
Remarque: l’instruction [expression when others] n’est pas obligatoire mais fortement
conseillée, elle permet de définir la valeur du SIGNAL dans le cas où la condition n’est pas
remplie.
Exemple 1:
--
-- Multiplexeur
Multiplexeur 44 vers
vers 11
with SEL select
with SEL select
S2
S2 <=
<= E1
E1 when
when "00",
"00",
E2
E2 when "01",
when "01",
E3
E3 when
when "10",
"10",
E4
E4 when
when "11",
"11",
‘0'
‘0' when others;
when others;
Remarque: when others est nécessaire car il faut toujours définir les autres
cas du signal de sélection pour prendre en compte toutes les valeurs possibles
de celui-ci. Schéma correspondant après synthèse:
28
Exemple 2: Affectation sélective avec
les autres cas forcés à ‘0’.
Library
Library ieee;
ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_1164.all;
entity
entity TABLE1
TABLE1 is is
port
port ( (
E1,E2
E1,E2 :: inin std_logic;
std_logic; Schéma correspondant après synthèse:
SEL
SEL :: inin std_logic_vector(1
std_logic_vector(1 downto
downto 0);
0);
S2 : out std_logic);
S2 : out std_logic);
end
end TABLE1;
TABLE1;
architecture
architecture DESCRIPTION
DESCRIPTION of of TABLE1
TABLE1 is
is
begin
begin
with
with SELSEL select
select
S2
S2 <= E1 when
<= E1 when "00",
"00",
E2 when "01",
E2 when "01",
'0'
'0' when
when others;
others;
--
-- Pour les autres cas de
Pour les autres cas de SEL
SEL S2
S2
--
-- prendra
prendra la la valeur
valeur 0
0 logique
logique
end
end DESCRIPTION;
DESCRIPTION;
29
Exemple 3: Affectation sélective avec
les autres cas forcés à ‘1’.
Library
Library ieee;
ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_1164.all;
entity
entity TABLE1
TABLE1 is is
port
port ( (
E1,E2
E1,E2 :: inin std_logic;
std_logic; Schéma correspondant après synthèse:
SEL
SEL :: inin std_logic_vector(1
std_logic_vector(1 downto
downto 0);
0);
S2 : out std_logic);
S2 : out std_logic);
end
end TABLE1;
TABLE1;
architecture
architecture DESCRIPTION
DESCRIPTION of of TABLE1
TABLE1 is
is
begin
begin
with
with SELSEL select
select
S2
S2 <= E1 when
<= E1 when "00",
"00",
E2 when "01",
E2 when "01",
‘1'
‘1' when
when others;
others;
--
-- Pour les autres cas
Pour les autres cas dede SEL
SEL S2
S2
--
-- prendra
prendra la la valeur
valeur 11 logique
logique
end
end DESCRIPTION;
DESCRIPTION;
30
Exemple 4: Affectation sélective avec
les autres cas forcés à ‘-’.
Library
Library ieee;
ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_1164.all;
entity
entity TABLE1
TABLE1 is is
port
port ( (
E1,E2
E1,E2 :: inin std_logic;
std_logic; Schéma correspondant après synthèse:
SEL
SEL :: inin std_logic_vector(1
std_logic_vector(1 downto
downto 0);
0);
S2 : out std_logic);
S2 : out std_logic);
end
end TABLE1;
TABLE1;
architecture
architecture DESCRIPTION
DESCRIPTION of of TABLE1
TABLE1 is
is
begin
begin
with
with SELSEL select
select
S2
S2 <= E1 when
<= E1 when "00",
"00",
E2 when "01",
E2 when "01",
‘-'
‘-' when
when others;
others;
--
-- Pour les autres cas
Pour les autres cas de
de SEL
SEL S2
S2
--
-- prendra
prendra la la valeur
valeur quelconque
quelconque
end
end DESCRIPTION;
DESCRIPTION;
31
5) Les instructions du mode séquentiel.
5.1) Définition d’un PROCESS.
Un process est une partie de la description d’un circuit dans laquelle les instructions
sont exécutées séquentiellement c’est à dire les unes à la suite des autres.
Il permet d’effectuer des opérations sur les signaux en utilisant les instructions standard
de la programmation structurée comme dans les systèmes à microprocesseurs.
L’exécution d’un process est déclenchée par un ou des changements d’états de signaux
logiques. Le nom de ces signaux est défini dans la liste de sensibilité lors de la
déclaration du process.
Remarque: Le nom du process entre crochet est facultatif, mais il peut être très utile
pour repérer un process parmi d’autres lors de phases de mise au point ou de simulations.
32
5.3) Exemples de process :
Schéma correspondant après synthèse:
Exemple N°1 :
Déclaration d’une bascule D.
Library
Library ieee;
ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_1164.all;
entity
entity BASCULED
BASCULED is is
port
port ( (
D,CLK
D,CLK :: in
in std_logic;
std_logic;
S : out std_logic);
S : out std_logic); Commentaires
end
end BASCULED;
BASCULED; - Seul le signal CLK fait partie de la liste de
architecture
architecture DESCRIPTION
DESCRIPTION of of BASCULED
BASCULED is
is sensibilité. D’après les règles de fonctionnement
begin
begin énoncées précédemment, seul un changement d’état du
PRO_BASCULED
PRO_BASCULED :: processprocess (CLK)
(CLK) signal CLK va déclencher le process et par conséquent
begin
begin évaluer les instructions de celui-ci.
if
if (CLK'event
(CLK'event andand CLK
CLK ='1')
='1') then
then - L’instruction if (CLK'event and CLK='1') then permet
S <= D;
S <= D; de détecter un front montant du signal CLK. La
end
end if;
if; détection de front est réalisée par l’attribut event
end
end process
process PRO_BASCULED;
PRO_BASCULED; appliqué à l’horloge CLK. Si on veut un déclenchement
end DESCRIPTION;
end DESCRIPTION; sur un front descendant, il faut écrire l’instruction
suivante : if (CLK'event and CLK='0').
- Les bibliothèques IEEE possèdent deux instructions
permettant de détecter les fronts montants )
rising_edge(CLK) ou descendants falling_edge(CLK).
- Si la condition est remplie alors le signal de sortie S
sera affecté avec la valeur du signal d’entrée D.
33
Exemple N°2 :
compteur avec retenue (fonctionnement incorrect).
Library
Library ieee;
ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_1164.all;
Use
Use ieee.numeric_std.all;
ieee.numeric_std.all;
Use
Use ieee.std_logic_unsigned.all;
ieee.std_logic_unsigned.all;
entity
entity CMP4BITSRET
PORT (
CMP4BITSRET is is Schéma correspondant après synthèse:
PORT (
RESET,
RESET, CLOCKCLOCK :: inin std_logic;
std_logic;
RET : out std_logic;
RET : out std_logic;
Q
Q :: out
out std_logic_vector
std_logic_vector (3 (3 downto
downto 0));
0));
end
end CMP4BITSRET;
CMP4BITSRET;
architecture
architecture DESCRIPTION
DESCRIPTION of of CMP4BITSRET
CMP4BITSRET is
is
signal
signal CMP:
CMP: std_logic_vector
std_logic_vector (3 (3 downto
downto 0);
0);
begin
begin
process
process (RESET,CLOCK)
(RESET,CLOCK)
begin
begin
if
if RESET
RESET ='1' ='1' then
then
CMP
CMP <= <= "0000";
"0000";
elsif
elsif (CLOCK
(CLOCK ='1'='1' and
and CLOCK'event)
CLOCK'event) then
then
CMP
CMP <= <= CMP
CMP ++ 1;
1;
if
if (CMP
(CMP = = "1111")
"1111") then
then
RET
RET <=
<= '1';
'1';
else
else
RET
RET <=
<= '0';
'0';
end
end if;if;
end
end if;
if;
end
end process;
process;
Q
Q <=
<= CMP;
CMP;
end
end DESCRIPTION;
DESCRIPTION;
34
Structure d’une description VHDL
Une description VHDL se compose de deux parties:
Comment faire?
35
1. Modèle comportemental :
Modèle comportemental :
description du fonctionnement du système :
- algorithmes, machine d’états
algorithme proche de ceux des langages de programmation
le temps peut intervenir :
- permet de coller à la réalité par le respect des temps de traversée
une description haut niveau est d’abord comportementale :
- elle sert de référence pour la suite de la conception
Exemple 1
Modèle comportemental
A B Cin S Cout A
0 0 0 0 0 S
B Sans référence à des
0 0 1 1 0 Additionneur structures ou des équations
0 1 0 1 0 1 Bit
Cin Cout
0 1 1 0 1 Comment faire?
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1 36
1. Modèle comportemental :
architecture
architecture comportementale
comportementale of
of Additionneur
Additionneur is
is
begin
begin
process(A,B,Cin)
process(A,B,Cin)
begin
begin
Exemple 1
if
if (A
(A ='0'
='0' and
and B='0'
B='0' and
and Cin='0'
Cin='0' )) then
then
Sum<='0';Cout<='0';
Sum<='0';Cout<='0';
elsif
elsif (A
(A ='0'
='0' and
and B='0'
B='0' and
Sum<='1';Cout<='0';
Sum<='1';Cout<='0';
and Cin='1'
Cin='1' )) then
then A
elsif
elsif (A
(A ='0'
='0' and
and B='1'
B='1' and
and Cin='0'
Cin='0' )) then
then Sum
Sum<='1';Cout<='0';
Sum<='1';Cout<='0'; B
Additionneur
elsif
elsif (A
(A ='0'
='0' and
and B='1'
B='1' and
and Cin='1'
Cin='1' )) then
Sum<='0';Cout<='1';
Sum<='0';Cout<='1';
then
1 Bit
Cin Cout
elsif
elsif (A
(A ='1'
='1' and
and B='0'
B='0' and
and Cin='0'
Cin='0' )) then
then
Sum<='1';Cout<='0';
Sum<='1';Cout<='0';
elsif
elsif (A
(A ='1'
='1' and
and B='0'
B='0' and
and Cin='1'
Cin='1' )) then
then
Sum<='0';Cout<='1';
Sum<='0';Cout<='1';
elsif
elsif (A
(A ='1'
='1' and
and B='1'
B='1' and
and Cin='0'
Cin='0' )) then
then
Sum<='0';Cout<='1';
Sum<='0';Cout<='1';
else
else
Sum<='1';Cout<='1';
Sum<='1';Cout<='1';
end
end if;
if;
end
end process;
process; ;;
end comportementale
end comportementale
37
1. Modèle comportemental :
library
library IEEE;
IEEE;
use
use IEEE.STD_LOGIC_1164.ALL;
IEEE.STD_LOGIC_1164.ALL;
use
use IEEE.STD_LOGIC_ARITH.ALL;
IEEE.STD_LOGIC_ARITH.ALL; Exemple 2
use
use IEEE.STD_LOGIC_UNSIGNED.ALL;
IEEE.STD_LOGIC_UNSIGNED.ALL;
entity
entity Mux21_comportementale
Mux21_comportementale is is
Port
Port (( A
A :: in
in STD_LOGIC;
STD_LOGIC;
B
B :: in
Sel
in STD_LOGIC;
STD_LOGIC; A
Sel :: in
in STD_LOGIC;
STD_LOGIC;
MUX2-1
S
S :: out
out STD_LOGIC);
MUX2-1
STD_LOGIC); Modèle
end
end Mux21_comportementale;
Mux21_comportementale;
comportemental S
architecture
architecture Behavioral
Behavioral of
of Mux21_comportementale
Mux21_comportementale is
is
B
begin
begin
S
S <=
<= AA WHEN
WHEN Sel='0'
Sel='0' ELSE
ELSE B
B WHEN
WHEN Sel='1'
Sel='1' ELSE
ELSE
'X';
'X';
end
end Behavioral;
Behavioral;
Sel
38
2. Modèle Flot des données :
AB 00 01 11 10 AB 00 01 11 10
A B Cin S Cout Cin Cin
0 0 1 0 1 0 0 0 1 0
0 0 0 0 0
1 1 0 1 0 1 0 1 1 1
0 0 1 1 0
S Cout
0 1 0 1 0
S=A xor B xor Cin Cout=(A and B ) or
0 1 1 0 1
Cin (A xor B)
1 0 0 1 0 Exemple 1
1 0 1 0 1
A
1 1 0 0 1
1 1 1 1 1 S
B équations booléennes
Additionneur
1 Bit
Cin Cout Comment faire?
39
2. Modèle Flot des données :
Comment faire?
library
library IEEE;
IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_1164.ALL;
use
use IEEE.STD_LOGIC_ARITH.ALL;
IEEE.STD_LOGIC_ARITH.ALL;
use
use IEEE.STD_LOGIC_UNSIGNED.ALL;
IEEE.STD_LOGIC_UNSIGNED.ALL;
entity
entity Additionneur_FD
Additionneur_FD is is
A
Port
Port (( A
A :: in
in STD_LOGIC;
STD_LOGIC;
B
B :: in
in STD_LOGIC;
STD_LOGIC; S
Cin
Cin :: in
in STD_LOGIC;
STD_LOGIC; B
S
S :: out
Cout
out STD_LOGIC;
STD_LOGIC; Additionneur
Cout :: out
out STD_LOGIC);
STD_LOGIC);
end
end Additionneur_FD;
Additionneur_FD; 1 Bit
Cin
architecture
architecture Behavioral
Behavioral of
of Additionneur_FD
Additionneur_FD is
is Cout
begin
begin
S<=
S<= A
A xor
xor B
B xor
xor Cin;
Cin;
Cout<=
Cout<= (A
(A and
and B)
B) or
or (Cin
(Cin and
and (A
(A xor
xor B));
B));
end
end Behavioral;
Behavioral;
40
2. Modèle Flot des données :
Exemple 2 S= not(Sel). A + Sel .B
équations
booléennes
library
library IEEE;
IEEE;
use
use IEEE.STD_LOGIC_1164.ALL;
IEEE.STD_LOGIC_1164.ALL;
A use
use IEEE.STD_LOGIC_ARITH.ALL;
IEEE.STD_LOGIC_ARITH.ALL;
use
use IEEE.STD_LOGIC_UNSIGNED.ALL;
IEEE.STD_LOGIC_UNSIGNED.ALL;
MUX2-1
MUX2-1
S entity
entity Mux21_FD
Mux21_FD is
Port
is
Port (( A
A :: in
in STD_LOGIC;
STD_LOGIC;
B
B :: in
in STD_LOGIC;
B Sel
Sel : in
:
STD_LOGIC;
in STD_LOGIC;
STD_LOGIC;
S
S :: out
out STD_LOGIC);
STD_LOGIC);
end
end Mux21_FD;
Mux21_FD;
architecture
architecture Behavioral
Behavioral of
of Mux21_FD
Mux21_FD is
is
begin
begin
S<=
S<= (not(sel)and
(not(sel)and A)
A) OR
OR (sel
(sel and
and B)
B) ;;
Sel end
end Behavioral;
Behavioral;
41
3. Architecture structurelle
•L’architecture str de l’exemple fait référence à la même déclaration d’entité que le modèle
comportemental précédent
•Elle est composée de 2 parties :
–La déclaration des composants utilisés
–L’instanciation des composants et leur interconnexion
•On peut utiliser une connexion
–explicite par nom
•Chaque instance a sa propre étiquette unique
•Une étape supplémentaire de configuration sera nécessaire pour associer une entité à chaque
instance de composant utilisé dans le modèle structurel
Logic
Logic Interconnection
Interconnection switches
switches
block
block
I/O
I/O
I/O
I/O
I/O
I/O
42
I/O
3. Architecture structurelle
COMPONENT 2
COMPONENT 1
ENTITY
ENTITY half_adder
half_adder IS
Sum IS
In2 PORT
PORT (a,b: IN
(a,b: IN std_logic;
std_logic;
Additionneur END
s,cout:
s,cout: OUT
OUT std_logic);
std_logic);
half_adder;
END half_adder;
1 Bit ARCHITECTURE
ARCHITECTURE beh beh OF
OF half_adder
half_adder IS
IS
Cin begin
begin
Carry ss <=
<= a
a XOR
cout<=
XOR b;
b;
cout<= aa AND
AND b;
b;
end
end beh;
beh;
library
library IEEE;
IEEE;
use
use IEEE.STD_LOGIC_1164.ALL;
IEEE.STD_LOGIC_1164.ALL;
use
use IEEE.STD_LOGIC_ARITH.ALL;
In1 use
IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
IEEE.STD_LOGIC_UNSIGNED.ALL;
A
A Cout
Cout
ENTITY
ENTITY OR_2
OR_2 IS
IS
PORT(a,b:
PORT(a,b: ININ std_logic;
HalfAdder
HalfAdder carry std_logic;
In2 END
c:
c: OUT
OR_2;
END OR_2;
OUT std_logic);
std_logic);
B
B S
S A
A Cout
Cout ARCHITECTURE
ARCHITECTURE beh beh OF
OF OR_2
OR_2 IS
IS
Begin
Begin
c
c <=
<= a
a OR
OR b;
b;
HalfAdder
HalfAdder end beh;
Cin Sum end beh;
B
B S
S
44
3. Architecture structurelle
Exemple 1 library
library IEEE;
IEEE;
use
use IEEE.STD_LOGIC_1164.ALL;
IEEE.STD_LOGIC_1164.ALL;
use
use IEEE.STD_LOGIC_ARITH.ALL;
In1 use
IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY
ENTITY full_adder
full_adder IS*
Sum IS*
In2 PORT(in1,in2,cin:
PORT(in1,in2,cin: IN
IN std_logic;
std_logic;
Additionneur END
sum,carry:
sum,carry: OUT
OUT std_logic);
std_logic);
END full_adder;
full_adder;
1 Bit ARCHITECTURE
ARCHITECTURE structural
structural OF
OF full_adder
full_adder
Cin
Carry COMPONENT
COMPONENT half_adder
PORT(a,b:
half_adder
PORT(a,b: IN
IN std_logic;
std_logic;
s,cout:
s,cout: OUT
OUT std_logic);
std_logic);
END
END COMPONENT;
COMPONENT;
COMPONENT
COMPONENT OR_2OR_2
PORT(a,b:
PORT(a,b: IN std_logic;
IN std_logic;
c
c :: OUT
OUT std_logic);
std_logic);
In1 END
END COMPONENT;
COMPONENT;
A
A Cout
Cout s2
SIGNAL
SIGNAL s1,s2,s3
s1,s2,s3 :: std_logic;
std_logic;
BEGIN
BEGIN
HalfAdder
HalfAdder carry H1
H1 :: half_adder
half_adder PORT MAP(in1,in2, s1,
PORT MAP(in1,in2, s1, s2);
s2);
In2 s1 H2
H2 :: half_adder
half_adder PORT
PORT MAP(s1,cin, sum,s3);
MAP(s1,cin, sum,s3);
O1
O1 :: or_2
or_2 PORT
PORT MAP(s2,s3,
MAP(s2,s3, carry);
carry);
B
B S
S A
A Cout
Cout END
END structural;
s3 structural;
HalfAdder
HalfAdder
Cin Sum
B
B S
S
45
3. Architecture structurelle
Exemple 2 library
library IEEE;
IEEE;
use
use IEEE.STD_LOGIC_1164.ALL;
IEEE.STD_LOGIC_1164.ALL;
use
use IEEE.STD_LOGIC_ARITH.ALL;
IEEE.STD_LOGIC_ARITH.ALL;
IN1 use
use IEEE.STD_LOGIC_UNSIGNED.ALL;
IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity
Entity add1
add1 is
is
Sum Port
Port (( IN1,IN2,
IN1,IN2, Cin
Cin :: in
in STD_LOGIC;
IN2 Carry, sum : out STD_LOGIC;
STD_LOGIC;
Additionneur Carry, sum : out STD_LOGIC;
end
end add1;
add1;
1 Bit ARCHITECTURE
ARCHITECTURE structure
structure OFOF add1
add1 IS
Cin COMPONENT
COMPONENT et PORT(e1,e2:IN std_logic;
et PORT(e1,e2:IN
IS
std_logic; s:OUT
Carry std_logic);
std_logic);
s:OUT
o1 x1 a1:
a1: et
et PORT
PORT MAP
MAP (IN1,IN2,f1);
(IN1,IN2,f1);
a2:
a2: et PORT MAP
et PORT MAP (f3,Cin,f2);
(f3,Cin,f2);
f2
Cette description f3 o1:
o1: ou
ou PORT
PORT MAP
MAP (f1,f2,Carry);
(f1,f2,Carry);
x1:
x1: oux
oux PORT
PORT MAPMAP (IN1,IN2,f3);
(IN1,IN2,f3);
structurelle utilise a2 x2:
r1 x2: oux
oux PORT
PORT MAP
MAP (f3,Cin,Sum);
(f3,Cin,Sum);
des portes et, ou et END
END structure;
structure;
oux (ou-exclusif). Cin
x2
entity
entity Mux21_FD
Mux21_FD is is
Port
Port (( A
A :: in
in STD_LOGIC;
STD_LOGIC;
A B
B :: in
sel
in STD_LOGIC;
STD_LOGIC;
sel : in STD_LOGIC;
: in STD_LOGIC;
MUX2-1
S
S :: out
out STD_LOGIC);
MUX2-1
STD_LOGIC);
S end Mux21_FD;
end Mux21_FD;
ARCHITECTURE
ARCHITECTURE structure
structure OFOF mux2
mux2 IS
IS
B --
-- déclarations de modèles de composants
déclarations de modèles de composants
sel bs COMPONENT
COMPONENT inv inv
a2 PORT(e:IN
PORT(e:IN std_logic;
std_logic;
B S END
s:OUT
s:OUT std_logic);
std_logic);
COMPONENT;
END COMPONENT;
o1 COMPONENT
COMPONENT et et
n1 nsel PORT(e1,e2:IN
PORT(e1,e2:IN std_logic;
std_logic;
s:OUT
s:OUT std_logic);
std_logic);
END
END COMPONENT;
Sel A a1
as
COMPONENT;
COMPONENT
COMPONENT ou ou
PORT(e1,e2:IN
PORT(e1,e2:IN std_logic;
std_logic;
s:OUT
s:OUT std_logic);
std_logic);
END
END COMPONENT;
COMPONENT;
--
-- déclarations
déclarations dede signaux
signaux internes
internes (fils)
(fils)
SIGNAL nsel,as,bs: std_logic;
SIGNAL nsel,as,bs: std_logic;
RQ: On suppose que les --
-- instanciation
instanciation etet cablage
cablage des
des composants
composants (schéma)
(schéma)
BEGIN
composants logiques déjà BEGIN
n1:
n1: inv
inv PORT
PORT MAP
MAP (sel,nsel);
(sel,nsel);
a1:
a1: et PORT MAP (nsel,A,as);
et PORT MAP
crées en VHDL a2:
(nsel,A,as);
a2: et
et PORT
PORT MAP
MAP (sel,B,bs);
(sel,B,bs);
o1:
o1: ou PORT MAP (bs,as,S);
ou PORT MAP (bs,as,S);
END
END structure;
structure;
47