chapitre 5: langage vhdl · chapitre 5: langage vhdl introduction avantages des langages de...

33
1 ELE3311– Systèmes logiques programmables Philippe Levesque, Ph.D. Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels de base du VHDL Entity, Architecture, Package, Library, Component Type, Mode Signal, Variable Descriptions: Structurelle, Comportementale, Mixte Exemples Points à retenir ELE3311– Systèmes logiques programmables P. Levesque Introduction VHDL – VHSIC Hardware Description Language VHSIC – Very High Speed Integrated Circuit Origine: développé pour le Département de la défense américaine (DoD) Initialement pour la modélisation Aujourd’hui: « modélisation » ET « synthèse » Seul un sous-ensemble du VHDL est synthétisable !!! Normes : VHDL-87, VHDL-93, VHDL 1076-2000, VHDL 1076-2006, VHDL 1076-2008 Page 2 ELE3311– Systèmes logiques programmables P. Levesque Avantages du HDL Augmentation de la productivité Réutilisation Indépendant de la technologie GAL, CPLD, FPGA, etc. Xilinx, Altera, Cypress, Actel, Lattice Semiconducteur, etc. Spartan3E, Virtex5, Kintex7, StratixV, CycloneV, etc. Gestion de la complexité Meilleur suivi des modifications grâce aux outils de gestion de fichiers Augmentation de la qualité des designs Page 3

Upload: others

Post on 24-Jul-2020

61 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

1

ELE3311– Systèmes logiques programmables

Philippe Levesque, Ph.D.

Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels de base du VHDL

Entity, Architecture, Package, Library, Component Type, Mode Signal, Variable Descriptions: Structurelle, Comportementale, Mixte

Exemples Points à retenir

ELE3311– Systèmes logiques programmablesP. Levesque

Introduction

VHDL – VHSIC Hardware Description Language VHSIC – Very High Speed Integrated Circuit

Origine: développé pour le Département de la défense américaine (DoD) Initialement pour la modélisation

Aujourd’hui: « modélisation » ET « synthèse »• Seul un sous-ensemble du VHDL est synthétisable !!!

Normes : VHDL-87, VHDL-93, VHDL 1076-2000, VHDL 1076-2006, VHDL 1076-2008

Page 2

ELE3311– Systèmes logiques programmablesP. Levesque

Avantages du HDL

Augmentation de la productivité Réutilisation

Indépendant de la technologie• GAL, CPLD, FPGA, etc.

• Xilinx, Altera, Cypress, Actel, Lattice Semiconducteur, etc.

• Spartan3E, Virtex5, Kintex7, StratixV, CycloneV, etc.

Gestion de la complexité Meilleur suivi des modifications grâce aux outils de

gestion de fichiers

Augmentation de la qualité des designs

Page 3

Page 2: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

2

ELE3311– Systèmes logiques programmablesP. Levesque

Flot de design

Page 4

ELE3311– Systèmes logiques programmablesP. Levesque

Caractéristiques du VHDL

Le VHDL est un langage de DESCRIPTION MATÉRIELLE qui permet:

De modéliser un environnement pour des fins de simulation

De synthétiser un circuit logique dans le but de programmer les interconnections d’un composant programmable afin d’utiliser ses ressources matérielles.

PENSEZ DIFFÉREMMENT !!!!

POUR CONCEVOIR AUTREMENT !!!!

Page 5

ELE3311– Systèmes logiques programmablesP. Levesque

Caractéristiques du VHDL

Logiciel: Algorithmes

• Exécution séquentielle (très instinctif car méthode usuelle!!!)

• Utilisation de ressources matérielles limités

CPU tout usage = référence à battre• RISC, CISC, DPS, etc.

Matériel: Algorithmes

• Exécution parallèle (plus difficile à imaginer car nouveau!!!)

• Architecture dédié

• Ressources matérielles illimitées (théoriquement!)

Coût, Dimension, Consommation, Performance

Page 6

Page 3: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

3

ELE3311– Systèmes logiques programmablesP. Levesque

Caractéristiques du VHDL

Page 7

Pas “case sensitive” : pas de différence entre les majuscules et les minuscules

Les identifications doivent débuter par une lettre (et non un chiffre)

Les instructions se terminent par : ;

Les commentaires sont précédés par : --

Les assignations pour les signaux utilisent le symbole : <=

Les assignations de variables et valeur par défaut utilisent le symbole : :=

La valeur d’un bus s’écrit entre guillemet : “…”

La valeur d’un bit s’écrit entre apostrophe : ‘…’

Les signaux possèdent une assignation de type « time value »

(ils possèdent une valeur en tout temps)

Les variables n’ont pas de signification physique dans un circuit.

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels de base du VHDL

Page 8

Design modulaire hiérarchique Entité : définit les interfaces externes (nom des ports d’entrées et de sorties)

Architecture: définit le comportement

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels de base du VHDL

Page 9

Structure recommandée d’une description en VHDL

Page 4: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

4

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels: Entity

Page 10

Entité (Entity) L’entité possède un nom qui lui est assigné lors de sa

déclaration

Définit tous les ports d’un module en spécifiant• Nom

• Mode : (in, out, buffer, inout)

• Type: (selon les libraries, bit, std_logig, std_ulogic, signes, unsigned, etc.)

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 11

Mode Défini le sens des ports de l’entité

4 modes possibles• in : défini une entrée

• out : défini une sortie– sa valeur ne peut pas être lue à l’intérieur de l’architecture;

• buffer : défini une sortie– sa valeur peut être lue à l’intérieur de l’architecture de l’entité (dans un

seul process). NON RECOMMANDÉ

• inout : défini un port comme une entrée et une sortie– ce mode doit être utilisé uniquement que pour les entrées et sorties à

trois états (tri-state) de l’entité top-level.

INFO:Xst:1739 - HDL ADVISOR - "C:/data/ecole/test_VHDL/new_lib/newlib/top_lev.vhd" line 43: declaration of a buffer port will make it difficult for you to validate this design by simulation. It is preferable to declare it as output.

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 12

Type Défini la nature des ports de l’entité

