Cours VHDL 10
Cours VHDL 10
Langage VHDL
VHSIC : Very High-Speed Integrated Circuits
HDL : Hardware Description Language
Objectif du module M21
Fournir une base solide pour que les étudiants en génie électrique comprennent et développent des
systèmes basés sur des microcontrôleurs dans divers contextes industriels et technologiques ;
Offrir une compréhension approfondie de la conception et de l'utilisation des FPGA dans divers
domaines de l'ingénierie électrique, en mettant l’accent sur la pratique et les applications réelles ;
Introduire l’utilisation d’outils avancée de modélisation de systèmes électroniques et
d'implémentation sur des FPGA.
2
Evaluation
- La note minimale pour valider le module doit être supérieure ou égale à 12
-La note minimale pour valider le composant module doit être supérieure ou égale à 12
La note du module : n = 0.50 x n1+ 0.50 x n2
3
Introduction aux FPGA
6
Architecture
7
Comparaison de solutions numériques
Langages de description matérielle
HDL
10
VHDL (HDL : Hardware Description Language)
Caractéristiques principales:
o description à plusieurs niveaux
o simulation activée par événements (event-driven)
o Modularité
o Extensibilité
o langage général, fortement typé
Entité et architecture
Au plus haut niveau d’abstraction, un système digital est vu comme une “boîte
noire”, dont on connaît l’interface avec l’extérieur
C’est l’entité (entity)
Une entité doit toujours être associée avec au moins une description de son
implémentation:
c’est l’architecture
Structure d’un programme VHDL
library ieee;
use ieee.std_logic_1164. all;
entity Telecom is
port (
Déclaration
des Nom de
entrées/sorties );
l’entité
end Telecom;
14
Les types (1)
VHDL est un langage fortement typé: toute donnée doit être déclarée
avant utilisation, en indiquant son type.
Par exemple:
Ces types ne sont pas prédéfinis: pour les utiliser, il faut déclarer le
paquet (package) std_logic_1164, qui fait partie de la
bibliothèque (library) IEEE:
library ieee;
use ieee.std_logic_1164. all ;
use ieee.std_logic_unsigned. all ;
Les types (4)
exemples
Q<=Q+1; -- Q est un std_logic_vector et 1 est un entier!!
A<B -- A et B des std_logic_vector
Data<=CONV_STD_LOGIC_VECTOR(TEMP,8);
o Avec la déclaration: TEMP integer range 0 to 255;
18
Le type std_logic
Une donnée de type std_logic possède une valeur parmi neuf possibles:
o ‘U’ uninitialized
o ‘X’ forcing unknown
o ‘0’ forcing 0
o ‘1’ forcing 1
o ‘Z’ high impedance
o ‘W’ weak unknown
o ‘L’ weak 0 (pull-down)
o ‘H’ weak 1 (pull-up)
o ‘-’ don’t care
Pour une affectation, les valeurs utilisées sont: ’X’, ‘0’, ‘1’, ‘Z’
Opérateurs (1)
Opérations de décalage
sll srl sla sra rol ror
Opérations de signe:
+ -
Opérateurs (2)
Relationnels ( retournent un boolean)
= /= < <= > >=
Arithmétiques
+ - * / MOD
A
S1
S2
B
24
Données traitées par VHDL
Toute donnée traitée par VHDL doit être déclarée comme
constante, variable ou signal
Constantes:
constant pi : real := 3.1416;
constant index_max : integer is 10*N;
Variables:
valeur modifiable immédiatement par une affectation (:=)
variable stop : boolean;
variable etat : CodeDEtat := ST0;
Signaux:
modélisation de l’entrée/sortie d’un dispositif.
C’est une forme d’onde qui change avec le temps: la modification a
lieu à la prochaine itération de la simulation (retard delta)
Signaux
Pour connecter les différents composants d’un système, VHDL utilise les
signaux (signal),
C’est l’équivalent des fils ou câbles d’interconnexion dans le monde réel
Initialisation
À éviter dans
Exemple: la synthèse
affectation
Signaux (suite)
On peut associer certains attributs aux signaux, qui produisent une valeur.
Exemples d’attributs :
o •s’ event :
(=vrai) si un événement arrive pendant le delta présent (c’est-à-dire, si le
signal s change de valeur)
o •s’ active:
(=vrai) si une transaction arrive pendant le delta présent (c’est-à-dire, si le
signal s est évalué, qu’il change ou pas de valeur)
library IEEE;
use IEEE.std_logic_1164.all;
entity ET3 is
port(
E : IN std_logic_vector(2 downto 0);
S : OUT std_logic
);
end ET3;
28
Logique combinatoire
Assignation simples 2
library IEEE;
use IEEE.std_logic_1164.all;
entity example is
port(
E:IN std_logic_vector(2 downto 0);
S1:OUT std_logic;
S2,S3:OUT std_logic_vector(3 downto 1);
S4:OUT std_logic_vector(2 downto 0)
);
end example;
29
Logique combinatoire: Instructions concurrentes
Assignation conditionnelle
Structure WHEN/ELSE
31
Logique combinatoire: Instructions concurrentes
Assignation sélective
with expression select
signal1 <= signal1when valeur 1,
signal2 when valeur2,
------
signal par défaut when others ;
32
Logique combinatoire: Instructions concurrentes
33
TD : additionneur 4 bits
étape 1: créer un composant ADDITIONNEUR 1 bits
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
34
TD : additionneur 4 bits
étape2: structurer le niveau supérieur ( comment faire 4 bits avec 1 bit?)
library IEEE;
use IEEE.std_logic_1164.all;
entity add4full is
port(
Cin:IN std_logic;
A:IN std_logic_vector(3 downto 0);
B:IN std_logic_vector(3 downto 0);
Res:OUT std_logic_vector(3 downto 0);
Cout:OUT std_logic
);
end add4full;
TD : additionneur 4 bits
étape2: structurer le niveau supérieur ( comment faire 4 bits avec 1 bit?)
begin
-- placement des 4 aditionneurs complets
U0: adit1 port map (Cin,A(0),B(0),Res(0),Fil1);
U1: adit1 port map (Fil1,A(1),B(1),Res(1),Fil2);
U2: adit1 port map (X=>A(2),Ci=>Fil2,Y=>B(2),Cout=>Fil3,S=>Res(2));
U3: adit1 port map (Fil3,A(3),B(3),Res(3),Cout);
end arch_add4full;
Exercice
37
Exercice
B1B0 > A1A0
38
Exercice
Réaliser puis simuler une bascule RS:
à portes NAND
à portes NOR
39
Processus (process)
Une architecture en VHDL est un ensemble de processus exécutés
en parallèle (en concurrence)
L’ordre relatif des processus à l’intérieur d’une architecture n’a
pas d’importance
Il existe deux types de processus:
le processus implicite ou phrase concurrente
le processus explicite
liste de sensibilité
begin
corps du processus
end process;
Logique séquentielle: le process
Le mot clé PROCESS
Syntaxe:
MONETIQUETTE : process (signal1, signal2 etc)
-- zone déclarative
Signal sFIL1,sFIL2 : xxxxxxxx
Begin
xxx
xxx
xxx
end process MONETIQUETTE;
Compteur Cpt
architecture DESCRIPTION of Compteur is
signal Compt : std_logic_vector (3 downto 0);
Rst begin
process (Rst , Clk)
begin
if Rst = '0' then
Compt <= "0000";
elsif (Clk ='1' and Clk 'event) then
Compt <= Compt + 1;
end if;
end process;
Cpt <= Compt ;
end DESCRIPTION;
43
Résumé d’instructions
VHDL
Conception de systèmes sur FPGA
49
Conception
d’un CI en
VHDL
50
Spécification
Validation fonctionnelle
Design correct
non
oui
Validation temporelle
Spécifications
non temporelles
correctes
oui
Programmation
Spécification : saisie du circuit logique (spécification syntaxique : VHDL, Verilog, mode graphique, etc.)
Implémentation : le programme est porté physiquement sur le circuit FPGA en fonction des spécifications
précisé par le programmeur (pins, etc.)
51
Outils de Conception
A S
B + R
53
Lancement de l’outil ISE
54
Création d’un nouveau projet
File>New Project
La fenêtre New Project Wizard – Create New Project apparaît, renseignez la avec les
valeurs voulues :
Project Name : nom de votre projet (attention pas d’espaces dans le nom)
Project Location : chemin de sauvegarde du projet et des fichiers associés
Top-Level Source Type : HDL
Cliquer sur Next
et renseigner les informations suivantes:
55
Editer le programme
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity bloc is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC;
R : out STD_LOGIC);
end bloc;
begin
S <= A xor B ;
R <= A and B ;
56
end Behavioral;
Synthèse
57
Testbench
VHDL est à la fois un langage de synthèse, et de simulation
Un testbenchVHDL est un code VHDL destiné à la vérification, par
simulation, du bon fonctionnement d’un système
Dans l’industrie, les testbenchs jouent un rôle très important ; ils sont
intégrés dans les spécifications d’un système
58
Structure d’un fichier VHDL
59
Exemple d’un programme à tester
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity porte is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
x : out STD_LOGIC);
end porte;
begin
x <= a xor b;
end Behavioral;
60
Fichier testbench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; signal E1: STD_LOGIC :='0';
signal E2: STD_LOGIC :='0';
entity testbench is signal S: STD_LOGIC ;
end testbench;
begin
architecture Behavioral of testbench is
uut: porte port map (a=>E1,
b=>E2, x=>S);
component porte is
E1<='1' after 100 ns, '0' after 300 ns;
Port ( a : in STD_LOGIC;
E2<='1' after 150 ns, '0' after 350 ns;
b : in STD_LOGIC;
x : out STD_LOGIC);
end Behavioral;
end component;
61
Exercice
A
S1
S2
B
62
TD
CLK
50MHz 1..10Hz 4Bits
Diviseur Compteur Codeur
Modulo 16 BCD/7Segments
Reset
Combinatoire
Séquentiel
entity diviseur is
PORT (
clk : in std_logic;
Div : out std_logic);
CLK Div
50MHz 1..10Hz
end diviseur;
Diviseur
architecture DESCRIPTION of diviseur is
signal CMP: std_logic_vector (24 downto 0);
begin
detection : process
begin
end DESCRIPTION;
entity diviseur is
PORT (
clk : in std_logic;
Div : out std_logic);
CLK Div
50MHz 1..10Hz
end diviseur;
Diviseur
architecture DESCRIPTION of diviseur is
signal CMP: std_logic_vector (24 downto 0);
begin
detection : process (clk)
begin
end DESCRIPTION;
entity Compteur is
PORT (
Clock 4Bits
Reset, Clock : in std_logic;
Compteur S : out std_logic_vector (3 downto 0));
Modulo 16
end Compteur ;
Reset
S0
S1
REG_DEC
CLOCK
Q3 Q2 Q1 Q0
68
IL I3 I2 I1 I0 IR
S0
S1
REG_DEC LIBRARY ieee;
CLOCK
USE ieee.std_logic_1164.all;
---------------------------------------
Q3 Q2 Q1 Q0
ENTITY Reg0 IS
PORT (
CLOCK, S0, S1 : IN STD_LOGIC;
IL, IR : in bit;
I : IN bit_VECTOR(3 downto 0);
Q : OUT bit_VECTOR(3 downto 0)
);
END Reg0;
69
ARCHITECTURE decaller OF Reg0 IS
IL I3 I2 I1 I0 IR
signal decal : bit_VECTOR(3 downto 0);
BEGIN
PROCESS (CLOCK)
S0 BEGIN
S1
REG_DEC IF (CLOCK'EVENT AND CLOCK='1') THEN
if(S0='0' and S1='1') then
CLOCK decal<=I;
else if(S0='1' and S1='0') then
Q3 Q2 Q1 Q0
decal<=decal SLL 1;
decal(0) <= IR ;
else if(S0='1' and S1='1') then
decal<=decal SRL 1;
decal(3) <= IL ;
end if;
end if;
end if;
END IF;
END PROCESS;
Q <= decal;
END decaller;
70
LIBRARY ieee;
USE ieee.std_logic_1164.all;
---------------------------------------
D Q
ENTITY bascule IS
PORT ( d, clk: IN STD_LOGIC;
q: BUFFER STD_LOGIC;
CLOCK Q
qbar: OUT STD_LOGIC
);
END bascule;
---------------------------------------
ARCHITECTURE ok OF bascule IS
BEGIN
PROCESS (clk)
BEGIN
IF (clk'EVENT AND clk='1') THEN
q <= d;
END IF;
END PROCESS;
qbar <= NOT q;
END ok;
71
LIBRARY ieee;
USE ieee.std_logic_1164.all;
Q0 Q1 Q2 Q3 ---------------------------------------
S1 1 ENTITY multiplexeur IS
PORT ( S : IN integer range 0 to 3;
S0 0
D Q : IN STD_LOGIC_VECTOR(3 downto 0);
D : OUT STD_LOGIC
);
END multiplexeur;
---------------------------------------
ARCHITECTURE choix OF multiplexeur IS
BEGIN
with S select
D<= Q(0) when 0,
Q(1) when 1,
Q(2) when 2,
Q(3) when 3;
END choix;
---------------------------------------
72
IL Q2 I3 Q3 Q3 Q1 I2 Q2 Q2 Q0 I1 Q1 Q1 IR I0 Q0
S1 S1 S1 S1
U1 U2 U3 U4
S0 S0 S0 S0
U5 U6 U7 U8
D Q D Q D Q D Q
Q Q Q Q
CLOCK
Q3 Q2 Q1 Q0
73
(Sortie série avec Choix du sens)
entity DECAL_DG is
port (CLK, SENS : in std_logic;
IN_OUT,OUT_IN : inout std_logic);
end DECAL_DG;
process(CLK)
begin
if (CLK'event and CLK='1') then
if SENS = '1' then
Q <= Q(2 downto 0) & IN_OUT;
else Q <= OUT_IN & Q(3 downto 1);
end if;
end if;
end process;
74 end ARCH_DECAL_DG;