Présentation VHDL
Présentation VHDL
Boumediene USTHB
INTRODUCTION AU LANGAGE DE
PROGRAMMATION VHDL
Objectif de ce cours
Dans ce chapitre, nous aborderons:
Simulate
Synthesize
Map
Place
Route
Download
Grandes étapes
Exigences
Synthesize
Gate-level
Model Simulate Test Bench
Timing
Model Simulate
Le « Y » de Gadjsky
Comportemental Structural
Algorithmes
Processeurs
Register transfer
Registres
Expressions Booléennes
Portes
Fonctions de transfert
Transistors
Structural Functional
haut niveau
d'abstraction
faible niveau
d'abstraction
Structural Functional
Algorithme (comportemental)
Register-Transfer
Language
Boolean Equation
Differential Equation
Structural Functional
Processor-Memory
Switch
Register-Transfer
Gate
Transistor
Structural Functional
Polygons
Sticks
Standard Cells
Plan d'étage
• Interfaces
• Modeling (Behavior, Dataflow, Structure)
• Test Benches
• Analysis, elaboration, simulation
• Synthesis
Flux de conception conventionnel
Funct. Spec
L'extrémité avant
Gate-level Net. Gate-Lev. Sim.
Back-end Floorplanning
Parasitic Extrac.
Place & Route
Layout
Vérification à différents niveaux d'abstraction
System Simulators
Behavioral
HDL HDL Simulators
Couverture de code
RTL
Gate-level Simulators
Verification
Analyse temporelle
Gate-level statique
Layout vs
Physical Schematic (LVS)
Domain
Classification des simulateurs
Logic Simulators
22
Classification des simulateurs
• HDL-based: Conception et banc de test décrits avec HDL
• Event-driven
• Cycle-based
Example: my_ckt
Inputs: A, B, C
Outputs: X, Y
VHDL description:
A entity my_ckt is
X
port (
B my_ckt
Y A: in bit;
S B: in bit;
S: in bit;
X: out bit;
Y: out bit);
end my_ckt ;
VHDL entity
Datatypes:
• entity my_ckt is In-built
Name of the circuit
User-defined
port ( User-defined
Filename same as circuit
A: in bit; Aname
Name of the circuit
B: in bit; Example.
User-defined X
B NomCircuit name:
de fichier
my_ckt my_ckt au
identique
S: in bit; Filename:
nom my_ckt.vhd
du circuit recommandé Y
X: out bit; S Example:
Direction of port
Circuit name: my_ckt
Y: out bit 3 main types:
Nom de fichier: my_ckt.vhd
in: Input
); out: Output
Noms de ports ou
inout: Bidirectional
noms deend my_ckt; Notez l'absence de point-virgule
signaux “;” à la
fin du dernier signal et la présence à la
fin du crochet de fermeture
VHDL: Concepts de base
• Structure générale
Votre fichier texte de description: xxx.vhd
27
VHDL: Concepts de base
• Méthodologie de conception
• Guide pratique du débutant
• COMBINATOIRE: Instructions dites concurrentes
• SEQUENTIELLE: Utilisation d’un PROCESS
Logique combinatoire
La sortie ne dépend pas de l’état passé Logique séquentielle
La sortie dépend de son état passé
Un vecteur d’entrée = un vecteur de sortie Système nécessitant une horloge (systèmes
unique dits synchrones)
Des exemples: Des exemples:
•Multiplexeurs •Compteurs
•Additionneurs •Registres à décalage
•Décodeur 7 segements •Machine d’état (automate)
•Encodeurs de priorité
Les Opérateurs.
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.
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 0 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 ….
Les Opérateurs.
Opérateur de concaténation : &.
Opérateur VHDL
ADDITION +
SOUSTRACTION -
MULTIPLICATION *
DIVISION /
Les Opérateurs.
Opérateurs relationnels.
Opérateur VHDL
Egal =
Non égal /=
Inférieur <
Inférieur ou égal <=
Supérieur >
Supérieur ou égal >=
VHDL: Concepts de base
• Les questions à se poser
• On identifie les fonctions et on les dessine sur papier
• On repère et nomme les entrées de chaque blocs ( on évite d’utiliser les mêmes noms)
• On répertorie les signaux INTERNES (mot clé SIGNAL)
• Le bloc est-il combinatoire ou séquentiel?
• Si séquentiel alors description avec le mot clé PROCESS + instructions autorisées
• Le bloc est-il utilisé plusieurs fois
• Si oui il vaut mieux créer un composant (entity+ architecture)
• Sinon le bloc est synthétiser par les lignes de codes directement
• Les opérateurs
• Logiques (boolean, bit, std_ulogic) Un bus (ou ensemble de fils électrique) est
• AND, OR, NAND, NOR, XOR, NOT représenté sous forme d’un vecteur de bits
• Relationnels ( retournent un boolean)
• = /= < <= > >=
• Arithmétiques
• + - * / ** MOD REM
• Concaténations d’éléments de tableaux &
• "bon" & "jour" => "bonjour" STD_LOGIC_VECTOR (3 DOWNTO 0);
Logique combinatoire: Instructions concurrentes
Assignation simples library IEEE;
Exemple 2
use IEEE.std_logic_1164.all;
library IEEE; Exemple 1
entity example is
use IEEE.std_logic_1164.all; port(
--librairie pour inclure type std_logic E:IN std_logic_vector(2 downto 0);
--portes ET S1:OUT std_logic; --1 fil
--3 entrées E2 E1 E0 S2,S3:OUT std_logic_vector(3 downto 1);--3 fils S1[3:1]
-- 1 sortie S0 S4:OUT std_logic_vector(2 downto 0)
entity ET3 is Bit Poid Fort Bit Poid faible );
port( end example;
E:IN std_logic_vector(2 downto 0);
--definition de l'architecture
S:OUT std_logic architecture arch_example of example is
); begin
end ET3; S1<='0';
S2<='1‘ & E(1 downto 0);
--definition de l'architecture -- operateur COLLER (ou CONCATENE) &
architecture arch_ET3 of ET3 is -- S2(3) S2(2) S2(1)
begin -- '1' E(1) E(0)
S3<="101";
S<=E(2) and E(1) and E(0); -- E(2) accès au fil 2
S4<= "111" XOR E; --manip sur les bus directement
end arch_ET3; end arch_example;
Logique combinatoire: Instructions concurrentes
• Assignation conditionnelle : Structure WHEN / ELSE
signal <= signal1 when expresion_boolénne else
---- Solution 1: with WHEN/ELSE ------------- ………
2 LIBRARY ieee; signal1xx when expresion_boolénne else
3 USE ieee.std_logic_1164.all; signal par défaut;
4 ---------------------------------------------
5 ENTITY encoder IS
6 PORT ( x: IN STD_LOGIC_VECTOR (3 DOWNTO 0);
7 y: OUT STD_LOGIC_VECTOR (1 DOWNTO 0));
8 END encoder;
9 ---------------------------------------------
10 ARCHITECTURE encoder1 OF encoder IS Exemple d’application:
11 BEGIN
encodeur clavier pour PIC
12 y <= "00" WHEN x="0001" ELSE
13 "01" WHEN x="0010" ELSE Intérêt: réduire le nombre d’entrée du PIC
14 "10" WHEN x="0100" ELSE
15 "11" WHEN x="1000" ELSE
20 "ZZZ";
21 END encoder1;
22 ---------------------------------------------
Logique combinatoire: Instructions concurrentes
Assignation sélective with expression select
signal1 <= signal1 when valeur 1,
Le multiplexeur: on aiguille une entrée vers la sortie signal2 when valeur2,
------
en fonction d’un numéro d’aiguillage signal par défaut when others ;
Autre possibilté:
MUX std_logic_vector(
1 voie parmi 4 1 downto 0)
Logique combinatoire: Instructions concurrentes
• Instanciation (placement) de composants déjà crées
• Découpage de votre projet en fonctions: création de composants adéquats
• Assemblage des composants créés pour structurer votre projet
• MOT CLE: PORT MAP
• Ma Référence :port map ( liste ordonnée de signaux) ;
Analogie avec ORCAD: on choisit un composant
de la bibliothèque en le référençant sur la feuille
• ou
Exemple: résistance R1
• Ma Référence : port map ( port=> signal , port => signal ) ; Un 555: U1
Exemple: applicatif: Comment faire un additionneur 4 bits?
LIBRARY IEEE;
Etape 1: je crée un composant ADDITIONNEUR 1 bits USE IEEE.STD_LOGIC_1164.ALL;
ENTITY fa IS PORT (
Ci, X, Y: IN STD_LOGIC;
S, Cout: OUT STD_LOGIC);
END fa;
ARCHITECTURE Dataflow OF fa IS
BEGIN
Cout <= (X AND Y) OR (Ci AND (X XOR Y));
S <= X XOR Y XOR Ci;
Full Adder END Dataflow;
Logique combinatoire: Instructions concurrentes
Etape 2: je valide le composant ( compilation /simulation)
Etape3: je structure mon niveau supérieur ( comment faire 4 bits avec 1 bit?)
END ARCHITECTURE
Logique combinatoire: exemples
• Décodeurs 7 segments
• UTILISATION D’UNE TABLE (LUT) POUR DECRIRE LE SYSTEME
entity decod7seg is library IEEE; Création de nouveaux types: TYPE
port( use IEEE.std_logic_1164.all;
iDigit:IN std_logic_vector(3 downto 0); use IEEE.std_logic_unsigned.all; Tableau: ARRAY
oSeg:OUT std_logic_vector(6 downto 0)
); --définition de l'architecture
end decod7seg; architecture arch_dec_7seg_v1 of decod7seg is
-- définition d'un nouveau type
-- tableau de 16 éléments de 7 bits
type ROM is array(15 downto 0) of std_logic_vector(6 downto 0);
--initialisation du tableau
-- tableau vu comme une mémoire(LUT)
signal LUT:ROM:=(
"1000000","1111001","0100100","0110000","0011001","0010010","0000010",
"1111000","0000000","0011000","0001000","0000011","1000110","0100001",
"0000110","0001110");
begin
-- pour indexer tableau il faut un entier
-- fonction de conversion conv_integer dans IEEE.std_logic_unsigned.all
oSeg<=LUT(conv_integer(iDigit));
Anode commune
end arch_dec_7seg_v1;
Segment actif à ‘0’
Logique combinatoire: exemples
• Additionneur « haut niveau »
• Emploi des librairies IEEE;
• On augmente la taille de 1 si l’on souhaite conserver la retenue d’entrée
architecture arch1_add4full of adddirect is
--librairie pour inclure type std_logic --creation de TEMP pour resultat: extension de 1 bit
library IEEE; signal TEMP:std_logic_vector(LARG downto 0);
use IEEE.std_logic_1164.all; begin
TEMP<=('0'&A)+('0'&B)+Cin;
use IEEE.std_logic_unsigned.all; --A et B etendu de 1 bit.
Res<=TEMP(TEMP'HIGH-1 downto 0);
entity adddirect is Cout<=TEMP(TEMP'HIGH);
--TEMP'HIGH renvoi indice poids fort
generic (LARG:integer:=4); end arch1_add4full;
-- parametre generique
-- taille aditionneur changer en 1 clic! Les attributs des signaux -Exemple S[5:0]
port(
S’HIGH renvoie 5 et S’LOW renvoie 0
Cin:IN std_logic;
A:IN std_logic_vector(LARG-1 downto 0); S’RANGE renvoie 5 downto 0
B:IN std_logic_vector(A'range); S’event renvoie TRUE si changement d’état de S
Res:OUT std_logic_vector(A'range);
Utilisation de GENERIC lors du PORT MAP
Cout:OUT std_logic
); U1: generic(10)
end adddirect; adddirect PORT MAP(xxxxxx);
Logique combinatoire: exemples
Arithmetic Logic Unit (ALU)
Sélection Op arithmétique/logique
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4 USE ieee.std_logic_unsigned.all;
5 ----------------------------------------------
Code Opératoire (mot de commande sur 3 bits)
6 ENTITY ALU IS
7 PORT (a, b: IN STD_LOGIC_VECTOR (7 DOWNTO 0);
8 sel: IN STD_LOGIC_VECTOR (3 DOWNTO 0); 26 ----- Logic unit: -----------
9 cin: IN STD_LOGIC;
10 y: OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
27 WITH sel(2 DOWNTO 0) SELECT
11 END ALU; 28 logic <= NOT a WHEN "000",
12 ---------------------------------------------- 29 NOT b WHEN "001",
13 ARCHITECTURE dataflow OF ALU IS 30 a AND b WHEN "010",
14 SIGNAL arith, logic: STD_LOGIC_VECTOR (7 DOWNTO 0); 31 a OR b WHEN "011",
15 BEGIN 32 a NAND b WHEN "100",
16 ----- Arithmetic unit: ------ 33 a NOR b WHEN "101",
17 WITH sel(2 DOWNTO 0) SELECT
18 arith <= a WHEN "000",
34 a XOR b WHEN "110",
19 a+1 WHEN "001", 35 NOT (a XOR b) WHEN OTHERS;
20 a-1 WHEN "010", 36 -------- Mux: ---------------
21 b WHEN "011", 37 WITH sel(3) SELECT
22 b+1 WHEN "100", 38 y <= arith WHEN '0',
b-1 WHEN "101", 39 logic WHEN OTHERS;
24 a+b WHEN "110", 40 END dataflow;
25 a+b+cin WHEN OTHERS;
41 ----------------------------------------------
Logique combinatoire: exemples
• Buffers 3 états
De manière générale il faut se poser la question:
Le composant cible dispose t’il des ressources
nécessaires pour synthétiser ma fonction
1 LIBRARY ieee; Pas de 3 états possibles si le composants n’en a
2 USE ieee.std_logic_1164.all; pas!!
3 ----------------------------------------------
4 ENTITY tri_state IS
5 PORT ( ena: IN STD_LOGIC;
6 input: IN STD_LOGIC_VECTOR (7 DOWNTO 0);
7 output: OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
8 END tri_state;
9 ----------------------------------------------
10 ARCHITECTURE tri_state OF tri_state IS
11 BEGIN
12 output <= input WHEN (ena='0') ELSE
13 (OTHERS => 'Z');
14 END tri_state;
15 ----------------------------------------------
Logique séquentielle: le process
• Le mot clé PROCESS
• Syntaxe:
• Le PROCESS est activé lors d’un changement d’état d’un des signaux de la liste de
sensibilité
• Une fois dans le PROCESS le déroulement est SEQUENTIELLE
• Les instructions utilisables dans un PROCESS sont SPECIFIQUE ( pas de when/else
par exemple)
• Les signaux sont mis à jour uniquement à la fin du process
Processus activé
Logique séquentielle: le process
• Rendre synchrone
• Bascule D edge: fonctionnement sur front
Autre façon:
Process(CLK)
Begin
If (CLK=‘1’) then
Q<=D;
End if;
End process;
Logique séquentielle: le process
• Ecriture correcte des process
• Les compilateurs imposent une certaine rigidité dans la description des process
• Les règles a respecter
process(horl)
if (horl’event and horl = ‘1’) then Ce qu’il faut faire!
if (ena = ‘ 1 ’) then
En pratique le FPGA (ou
contenu_registre <= valeur_in;
CPLD) possède une ou
end if;
des broches spécifiques
end if;
pour le signal d’horloge
end process;
Logique séquentielle: le process
• Penser à l’initialisation du systèmes
• Signaux reset et set: comportement défini par l’utilisateur
Reset et Set SYNCHRONE
LIBRARY ieee;
On remarquera que RST a
USE ieee.std_logic_1164.all;
disparu de la liste de sensibilité
---------------------------------------
ENTITY dff IS
PORT ( d, clk, rst: IN STD_LOGIC;
q: OUT STD_LOGIC); process (CLK)
END dff; Begin
if (CLK'event and CLK ='1') then
--------------------------------------- if (RESET =’1’) then
S <= ‘0’;
ARCHITECTURE behavior OF dff IS elsif (SET =’1’)then Actif à 1 ici pour l’exemple
BEGIN S <= ‘1’;
else
PROCESS (rst, clk) S <= D;
end if;
BEGIN end if;
IF (rst=‘0') THEN end process ;
q <= '0';
ELSIF (clk'EVENT AND clk='1') THEN Reset ASYNCHRONE
q <= d;
Comportement
END IF;
synchrone de la bascule
END PROCESS;
END behavior;
Logique séquentielle: le process
• Mise à jour des signaux à la fin du process
• Exemple 1: bascule avec sortie complémentée
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY Compteur IS
PORT (
clk,load :IN std_logic;
qs : OUT std_logic_vector(3 downto 0);
qe : IN std_logic_vector(3 downto 0));
END Compteur;
ARCHITECTURE acmpt OF Compteur IS
SIGNAL q :std_logic_vector(3 downto 0);
BEGIN
qs <= q;
PROCESS(clk,load) BEGIN
IF load='1' THEN
q<=qe; -- ou q<=31; valeur predefinie
ELSIF clk'event and clk='1' THEN
q<=q+1;
END IF;
END PROCESS;
END acmpt;
Logique séquentielle: le process
Compteur 4 bits BCD avec validation d'horloge
architecture Behavioral of Counter2_VHDL is
un compteur BCD, c'est à dire qui compte de 0 à 9 signal temp: std_logic_vector(3 downto 0);
begin
process(Clock,Reset) begin
library IEEE; if Reset='1' then
use IEEE.STD_LOGIC_1164.ALL; temp <= "0000";
use IEEE.STD_LOGIC_ARITH.ALL; elsif(Clock'event and Clock='1') then
use IEEE.STD_LOGIC_UNSIGNED.ALL; if Clock_enable='0' then
entity Counter2_VHDL is if temp="1001" then
port(
temp<="0000";
Clock_enable: in std_logic;
Clock: in std_logic; else temp <= temp + 1;
Reset: in std_logic; end if;
Output: out std_logic_vector(3 downto 0)); else temp <= temp;
end Counter2_VHDL; end if;
end if;
end process;
Output <= temp;
end Behavioral;
Logique séquentielle: le process
Résultats de simulation
Logique séquentielle: le process
Compteur 4 bits
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter is
Port ( CLOCK : in STD_LOGIC;
DIRECTION : in STD_LOGIC;
COUNT_OUT : out STD_LOGIC_VECTOR (3 downto 0));
end counter;
architecture Behavioral of counter is
signal count_int : std_logic_vector(3 downto 0) := "0000";
begin
process (CLOCK)
Begin
if CLOCK='1' and CLOCK'event then
if DIRECTION='1' then
count_int <= count_int + 1;
else
count_int <= count_int - 1;
end if;
end if;
end process;
COUNT_OUT <= count_int;
end Behavioral;
Logique séquentielle: les instructions
• Assignations directes Library ieee;
• S<= signal; Use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Use ieee.std_logic_unsigned.all;
entity CMP4BITS is
PORT (
CLOCK : in std_logic;
Q : out std_logic_vector (3 downto 0));
end CMP4BITS;
Q est défini en sortie
architecture DESCRIPTION of CMP4BITS is
OR Q<=Q+1 signifie signal Q_BUS_INTERNE : std_logic_vector(3 downto 0));
Relire état courant et incrémente begin
Solution 1: définir BUFFER au lieu process (CLOCK)
de OUT begin
if (CLOCK ='1' and CLOCK'event) then
Solution 2: couramment utilisée: Q_BUS_INTERNE <= Q_BUS_INTERNE + 1;
end if;
passer par un signal
end process;
Q <= Q_BUS_INTERNE; -- affectation du bus interne au
-- signal de sortie Q
end DESCRIPTION;
Logique séquentielle: les instructions
• Assignation conditionnelle COMPTEUR GRAY
LIBRARY ieee;
• Structure SI/SINON SI USE ieee.std_logic_1164.all;
USE work.std_arith.all;
entity GRAY is
Library ieee; port (H,R :in std_logic;
Use ieee.std_logic_1164.all; Q :out std_logic_vector(2 downto 0));
Use ieee.numeric_std.all; end GRAY;
Use ieee.std_logic_unsigned.all; architecture ARCH_GRAY of GRAY is
entity BASCULET is signal X :std_logic_vector(2 downto 0);
port ( begin
D,CLK : in std_logic; Bascule T
process(H,R)
S : buffer std_logic); begin
end BASCULET; T comme TOGGLE ( basculement) if R='1' then X <= "000";
La sortie change d’état à chaque front ( elsif (H'event and H='1') then
architecture DESCRIPTION of if X = "000" then X <= "001";
BASCULET is utilisation pour la synthèse des compteurs)
elsif X = "001" then X <= "011";
begin elsif X = "011" then X <= "010";
PRO_BASCULET : process (CLK) elsif X = "010" then X <= "110";
Begin elsif X = "110" then X <= "111";
if (CLK'event and CLK='1') then elsif X = "111" then X <= "101";
if (D=’1’) then Compteur elsif X = "101" then X <= "100";
S <= not (S); de GRAY elsif X = "100" then X <= "000";
end if; end if;
end if; end if;
end process PRO_BASCULET; Code binaire réfléchi
end process;
end DESCRIPTION; Q <= X;
(codeur de position par exemple)
end ARCH_GRAY;
Logique séquentielle: les instructions
• Assignation conditionnelle
• Structure CASE/IS
• Utile pour décrire des grafcets, machine d’états
Case selecteur is
when condition1 => instructions ;
…….
instructions ;
when condition2 => instructions ;
----
when others => instructions ;
end case ;
Any Questions ?
“The future depends on what you do today.”