Plusieurs possibilités:• Bit : valeurs logiques 0 ou 1

• Std_logic, std_ulogic:– 9 états logiques

– U: non initialisé ou non défini (unitialized)

– X: inconnue (unknown)

– 0: niveau logique bas (inactif)

– 1: niveau logique haut (actif)

– Z: haute impedance (Hi-Z, high impedance)

– W: weak unknown

– L: weak logical 0, similaire à une pull-down logique

– H: weak logical 1, similaire è une pull-up logique

– -: don’t care

Regroupement avec _vector (bit_vector, std_logic_vector)

Page 5: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

5

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 13

Type (suite) Représentation des nombres

• Binaire: – ‘1’, ‘X’, “1100”, “100X00WLHZ”, etc.

• Hexadécimale: – X“FE”, X“10”, X“A”, etc.

• Octal: – O“70”, O“102”, O“6”, etc.

• Décimale: – 4, 16, 25, etc.

• Positif / Négatif : voir les libraries– Attention!! Restons près du matériel– Nombre négatif en complément à 2 pour le type signed

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 14

Type (suite) Le type permet également de définir des variables

• Boolean: Vrai ou Faux

• Integer : Valeur entière (utile comme valeur statique)– Entre -231 +1 et +231 +1

– Représentation en base 10 (habituellement)» Binaire: 2#....#

» Octal: 8#....#

» Hexa: 16#...#

• Real: Valeur point flottant

• Character : caractère ASCII

• Physical type: représentation de valeur physique – Temps: Utile pour les tests bench

» Fs, ps, ns, us, sec, min, hr

» Signal_A <= … after 2 ns; (attention à l’espace entre la valeur et l’unité)

– Longueur, Tension, etc.

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 15

Type (suite) Définir de nouveaux types

• enumeration: – définit un nouveau type en spécifiant la liste des valeurs possible

– Utile pour les MSA

» Type T_enum_name is (val1, val2, …);

» Type T_msa is (a, b, c, d);

» Signal etat_p, etat_s : T_msa;

• Tableau:

type nom_type is array (debut to fin) of type_element;type nom_type is array (fin downto debut) of type_element;

Page 6: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

6

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 16

Type (suite) Définir de nouveaux types

• Subtype:– Ajoute une contrainte à un type déjà défini

– Il est recommandé de toujours contrainte un integer

» Signal addr_s is integer range 0 to 255;

» Subtype ST_addr_val is integer range 0 to 255;

» Signal addr_s : ST_addr_val;

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 17

Syntaxe de déclaration d’une entité

entity nom_entity isgeneric (

nom_generic : type := valeur par défault;...

nom_generic : type := valeur par défault);

port (nom_signal, nom_signal : mode type_signal;nom_signal : mode type_signal;

...nom_signal : mode type_signal);

end nom_entity;

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Entity

Page 18

Exemple

entity nom_entity isgeneric (

gen_WIDTH : integer := 4; --utilisation facultative, valeur par défaut facultative) ; -- permet de définir une interface plus génériqueport (

clk : in bit;a_n : in std_logic;b : in std_logic_vector(gen_WIDTH-1 downto 0);c : buffer bit;d : out std_logic_vector(2 downto 0);e : inout std_logic --pas de ; pour le dernier port de l’interface); -- le ; se trouve après la fermeture de la parenthèse

end nom_entity;

Page 7: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

7

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 19

Architecture Est associé à une seule entité

Décrit le comportement ou la structure

Spécifie la relation entre les entrées et les sorties de l’entités

Top Level

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 20

La Syntaxe de description d’une architecture

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 21

Déclaration Section servant à déninir:

• Des types:type T_nom is (val1, val2);

type T_nom_tableau is array (0 to 255) of std_logic_vector (3 downto 0);

• Des constantes:constant NOM_CONST : std_logic :=1;

constant LUT_NOM_CONST : T_nom_tableau :=

(“1011”, “1111”, “0001”,…, “0101”);

• Des signaux:signal nom_signal : std_logic

Page 8: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

8

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 22

Déclaration Section servant à déninir:

• Des composants:component nom_component is

port

(

--Definition des ports…

);

end component;

• Des variables (non recommandé)

• Des fonctions

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 23

Description d’une architecture Une description en VHDL doit être considérée dans son ensemble

Il ne s’agit pas d’exécution, mais plutôt d’évaluation

Description structurelle• Description de la structure d’assemblage des différents composants

Description comportementale• Description du comportement

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 24

Description structurelle

nom_instance: nom_composantport map(

signal1, signal2,...,signaln);

nom_instance: nom_composantport map(

port1=>signal1,...,portn=>signaln);

Page 9: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

9

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 25

Description structurelle (exemple)

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 26

Description structurelle (exemple)library ieee;use ieee.std_logic_1164.all;

entity mux41 isport (A,B,C,D: in std_logic;

S : in std_logic_vector(1 downto 0);Y : out std_logic

);end mux41;

architecture struct of mux41 is-- signaux internessignal S1,S2: std_logic;-- declaration du ou des composantscomponent mux21 is

port (Entree1,Entree2, Sel: in std_logic;Sortie : out std_logic

);end component;

begin-- instantiationMux1: mux21 port map (Entree1 => A, Entree2 => B,

Sel => S(0), Sortie => S1);Mux2: mux21 port map (Entree1 => C, Entree2 => D,

Sel => S(0), Sortie => S2);Mux3: mux21 port map (Entree1 => S1, Entree2 => S2,

Sel => S(1), Sortie => Y);end struct;

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 27

Description comportementale

Page 10: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

10

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 28

Description conditionnelle du flux de données

Choix mutuellement exclusifs, mais qui ensemble, forment toutes les possibilités

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 29

Description cond. du flux de données (exemple)

library ieee;use ieee.std_logic_1164.all;

entity mux21 isport (Entree1,Entree2,Sel: in std_logic;

Sortie : out std_logic);

end mux21;

architecture dataflow of mux21 isbegin

Sortie <= (not Sel and Entree1) or (Sel and Entree2); end dataflow;

