Académique Documents
Professionnel Documents
Culture Documents
systèmes VHDL
M. Kthiri Moez
Maitre assistant à l’ISLAIB
Electronique reprogrammable
▪ Apparition des premiers circuits vers les années 70: premiers PLD-> PAL, GAL
▪ Evolution vers composants plus complexes: CPLD, FPGA
▪ Différentes technologies pour la programmation des connexions
✓ Permanents , Volatiles statiques, Volatiles
✓ Capacité de programmation In-Situ
• composants dits ISP via interface JTAG
▪ Contexte de compétitivité mondiale
✓ Importance du Time-To-Market
2
Connexions programmables
Introduction
▪ Deux formes canoniques pour les équations logiques
✓ Somme de produits S=a.b+ c.d
✓ Produits de somme S=(z+f).(e +x)
Connexions programmables
ET cablé
Représentation
standard
OU cablé
Exemple de référence
Famille Cyclone (FPGA Low Cost
d’ALTERA)
Concurrent: Spartan3 (chez Xilinx)
4
FPGA
Specifications
La carte DE2 (utilisé en TP) FPGA
• Cyclone II EP2C35F672C6 FPGA and
EPCS16 serial configuration device
I/O Devices
• Built-in USB Blaster for FPGA configuration
• 10/100 Ethernet, RS-232, Infrared port
• Video Out (VGA 10-bit DAC)
• Video In (NTSC/PAL/Multi-format)
• USB 2.0 (type A and type B)
• PS/2 mouse or keyboard port
• Line-in, Line-out, microphone-in
(24-bit audio CODEC)
• Expansion headers (76 signal pins)
Memory
• 8-MB SDRAM, 512-KB SRAM, 4-MB Flash
• SD memory card slot
Switches, LEDs, Displays, and Clocks
• 18 toggle switches
• 4 debounced pushbutton switches
• 18 red LEDs, 9 green LEDs
• Eight 7-segment displays
• 16 x 2 LCD display
• 27-MHz and 50-MHz oscillators, external SMA clock input5
VHDL introduction
Programmation ou description?
▪ Les objectifs du langage VHDL
✓ Conception de circuits intégrés reconfigurable ou non (ASIC, FPGA…) : SYNTHESE
✓ Mise au point de modèle de simulations numériques (circuits virtuels) : MODELISATION
▪ Le langage est capable de DECRIRE
✓ des comportements CONCURRENTS ( // )
✓ Des comportements séquentiels
6
VHDL: concepts de base
Structure générale
Votre fichier texte de
description: xxx.vhd
7
Flot de conception
8
VHDL: concepts de base
Méthodologie de conception
▪ Guide pratique du débutant
✓ Décomposition du cahier des charges en fonctions élémentaires
✓ Classification de la fonction
• COMBINATOIRE: instructions dites concurrentes
• SEQUENTIELLE: utilisation d’un PROCESS
La sortie ne dépend pas de l’état passé La sortie dépend de son état passé
Un vecteur d’entrée = un vecteur de sortie unique Système nécessitant une horloge (systèmes dits
synchrones)
Des exemples:
Des exemples:
•Multiplexeurs
•Compteurs
•Additionneurs
•Registres à décalage
•Décodeur 7 segements
•Machine d’état (automate)
•Encodeurs de priorité 9
VHDL: concepts de base
Sorties pilotant
les Leds de
Séquentiel donc process l’afficheur 1
COMPT: PROCESS(CLK)
Begin
….
END PROCESS;
11
VHDL: concepts de base
Les librairies
▪ Facilite la tâche du concepteur
▪ Rajout de fonctionnalités supplémentaires
La librairie IEEE
▪ A mettre au début de votre description
▪ Pour rajouter les types étendues std_logic et std_logic_vector
✓ use IEEE.STD_LOGIC_1164.all;
▪ DORENAVANT nous remplacerons SYSTEMATIQUEMENT
✓ BIT par STD_LOGIC
✓ BIT_VECTOR par STD_LOGIC_VECTOR
▪ Pour utiliser des fonctions arithmétiques sur ces STD_LOGIC_VECTOR
✓ USE IEEE.NUMERIC_STD.ALL;
✓ Et aussi USE IEEE.std_logic_arith.all;
• Q<=Q+1; -- Q étant par exemple un std_logic_vector et 1 est un entier!!
Exemples
• A<B -- A et B des std_logic_vector
Applicatifs • oData<=CONV_STD_LOGIC_VECTOR(TEMP,8); avec TEMP integer range 0 to 255;
12
VHDL: concepts de base
13
VHDL: concepts de base
Littéraux
▪ Caractères: ’0’, ’x’,’a’,’%’
▪ Chaînes: ”11110101”,”xx”,”bonjour”,”$@&” Ne pas confondre 1 bit
14
Logique combinatoire: Instructions concurrentes
16
Logique combinatoire: Instructions concurrentes
MUX
Autre possibilté:
1 voie parmi 4 std_logic_vector(1 downto 0)
17
Logique combinatoire: Instructions concurrentes
ENTITY ET4 IS
PORT
(X1,X2,X3,X4 : IN
--librairie pour inclure type std_logic
STD_LOGIC;
library IEEE;
Y: OUT STD_LOGIC
use IEEE.std_logic_1164.all;
);
Je commence par faire ma END ET4;
Je respecte les noms
ENTITY ET2 IS ET2 choisis sur papier
PORT
ARCHITECTURE arch_ET4 OF ET4 IS
(
-- partie déclarative COMPOSANT
A,B: IN STD_LOGIC;
On COMPONENT ET2 is
S: OUT STD_LOGIC
PORT
); déclare
(A,B: IN STD_LOGIC;
END ET2; ET2 S: OUT STD_LOGIC);
END COMPONENT ET2;
ARCHITECTURE arch_ET2 OF ET2 IS
-- partie déclarative SIGNAL
BEGIN
--pas de IN ou OUT car signal INTERNE Les fils de
S<= A and B;
SIGNAL FIL1,FIL2: STD_LOGIC ;
END arch_ET2; connexions
BEGIN INTERNES
-----------------------
-- 1ere porte ET placée
U1:ET2 port map (A=>X1,B=>X2,S=>FIL1);
-- 2ème porte ET placée
U2:ET2 port map (A=>X3,B=>X4,S=>FIL2);
-- 3ème porte ET placée PORT MAP
U3:ET2 port map (A=>FIL1,B=>FIL2,S=>Y); pour
-- on pourrait faire à la place !!!! placement et
2 fichiers .vhd avec chacun 1 entity+1 architecture -- Y<= X1 and X2 and X3 and X4
END arch_ET4;
connexion
20
Logique combinatoire: Instructions concurrentes
--les libraries
library IEEE;
Bilan use IEEE.std_logic_1164.all;
……….
▪ Pour décrire des systèmes combinatoires les
instructions types « concurrentes » seront ENTITY LENIVEAUTOP (
………..)
préférées End ENTITY
▪ L’ordre des instructions est SANS ARCHITECTURE …..
IMPORTANCE ( car en parallèle)
COMPONENT Truc
▪ Il est souhaite de scinder les projets en …
composants simples END COMPONENT Déclaration de
COMPONENT Machin
✓ APPROCHE METHODOLOGIQUE TOP-DOWN …
composants créés
SIGNAL: ……….
SIGNAL: ……..
XX<=“1110”;
Squelette de YY<= A AND B;
U1: Truc PORT MAP( …….);
description S<= “10” when (A=B) else
Utilisation des
ressources
“00”;
VHDL U2: Machin PORT MAP( …….);
disponibles
Décodeurs 7 segments
▪ UTILISATION D’UNE TABLE (LUT) POUR DECRIRE LE SYSTEME
Création de
library IEEE; nouveaux types:
entity decod7seg is use IEEE.std_logic_1164.all; TYPE
port( use IEEE.std_logic_unsigned.all; Tableau: ARRAY
iDigit:IN std_logic_vector(3 downto 0);
oSeg:OUT std_logic_vector(6 downto --definition de l'architecture
architecture arch_dec_7seg_v1 of decod7seg is
0)
-- definition d'un nouveau type
); -- tableau de 16 elements de 7 bits
end decod7seg; type ROM is array(15 downto 0) of std_logic_vector(6 downto 0);
--initialisaion du tableau
-- tableau vu comme une memoire(LUT)
signal LUT:ROM:=(
"1000000","1111001","0100100","0110000","0011001","
0010010","0000010",
"1111000","0000000","0011000","0001000","0000011","
1000110","0100001",
"0000110","0001110");
begin
Carte DE2: -- pour indexer tableau il faut un entier
-- fonction de conversion conv_integer dans
✓Anode commune
IEEE.std_logic_unsigned.all
✓Segment actif à ‘0’ oSeg<=LUT(conv_integer(iDigit));
22
✓Brochage: voir p31 du manuel end arch_dec_7seg_v1;
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
Pas de 3 états possibles si le composants
n’en a pas!!
1 LIBRARY ieee;
2 USE ieee.std_logic_1164.all;
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 ----------------------------------------------
25
Logique séquentielle: le process
▪ 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
process Process Process(a,b)
begin begin begin
Écritures q <= d; c <= a and b; c <= a and b;
alternatives wait until Reloj = ‘1’; wait on a, b; end process;
end process; end process; 26
Logique séquentielle: le process
Réveil du process
▪ Exemple: bascule D latch
✓ Fonctionnement sur niveau
Processus activé
27
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;
28
Logique séquentielle: le process
Des solutions
SOLUTION 1:
SOLUTION 2:
process (RESET,CLOCK) process (RESET,CLOCK)
begin begin
if RESET ='1' then if RESET='1' then
CMP <= "0000"; CMP <= "0000";
elsif (CLOCK ='1' and CLOCK'event) elsif (CLOCK ='1' and
then CLOCK'event) then
CMP <= CMP + 1; CMP <= CMP + 1;
Je décris le
if (CMP = "1110") then end if;
combinatoire HORS
–- La retenue passera à un quand CMP end process;
du PROCESS
= 14 décimal
RET <= '1'; -- Validation de la retenue
else RET <= '1' when (CMP = "1111")
RET <= '0'; else '0';
Version complètement
end if; synchrone:
end if;
end process; J’anticipe pour avoir un résultat
correct
33
Logique séquentielle: les instructions
entity CMP4BITS is
PORT (
CLOCK : in std_logic;
Q : out std_logic_vector (3 downto 0));
Q est défini en sortie end CMP4BITS;
34
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 ;
36
Logique séquentielle: les instructions
1 --------------------------------------------------
Registre à décalage simple 2 LIBRARY ieee;
▪ Sortie série ( 1 seule sortie) 3 USE ieee.std_logic_1164.all;
4 --------------------------------------------------
ENTITY shiftreg IS
6 GENERIC (n: INTEGER := 4);
7 PORT (d, clk, rst: IN STD_LOGIC;
8 q: OUT STD_LOGIC);
9 END shiftreg;
10 --------------------------------------------------
11 ARCHITECTURE behavior OF shiftreg IS
12 SIGNAL internal: STD_LOGIC_VECTOR (n-1 DOWNTO 0);
13 BEGIN
14 PROCESS (clk, rst)
15 BEGIN
16 IF (rst='1') THEN
17 internal <= (OTHERS => '0');
18 ELSIF (clk'EVENT AND clk='1') THEN
19 internal <= d & internal(internal'LEFT DOWNTO 1);
20 END IF;
21 END PROCESS;
22 q <= internal(0);
23 END behavior;
24 --------------------------------------------------
38
Logique séquentielle: des exemples
Registre à décalage
LIBRARY ieee;
▪ Sortie parallèle USE ieee.std_logic_1164.all;
▪ Choix du sens USE work.std_arith.all;
entity DECAL_DG is
port (H,R,SENS :in std_logic;
IN_OUT,OUT_IN :inout std_logic);
end DECAL_DG;
architecture ARCH_DECAL_DG of DECAL_DG is
signal Q :std_logic_vector(3 downto 0);
begin
process(H,R)
begin
if R='1' then Q <= "0000";
Emploi de signaux et non de elsif (H'event and H='1') then
variables if SENS = '1' then
Q <= Q(2 downto 0) & IN_OUT;
Affectation en dehors du else Q <= OUT_IN & Q(3 downto 1);
process end if;
end if;
end process;
OUT_IN <= Q(3) when SENS = '1' else 'Z';
IN_OUT <= Q(0) when SENS = '0' else 'Z';
end ARCH_DECAL_DG;
39
Logique séquentielle: des exemples
Une RAM
LIBRARY ieee;
USE ieee.std_logic_1164.all;
---------------------------------------------------
ENTITY ram IS
GENERIC ( bits: INTEGER := 8; -- # of bits per word
words: INTEGER := 16); -- # of words in the memory
PORT ( wr_ena, clk: IN STD_LOGIC;
addr: IN INTEGER RANGE 0 TO words-1;
data_in: IN STD_LOGIC_VECTOR (bits-1 DOWNTO 0);
data_out: OUT STD_LOGIC_VECTOR (bits-1 DOWNTO 0));
12 END ram;
---------------------------------------------------
ARCHITECTURE ram OF ram IS Création d’un nouveau type:
TYPE vector_array IS ARRAY (0 TO words-1) OF STD_LOGIC_VECTOR (bits-1 DOWNTO 0); TYPE
SIGNAL memory: vector_array; Déclaration d’un signal du type C’est un tableau de vecteurs
BEGIN créé précédemment
PROCESS (clk, wr_ena)
BEGIN
IF (clk'EVENT AND clk='1') THEN
IF (wr_ena='1') THEN
memory(addr) <= data_in;
END IF;
END IF;
END PROCESS;
data_out <= memory(addr); 40
END ram;
Logique séquentielle: des exemples
Diviseur de fréquence
▪ Diviseur par comptable
▪ Possibilité de faire par décomptage aussi
LIBRARY ieee; Application et utilisation d’un
USE ieee.std_logic_1164.all;
USE ieee.std_arith.all; diviseur de fréquence
entity DIV_FREQ1 is
port (H :in std_logic; •On évitera de cascader la sortie du
N :in std_logic_vector(3 downto 0); diviseur sur l’horloge du bloc suivant
DIV : out std_logic);
end DIV_FREQ1;
architecture ARCH_DIV_FREQ1 of DIV_FREQ1 is •La bonne méthode:
signal Q :std_logic_vector(3 downto 0); Horloge du système LA même
begin pour tous les blocs
process(H) La sortie du diviseur est une
begin entrée de validation du bloc
if (H'event and H='1') then suivant
if Q = 15 then Q <= N; Si En=‘1’ alors je
else Q <= Q + 1; compte
end if;
end if;
end process;
DIV <= '1' when Q = 15 else '0';
end ARCH_DIV_FREQ1;
41
Logique séquentielle: des exemples
LIBRARY ieee;
USE ieee.std_logic_1164.all; COMPOSANT HAUT NIVEAU
USE work.std_arith.all; LIBRARY ieee;
entity COMPTCAS is USE ieee.std_logic_1164.all;
port (H,R,EN :in std_logic; USE work.std_arith.all;
CO :out std_logic; entity COMPT12 is
Q :out std_logic_vector(3 downto 0)); port (H,RAZ,EN :in std_logic;
end COMPTCAS; CO :out std_logic;
architecture ARCH_COMPTCAS of COMPTCAS is Q :out std_logic_vector(11 downto 0));
end COMPT12;
signal X :std_logic_vector(3 downto 0);
architecture ARCH_COMPT12 of COMPT12 is
begin signal X :std_logic_vector(11 downto 0);
process(H,R) signal CO1,CO2,CO3,EN1 :std_logic;
begin component COMPTCAS
if R='1' then X <= "0000"; port (H,R,EN : in std_logic;
elsif (H'event and H='1') then CO : out std_logic;
if EN = '1' then X <= X + 1; Q : out std_logic_vector(3 downto 0));
else X <= X; end component;
end if; begin
COMPTEUR1 : COMPTCAS port map(H,RAZ,EN,CO1,Q(3 downto 0));
end if;
COMPTEUR2 : COMPTCAS port map(H,RAZ,CO1,CO2,Q(7 downto 4));
end process; EN1 <= CO1 and CO2;
Q <= X; COMPTEUR3 : COMPTCAS port map(H,RAZ,EN1,CO3,Q(11 downto 8));
CO <= '1' when Q = 15 else '0'; CO <= CO1 and CO2 and CO3;
42
end ARCH_COMPTCAS; end ARCH_COMPT12;
Logique séquentielle: des exemples
43
Bibliographie
44