architecture dataflow of mux21 is-- signaux internessignal S1_s,S2_s,S3_s: std_logic;

beginS1_s <= not Sel;S2_s <= S1_s and Entree1;S3_s <= Sel and Entree2;Sortie <= S2_s or S3_s;

end dataflow;

architecture dataflow of mux21 is-- signaux internessignal Stemp1_s,Stemp2_s: std_logic;

beginStemp1_s <= '1' when Sel='0' and Entree1='1' else '0';Stemp2_s <= '1' when Sel='1' and Entree2='1' else '0';Sortie <= '1' when Stemp1_s='1' or Stemp2_s='1' else '0';

end dataflow;

architecture dataflow of mux21 is-- signaux internessignal entrees_s: std_logic_vector(2

downto 0);begin

entrees_s <= Sel & Entree1 & Entree2;

with entrees_s selectSortie <= '1' when "010"|"011",

'1' when "101"|"111",'0' when others;

end dataflow;

A B

D

C

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 30

Description par processus (process)

Entrées qui influencent directement les sorties

Évaluation séquentielle afin de trouver la nouvelle valeur des sorties en fonction des entrées

Page 11: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

11

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 31

Processus conditionnel

OPÉRATEURS LOGIQUES:

ANDORNANDNORXORNOT --(bit par bit)

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 32

Processus conditionnel (exemple)

nom_process : process (a,b) -- (liste de sensibilité)begin

z <= a and b;end process;

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 33

Processus IF

OPÉRATEURS RELATIONNELS:

= égal /= différent < plus petit <= plus petit ou égal > plus grand >= plus grand ou égal

Page 12: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

12

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 34

Processus IF (exemple)

nom_process : process (a,b) -- (liste de sensibilité)begin

if a=’1’ and b=’1’ thenz <= ‘1’;

elsez <= ‘0’;

end if;end process;

process (Entree1,Entree2,Sel)begin

if (Sel = '0') thenSortie <= Entree1;

elseSortie <= Entree2;

end if;end process;

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 35

Processus CASE

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 36

Processus CASE (exemple)

nom_process : process (a,b) -- (liste de sensibilité)begin

case a=’1’ iswhen ‘1’=>

z <= b;when other =>

z <= ‘0’;end case;

end process;

Page 13: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

13

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 37

Description de latch Élément de mémoire (sensible sur les niveaux)

Généralement indésirable

Résultent habituellement d’une description VHDL erronée

Occasionné par :• un signal manquant dans la liste de sensibilité d’un processus,

• un ELSE manquant dans un IF

• un WHEN OTHERS manquant dans un CASE

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 38

Description de registre Élément de mémoire (sensible sur les fronts)

Reset synchrone ou asynchrone…

QD

clk

rst

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 39

Description de registre (exemple) L’entrée D n’affecte pas directement les sorties

‘event = changement

Pas besoin de elseQ

D

clk

rst

process (rst,clk)begin

if (rst = ‘1') then --Utilisez un RST actif haut

Q <= '0';Q_n <= '1';

elsif (clk'event and clk = '1') then -- front montant d'horlogeQ <= D;Q_n <= not D;

end if;end process;

Page 14: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

14

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 40

Description de registre (exemple)

library ieee;

use ieee.std_logic_1164.all;entity shiftreg is

port (din,rst,clk : in std_logic;dout : out std_logic

);end shiftreg;

architecture behavioural of shiftreg is-- signaux internessignal q_r: std_logic_vector(7 downto 0);

Begin

dout <= q_r(7);

process (rst,clk)begin

if (rst = ‘1') thenq_r <= (others => '0'); -- met tous les bits de q a 0

elsif (clk'event and clk = '1') thenq_r <= q(6 downto 0) & din;

end if;end process;

end behavioural;

& : concaténation, opérateur de manipulation

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 41

Processus LOOP (boucle statique) Créent plusieurs copies de logique combinatoire lors de la

synthèse

Ne constituent pas une boucle d’exécution

Il est déconseillé de les utiliser pour une première initiation au VHDL

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 42

Processus LOOP (exemple)

dout <= q_r(7);

process (rst,clk)begin

if (rst = ‘1') thenq_r <= (others => '0'); -- met tous les bits de q a 0

elsif (clk'event and clk = '1') then

for i in 0 to 6 loop q_r(i+1) <= q(i);

end loop;

q_r(0) <= din; end if;

end process;end behavioural;

Page 15: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

15

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 43

Opérateurs arithmétiques, logiques et de manipulationOPÉRATEURS RELATIONNELS:

= égal /= différent < plus petit <= plus petit ou égal > plus grand >= plus grand ou égal

OPÉRATEURS LOGIQUES:

AND OR NAND NOR XOR NOT --(bit par bit)

OPÉRATEURS ARITHMÉTIQUES:

+ : addition - : soustraction * : multiplication / : division (ATTENTION!!!)

OPÉRATEUR DE MANIPULATION:

& : concaténation

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 44

Addition (exemple)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;

entity add_4bit isport (rst_n,clk : in std_logic;

din_a, din_b : in std_logic_vector(3 downto 0);dout : out std_logic_vector(4 downto 0)

);end add_4bit;

architecture behavioural of add_4bit is-- signaux internessignal dout_s,dout_r: std_logic_vector(4 downto 0);signal da_r, db_r: std_logic_vector(3 downto 0);

begindout <= dout_r;dout_s <= (‘0’&da_r) + (‘0’&db_r);

process (rst,clk)begin

if (rst = ‘1') thendout_r <= (others => '0'); -- met tous les bits a 0da_r <= (others => '0'); db_r <= (others => '0');

elsif (clk'event and clk = '1') thendout_r <= dout_s;da_r <= din_a;db_r <= din_b;

end if;end process;

end behavioural;

use ieee.numeric_std.all;

dout_s <= std_logic_vector(unsigned(‘0’&da_r) + unsigned(‘0’&db_r));

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 45

Multiplication (exemple)use ieee.numeric_std.all;library ieee;

use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;

entity mult_4x4bit isport (rst, clk : in std_logic;

din_a, din_b : in std_logic_vector(3 downto 0);dout : out std_logic_vector(7 downto 0)

);end mult_4x4bit;

architecture behavioural of mult_4x4bit is-- signaux internessignal dout_s, dout_r: std_logic_vector(7 downto 0);signal da_r, db_r: std_logic_vector(3 downto 0);

begindout <= dout_r;dout_r <= da_r * db_r;

process (rst,clk)begin

if (rst = ‘1') thendout_r <= (others => '0'); -- met tous les bits a 0da_r <= (others => '0'); db_r <= (others => '0');

elsif (clk'event and clk = '1') thendout_r <= dout_s;da_r <= din_a;db_r <= din_b;

end if;end process;

dout_r <= std_logic_vector(unsigned(da_r) * unsigned(db_r));

Page 16: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

16

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 46

Latence et DébitLatence = 2Débit = 1

Latence : Nombre de cycle d’horloge qui s'écoule entre le moment où commence à s'appliquer un stimulus et le moment où s'apparaît la réponse.

Débit : Quantité de données produites par cycle d’horloge.

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 47

Architecture Pipeline

Architecture Pipeline : Permet d’effectuer simultanément plusieurs opérations pendant le même cycle d’horloge.

• Avantages : Réduit les délais de propagations : permet d’augmenter la fréquence de l’horloge, ce qui améliore le taux de production des données (débit/s).

• Inconvénient : Augmente la latence en fonction du nombre d’étages.

Recommandation : Une seule opération à la fois !!! (entre deux étages de registres)

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Architecture

Page 48

Compteur modulo 10 (exemple)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;

entity cmpt isport (rst, clk : in std_logic;

compteur : out std_logic_vector(3 downto 0));

end cmpt;

architecture behavioural of cmpt is-- signaux internessignal cmpt_r: std_logic_vector(7 downto 0);

begincompteur <= cmpt_r;process (rst, clk)begin

if (rst = ‘1') thencmpt_r <= (others => '0'); -- met tous les bits a 0

elsif (clk'event and clk = '1') thenif cmpt_r = “1001” then -- si rendu a 9

cmpt_r <= “0000”; -- retourne à 0else

cmpt_r <= cmpt_r + 1;end if;

end if;end process;

end behavioural;

Page 17: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

17

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Librarie et Package

Page 49

Librarie et paquetage (package) Librairie work créée et utilisée par le compilateur pour

tout design VHDL• library work; (pas nécessaire)

• use work.nom_package.all;

Les librairies communes sont aussi souvent utiles• Ex: IEEE

• library ieee;

• use ieee.std_logic_1164.all;

• use ieee.std_logic_arith.all; ou use ieee.numeric_std.all;

• use ieee.std_logic_unsigned.all;

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Librarie et Package

Page 50

Std_logic_1164 Types std_ulogic, std_logic, std_ulogic_vector, std_logic_vector;

Fonctions: to_bit, to_stdulogic, to_stdlogicvector, rising_edge, falling_edge, is_x

Std_logic_arith Type unsigned et signed; signal test : signed(7 downto 0);

Fonctions arithmetiques : +, -, *;

Fonctions relationnelles : <, <=, >, >=, =, /=;

Fonctions de décalages : shl et shr;

Fonctions : conv_integer, conv_signed, conv_std_logic_vector

N’est pas recommandé pour les nouveau design (utiliser numeric_std)

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Librarie et Package

Page 51

Numeric_std Standard IEEE

Type unsigned et signed;

Fonctions arithmetiques : +, -, *, /;

Fonctions relationnelles : <, <=, >, >=, =, /=;

Fonctions de décalages : shl, shr, …;

Fonctions :to_integer, to_signed, to_unsigned,

conv_integer, conv_signed, conv_unsigned

Fonctions de cast (similaire au C/C++) :integer, signed, unsigned, std_logic_vector

Page 18: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

18

ELE3311– Systèmes logiques programmablesP. Levesque

Éléments structurels : Librarie et Package

Page 52

Std_logic_unsigned Étend la librairie std_logic_arith pour l’utilisation des

std_logic_vector en tant qu’entier non signé

Pratique puisque numeric_std ne défini pas les fonctions ALU sur les std_logic_vector

Std_logic_signed Il n’est pas recommandé d’utiliser cette librarie

Étend la librairie std_logic_arith pour l’utilisation des std_logic_vector en tant qu’entier signé (complément à 2)

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 53

Il est recommandé de toujours registrer les sorties Fmax optimal

Synchronisation des sorties

La machine de Moore est préférable:• Description VHDL = diagramme d’état

• En simulation:– Il est facile de faire correspondre les sorties présentes avec l’état

présent

– Il est facile de suivre le déroulement de la MSA

– Il est facile de retracer la provenance des sorties présentes

• Il est donc facile de trouver les erreurs

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 54

Page 19: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

19

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 55

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 56

Machine de Mealy0

0

b

X

0

c

0

d

X

a

X

X

Z=1

1

1

1

1

library ieee;use ieee.std_logic_1164.all;

entity msa isport (X,rst_n,clk : in std_logic;

Z : out std_logic);

end msa;

architecture behavioural of msa is-- definition d'un typetype etat_T is (a,b,c,d);-- signaux internessignal etat_p, etat_f: etat_T;

beginsynchrone : process (rst_n, clk)begin

if (rst_n = '0') thenetat_p <= a;

elsif (clk'event and clk = '1') thenetat_p <= etat_s;

end if;end process;

...

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 57

Machine de Mealy0

0

b

X

0

c

0

d

X

a

X

X

Z=1

1

1

1

1

asynchrone : process (etat_p, X)begin

case etat_courant iswhen a => if (X = '1') then

etat_f <= b;else

etat_f <= a;end if;Z <= '0';

when b => if (X = '1') thenetat_f <= c;

elseetat_f <= b;

end if;Z <= '0';

when c => if (X = '1') thenetat_f <= d;

elseetat_f <= c;

end if;Z <= '0';

when others => if (X = '1') then --when detat_f <= a;Z <= '1';

elseetat_f <= d;Z <= '0';

end if;end case;

end process;end behavioural;

Page 20: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

20

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 58

Machine de Moorelibrary ieee;use ieee.std_logic_1164.all;

entity msa isport (x,rst_n,clk : in std_logic;

Z : out std_logic);

end msa;

architecture behavioural of msa is-- definition d'un typetype etat_T is (a,b,c);-- signaux internessignal etat_p, etat_f: etat_T;signal sortie_p, sortie_f: std_logic;

begin-- assignation des sortiesz <= sortie_p;synchrone : process (rst_n, clk)begin

if (rst_n = '0') then --initialisationetat_p <= a;sortie_p <= ‘0’

elsif (clk'event and clk = '1') thenetat_p <= etat_p;sortie_p <= sortie_f;

end if;end process;

...

ELE3311– Systèmes logiques programmablesP. Levesque

Description des MSA

Page 59

Machine de Moore

asynchrone : process (etat_p, x)begin

case etat_p iswhen a => if (x = '1') then

etat_f <= b;sortie_f <= ‘1’;

elseetat_f <= a;sortie_f <= ‘0’;

end if;

when b => if (x = '1') thenetat_f <= c;

elseetat_f <= a;

end if;sortie_f <= '0';

when others => if (x = '1') then –when cetat_f <= c;

elseetat_f <= a;

end if;sortie_f <= '0';

end case;end process;

end behavioural;

ELE3311– Systèmes logiques programmablesP. Levesque

Partage de ressource

Page 60

synchrone : process (rst=,clk)begin

if rst= =‘1’ thendin_a_reg <= (others=>’0’);din_b_reg <= (others=>’0’);dout_reg <= (others=>’0’);

elsif clk’event and clk=‘1’ thendin_a_reg <= din_a;din_b_reg <= din_b;dout_reg <= dout_next;

end if;end process;

end behavioural;

4

4

8

Dout2

3

0

1 8

Q

QSET

CLR

D

8

clk

Sel

Q

QSET

CLR

D

Q

QSET

CLR

D

4

4

4

8

clk

clk

Din_a4

Din_b

4

4

8

4

4

8

Page 21: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

21

ELE3311– Systèmes logiques programmablesP. Levesque

Partage de ressource

Page 61

asynchrone : process (din_a_reg,din_b_reg,sel)begin

case sel iswhen “00” =>

dout_next <= din_a_reg * din_a_reg;when “01” =>

dout_next <= din_a_reg * din_b_reg;when “10” =>

dout_next <= din_b_reg * din_a_reg;when others => --“11” =>

dout_next <= din_b_reg * din_b_reg;end case;

end process;end behavioural;

Il y a 4 multiplicateurs

L’outil de synthèse n’optimisera pas nécessairement

ELE3311– Systèmes logiques programmablesP. Levesque

Partage de ressource

Page 62

sel <= sel_a & sel_b;dout_next <= din_1 * din_2;

asynchrone : process (din_a_reg,din_b_reg,sel)begin

case sel iswhen “00” =>

din_1 <= din_a_reg;din_2 <= din_a_reg;

when “01” =>din_1 <= din_a_reg;din_2 <= din_b_reg;

when “10” =>din_1 <= din_a_reg;din_2 <= din_b_reg;

when others => --“11” =>din_1 <= din_b_reg;din_2 <= din_b_reg;

end case;end process;

end behavioural;

Il y a 1 multiplicateur

L’outil de synthèse optimisera si nécessaire(Optimisation : vitesse vs ressource)

ELE3311– Systèmes logiques programmablesP. Levesque

Chemin de contrôles et chemin de données

Page 63

Contrôle: Objectif : Placer les bonnes données aux bons endroits aux bons moments

Réalisation efficace et simple : MSA

Données: Objectif: Effectuer les bonnes opérations (ALU)

Réalisation efficace :

• Architecture pipeline (architecture recommandée)

plus de matériel;

moins de contrôle;

meilleur débit.

• Architecture itérative

moins de matériel;

plus de contrôle;

réutilisation du matériel.

Page 22: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

22

ELE3311– Systèmes logiques programmablesP. Levesque

Chemin de contrôles et chemin de données

Page 64

Exemple: Cœur de traitement d’un échographe miniature

Synchronisation

Compression de pixels

&Calibration des tons de

gris

Unité deconversionde balayage

Unité deprétraitementdes données

Traitement de position

Traitement des lignes

Traitementcoordonnées

polaires&

cartésiennes

Démodulationen quadrature

Générateur d’impulsions

Synchronisation des unités de

traitement

Cœurde traitement

Implusion

État du système

Paramètres de configuration

Calibrationde

l’intensité

Amplificateurnumérique

Réjectiondu bruit

PositionDonnées

ultrasoniques

FIFO

&

Pixel(Intensité et Position)

ELE3311– Systèmes logiques programmablesP. Levesque

Chemin de contrôles et chemin de données

Page 65

Exemple: Cœur de traitement d’un échographe miniature

 

0f 0 2

BWf 0 2

BWf

0f 0 2

BWf 0 2

BWf

tPMS t

rPMS t

0rPMS nT

0PMQ nT 0PMI nT

20PMI nT

20PMQ nT

0addrPMS nT

0PMA nT

1tan

0rPMS nT

0PW nT

ELE3311– Systèmes logiques programmablesP. Levesque

IF vs CASE

Page 66

Évitez: If, elsif, elsif, elsif, elsif, else Dans ce cas: UTILISEZ un CASE

IF : toutes les conditions doivent être exclusives et former un tout.

CASE: il est plus évident que toutes les conditions sont exclusives et forment un tout

Page 23: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

23

ELE3311– Systèmes logiques programmablesP. Levesque

Fonctions pratiques

Page 67

Std_logic_unsigned

conv_integer : std_logic_vector to integerint_val <= conv_integer(signal_vect);

Attention à la représentation des nombre…

TOUJOURS non signé

Std_logic_arith conv_std_logic_vector : integer to std_logic_vector

signal_vect <= conv_std_logic_vector(int_val,8); --8=nb bits

(fct conv_integer : signed ou unsigned to integer)

Pas recommandé

ELE3311– Systèmes logiques programmablesP. Levesque

Fonctions pratiques

Page 68

Numeric_std

to_integer : signed ou unsigned to integersig_int_val <= to_integer(signal_signed);

usig_int_val <= to_integer(signal_unsigned);

sig_int_val <= to_integer(signed(signal_vect));

usig_int_val <= to_integer(unsigned(signal_vect));

conv_integer : integer to signed ou unsignedsignal_signed <= to_signed(sig_int_val,8));

unsignal_signed <= to_unsigned(usig_int_val,8);

signal_signed <= to_signed(signed(signal_vect),8);

unsignal_signed <= to_unsigned(unsigned(signal_vect),8);

Signal_vect <= std_logic_vector(…);

Attention à la représentations des nombres….utilisation de « cast »

ELE3311– Systèmes logiques programmablesP. Levesque

ROM (ex1)

Page 69

process (clk)begin

if (clk’event and clk = ’1’) thenif (en = ’1’) then

data <= ROM(conv_integer(addr));end if;

end if;end process;

type rom_type is array (63 downto 0) of std_logic_vector (19 downto 0);

signal ROM : rom_type:= (X"0200A", X"00300", X"08101", X"04000", X"08601", X"0233A",X"00300", X"08602", X"02310", X"0203B", X"08300", X"04002",X"08201", X"00500", X"04001", X"02500", X"00340", X"00241", X"04002", X"08300", X"08201", X"00500", X"08101", X"00602", X"04003", X"0241E", X"00301", X"00102", X"02122", X"02021", X"00301", X"00102", X"02222", X"04001", X"00342", X"0232B", X"00900", X"00302", X"00102", X"04002", X"00900", X"08201", X"02023", X"00303", X"02433", X"00301", X"04004", X"00301", X"00102", X"02137", X"02036", X"00301", X"00102", X"02237", X"04004", X"00304",X"04040", X"02500", X"02500", X"02500", X"0030D", X"02341", X"08201", X"0400D");

Page 24: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

24

ELE3311– Systèmes logiques programmablesP. Levesque

ROM (ex2)

Page 70

rdata <= ROM(conv_integer(addr));process (clk)

beginif (clk’event and clk = ’1’) then

if (en = ’1’) thendata <= rdata;

end if;end if;

end process;

type rom_type is array (63 downto 0) of std_logic_vector (19 downto 0);signal ROM : rom_type:= (X"0200A", X"00300", X"08101", X"04000", X"08601", X"0233A",X"00300", X"08602", X"02310", X"0203B", X"08300", X"04002",X"08201", X"00500", X"04001", X"02500", X"00340", X"00241", X"04002", X"08300", X"08201", X"00500", X"08101", X"00602", X"04003", X"0241E", X"00301", X"00102", X"02122", X"02021", X"00301", X"00102", X"02222", X"04001", X"00342", X"0232B", X"00900", X"00302", X"00102", X"04002", X"00900", X"08201", X"02023", X"00303", X"02433", X"00301", X"04004", X"00301", X"00102", X"02137", X"02036", X"00301", X"00102", X"02237", X"04004", X"00304",X"04040", X"02500", X"02500", X"02500", X"0030D", X"02341", X"08201", X"0400D");signal rdata : std_logic_vector(19 downto 0);

ELE3311– Systèmes logiques programmablesP. Levesque

RAM à 1 port, read first

Page 71

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM: ram_type;

process (clk)begin

if clk’event and clk = ’1’ thenif en = ’1’ then

if we = ’1’ thenRAM(conv_integer(addr)) <= di;

end if;do <= RAM(conv_integer(addr)) ;

end if;end if;

end process;

ELE3311– Systèmes logiques programmablesP. Levesque

RAM 1 port, write first (ex1)

Page 72

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM: ram_type;

process (clk)begin

if clk’event and clk = ’1’ thenif en = ’1’ then

if we = ’1’ thenRAM(conv_integer(addr)) <= di;do <= di;

elsedo <= RAM( conv_integer(addr));

end if;end if;

end if;end process;

Page 25: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

25

ELE3311– Systèmes logiques programmablesP. Levesque

RAM 1 port, write first (ex2)

Page 73

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM: ram_type;signal read_addr: std_logic_vector(5 downto 0);

process (clk)begin

if clk’event and clk = ’1’ thenif en = ’1’ then

if we = ’1’ thenRAM(conv_integer(addr)) <= di;

end if;read_addr <= addr;

end if;end if;

end process;

do <= ram(conv_integer(read_addr));

ELE3311– Systèmes logiques programmablesP. Levesque

RAM 1 port, no change

Page 74

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM: ram_type;

process (clk)begin

if clk’event and clk = ’1’ thenif en = ’1’ then

if we = ’1’ thenRAM(conv_integer(addr)) <= di;

elsedo <= RAM( conv_integer(addr));

end if;end if;

end if;end process;

ELE3311– Systèmes logiques programmablesP. Levesque

RAM 1 port, lecture asynchrone

Page 75

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM: ram_type;

process (clk)begin

if (clk’event and clk = ’1’) thenif (we = ’1’) then

RAM(conv_integer(a)) <= di;end if;

end if;end process;

do <= RAM(conv_integer(a));

Page 26: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

26

ELE3311– Systèmes logiques programmablesP. Levesque

RAM 1 port, lecture synchrone (=write first)

Page 76

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM : ram_type;signal read_a : std_logic_vector(5 downto 0);

process (clk)begin

if (clk’event and clk = ’1’) thenif (we = ’1’) then

RAM(conv_integer(a)) <= di;end if;read_a <= a;

end if;end process;

do <= RAM(conv_integer(read_a));

Méthode recommandée

ELE3311– Systèmes logiques programmablesP. Levesque

RAM 1 port, avec enable

Page 77

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM : ram_type;signal read_a : std_logic_vector(5 downto 0);

process (clk)begin

if (clk’event and clk = ’1’) thenif (en = ’1’) then

if (we = ’1’) thenRAM(conv_integer(a)) <= di;

end if;read_a <= a;

end if;end if;

end process;

do <= RAM(conv_integer(read_a)); Méthode recommandée

ELE3311– Systèmes logiques programmablesP. Levesque

Mémoire double ports, lecture asynchrone

Page 78

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM : ram_type;

process (clk)begin

if (clk’event and clk = ’1’) thenif (we = ’1’) then

RAM(conv_integer(a)) <= di;end if;

end if;end process;

spo <= RAM(conv_integer(a));dpo <= RAM(conv_integer(dpra));

Page 27: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

27

ELE3311– Systèmes logiques programmablesP. Levesque

Mémoire double ports, lecture synchrone

Page 79

Méthode recommandée

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM : ram_type;signal read_a : std_logic_vector(5 downto 0);signal read_dpra : std_logic_vector(5 downto 0);

process (clk)begin

if (clk’event and clk = ’1’) thenif (we = ’1’) then

RAM(conv_integer(a)) <= di;end if;read_a <= a;read_dpra <= dpra;

end if;end process;

spo <= RAM(conv_integer(read_a));dpo <= RAM(conv_integer(read_dpra));

ELE3311– Systèmes logiques programmablesP. Levesque

Mémoire double ports, 2 horloges

Page 80

Méthode recommandée

type ram_type is array (63 downto 0) of std_logic_vector (15 downto 0);signal RAM : ram_type;signal read_add1 : std_logic_vector(5 downto 0);signal read_add2 : std_logic_vector(5 downto 0);

process (clk)begin

if (clk1’event and clk1 = ’1’) thenif (we = ’1’) then

RAM(conv_integer(add1)) <= di;end if;read_add1 <= add1;

end if;end process;

do1 <= RAM(conv_integer(read_add1));

process (clk2)begin

if (clk2’event and clk2 = ’1’) thenread_add2 <= add2;

end if;end process;

do2 <= RAM(conv_integer(read_add2));

ELE3311– Systèmes logiques programmablesP. Levesque

Mémoire double ports, lecture et écriture

Page 81

type ram_type is array (63 downto 0) of std_logic_vector(15 downto 0);shared variable RAM : ram_type;

process (CLKA)begin

if CLKA’event and CLKA = ’1’ thenif ENA = ’1’ then

if WEA = ’1’ thenRAM(conv_integer(ADDRA)) := DIA;

end if;DOA <= RAM(conv_integer(ADDRA));

end if;end if;

end process;

Si pas de shared variable:ERROR:Xst:3051 - You have modeled RAM <RAM> with two separate write ports using a signal. This model will not behave correctly in simulation tools. Please use instead a shared variable. Coding guidelines are provided in the XST User Guide.

Page 28: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

28

ELE3311– Systèmes logiques programmablesP. Levesque

Mémoire double ports, lecture et écriture

Page 82

Méthode recommandée

process (CLKB)begin

if CLKB’event and CLKB = ’1’ thenif ENB = ’1’ then

if WEB = ’1’ thenRAM(conv_integer(ADDRB)) := DIB;

end if;DOB <= RAM(conv_integer(ADDRB));

end if;end if;

end process;

ELE3311– Systèmes logiques programmablesP. Levesque

Configuration de la synthèse (auto habituellement OK)

Page 83

Autres possibilitésVoir: XST User Guide (xst.pdf)

help -> software manual -> xst user guide for …

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 84

Page 29: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

29

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 85

entity_et.vhd

library ieee;use ieee.std_logic_1164.all;

entity entity_et isport

(a : in std_logic;b : in std_logic;c : out std_logic;);

end entity_et;

architecture arch_et of entity_et isbegin

c<= a and b;end arch_et;

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 86

entity_mux.vhdlibrary ieee;use ieee.std_logic_1164.all;

entity entity_mux isport

(a : in std_logic;b : in std_logic;c : in std_logic;d : out std_logic;);

end entity_mux;

architecture arch_mux of entity_mux isbegin

process (a,b,c) – ATTENTION au latchbegin

case c iswhen ‘0’ =>

d <= a;when others => -- ATTENTION au latch

d<= b;end case;

end process;end arch_mux;

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 87

package_ex.vhd

library ieee;use ieee.std_logic_1164.all;

package package_ex is--possibilité d’ajouter d’autre type de déclaration

component entity_et isport

(a : in std_logic;b : in std_logic;c : out std_logic;);

end component;

component entity_mux isport

(a : in std_logic;b : in std_logic;c : in std_logic;d : out std_logic;);

end component;

end package_ex;

Page 30: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

30

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 88

entity_ex.vhdlibrary ieee;use ieee.std_logic_1164.all;use work.package_ex.all; -- utilisation d’un package pour définir les components

entity entity_ex isport

(data_a : in std_logic_vector(1 downto 0);data_b : in std_logic_vector(1 downto 0);sel : in std_logic;r_w : in std_logic;data_in : in std_logic;rst : in std_logic;clk : in std_logic;led : out std_logic;data_out : out std_logic;data_bus : inout std_logic;);

end entity_ex;architecture arch_ex of entity_ex is--possibilite de definer components ici au lieu d’utiliser un packagesignal data_s : std_logic_vector(1 downto 0);signal data_r : std_logic_vector(1 downto 0);signal signal1_s : std_logic;signal signal2_s : std_logic;

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 89

entity_ex.vhd (suite)begin

data_bus <= data_in when r_w = ‘0’ else (others=>’z’); -- controle bus tri-statedata_s <= data_bus;data_out <= data_r;

process (clk,rst)begin

if rst=’1’ thendata_r<=(others=>’0’);

elsif clk’event and clk=’1’ thendata_r <= data_s;

end if;end process;

et1: entity_et -- utilisation du component entity_etport map

(a => data_a(1), -- attention ici c’est une virgule (,) et non (;)b => data_a(0),c => signal1_s -- pas de virgule);

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 90

entity_ex.vhd (suite)

et2: entity_etport map

(a => data_b(1), -- attention ici c’est une virgule (,) et non (;)b => data_b(0),c => signal2_s -- pas de virgule);

mux1: entity_muxport map

(a => signal1_s, -- attention ici c’est une virgule (,) et non (;)b => signal2_s,c => sel,d => led -- pas de virgule);

end arch_ex;

Page 31: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

31

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 91

package_tb.vhd

library ieee;use ieee.std_logic_1164.all;

package package_tb is

type tableau1_T is array (0 to 15) of std_logic_vector(1 downto 0); type tableau2_T is array (0 to 15) of std_logic;

constant LUT_table_1 : tableau2_T := ('0', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '0', '1', '0', '1');

constant LUT_table_2 : tableau1_T := (''00'', '01'', '10'', '11'', '00'', '11'', '10'', '01'', '00'', '10'', '01'', '10'', '01'', '00'', '11'', '00'');

constant LUT_table_3 : tableau1_T := (''11'', '01'', '10'', '00'', '10'', '11'', '01'', '00'', '10'', '11'', '01'', '00'', '00'', '00'', '11'', '00'');

end package_tb;

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 92

test_bench.vhdlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use work.package_tb.all;

entity entity_ex_tb isend entity_ex_tb;

ARCHITECTURE behavior OF entity_ex_tb IS-- DEFINITION DU MODULE A TESTERcomponent entity_export (data_a : in std_logic_vector(1 downto 0);

data_b : in std_logic_vector(1 downto 0);sel : in std_logic;

r_w : in std_logic;data_in : in std_logic;rst_n : in std_logic;clk : in std_logic;led : out std_logic;

data_out : out std_logic;data_bus : inout std_logic;

);end component;-- AJOUT POSSIBLE DE MODULES POUR FIN DE TEST-- CODE ICI

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 93

test_bench.vhd (suite)-- DECLARATION DES SIGNAUX INTERNES-- SIGNAUX DU MODULE A TESTER

--Inputssignal clk_tb : std_logic :='0'; -- valeur initiale a utiliser que pour les test-benchssignal rst_tb,sel, r_w : std_logic :='0';signal data_a_tb, data_b_tb : std_logic_vector(1 downto 0) := ''00'';

--Outputssignal led_tb, data_out_tb : std_logic;

--InOutsignal data_bus_tb : stb_logic := 'Z';

-- SIGNAUX ADDITIONNELSsignal cmpt_tb : std_logic_vector (3 downto 0);

-- DEFINITION DE CONSTANTES-- Définition de la période de l’horlogeconstant clk_1mhz_period : time := 1 us;--Attention, il doit y avoir un espace entre la valeur (1) et l’unité (us)

Page 32: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

32

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 94

test_bench.vhd (suite)Begin

entity_ex_instance : entity_export map (

data_a => data_a_tb,data_b => data_b_tb,sel => sel_tb,r_w => r_w_tb,data_in => data_in_tb,rst => rst_tb,clk => clk_tb,led => led_tb,data_out => data_out_tb,data_bus => data_bus_tb,);

-- Génération du signal RESETrst_tb <= '0' , '1' after 5 us;--Attention, il doit y avoir un espace entre la valeur (5) et l’unité (us)

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 95

test_bench.vhd (suite)

-- Génération de l’horlogeclk_1mhz_process :process -- pas de liste de sensibilite avec les "wait"begin

clk_tb <= '0';wait for clk_1mhz_period/2;clk_tb <= '1';wait for clk_1mhz_period/2;

end process;

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 96

test_bench.vhd (suite)-- Génération des stimulisstim_proc: processbegin

sel<='0';r_w<='0';data_bus<='Z';wait for 5 us;sel<='0';r_w<='1';data_bus<='1';wait for clk_1mhz_period*6;sel<='1';r_w<='0';data_bus<='Z';wait for clk_1mhz_period*6000;sel<='1';r_w<='1';data_bus<='0';wait for 122 us;-- insert stimulus herewait; -- a utiliser si on ne desire pas boucler

end process;

--Utilisation de tablesdata_in <= LUT_table_1(conv_integer(cmpt_tb));data_a <= LUT_table_2(conv_integer(cmpt_tb));data_b <= LUT_table_3(conv_integer(cmpt_tb));

Page 33: Chapitre 5: langage VHDL · Chapitre 5: langage VHDL Introduction Avantages des langages de description de matériel Flot de design Caractéristiques du VHDL Éléments structurels

33

ELE3311– Systèmes logiques programmablesP. Levesque

Exemple synthèse

Page 97

test_bench.vhd (suite)

compteur_p : process(rst_n_tb, clk_tb)begin

if rst_tb =‘1' thencmpt_tb <= (others => '0');

elsif clk_tb'event and clk_tb= '1' thencmpt_tb <= cmpt_tb + 1;

end if;end process;

-- AJOUT DE TOUT AUTRE CODE POSSIBLE!!!end;

ELE3311– Systèmes logiques programmablesP. Levesque

Points à retenir (suite)

Page 98

Utilisation du ELSE dans une instruction IF (pas de latchs)

Utilisation du OTHERS dans une instruction CASE (pas de latchs)

Utilisation de l’instruction CASE plutôt qu’une suite IF-ELSIF-ELSIF-ELSE lorsque les conditions sont mutuellement exclusives

Affecter une valeur à un signal de sortie à un seul endroit

En général, on met tout en minuscules sauf les constantes;

Pour les signaux en logique négative : utiliser _n à la fin du nom;

Pour les signaux registrés : utiliser _r à la fin du nom (après le _n dans le cas d’un signal en logique négative);

ELE3311– Systèmes logiques programmablesP. Levesque

Points à retenir (suite)

Page 99

Pour les signaux non registrés : utiliser _s à la fin du nom;

Pour les signaux des tests bench : utiliser _tb à la fin du nom;

LUT : ajouter LUT_ (en majuscule) au début du nom de la LUT;

CONSTANTE : Mettre le nom en majuscule

Définition d’un type : ajouter TYPE_ ou T_ (en majuscule) au début du nom du type;

ATTENTION!!! Il n’est pas conseillé d’utiliser des variables;

ATTENTION!!! Il n’est pas conseillé d’utiliser le mode buffer;

Pensez selon une approche matérielle !!!!

Concevez avant de coder !!!!