COURS VHDL PROGRAMMATION ET _ETAPES pour comprendre
1. Elément1 : Circuits FPGA et LangageVHDL
FPGA : Field Programmable Grid Array
V : VHSIC (Very High Speed Integrated Circuit)
H : Hardware
D : Description
L : Language
Animé par le professeur:
Mohammed NAHID
UNIVERSITÉ HASSAN II CASABLANCA
FACULTÉ DES SCIENCES ET TECHNIQUES
DÉPARTEMENT GÉNIE ÉLECTRIQUE
Master : Ingénierie des Systèmes Embarqués & Réseaux et Télécommunications
2. 2
Présentation des Circuits Logiques Programmables
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
Montage du circuit Programmation Programmation
non programmé sur site éventuelle
Circuit Numérique
SPECIFIQUE
à l'Application
STANDARD (Conçu et
Réalisé par le Fabricant)
Une fonction
par circuit
Spécialisés
Séquentiables
(Full Custom)
Configurables
(Semi Custom)
Mixtes : FPGA + Micro + RAM
PLDs
RAM, ROM
à Mémoire
MicroProcesseurs
MicroControleurs
DSP
Périphériques
standard, ASICs
PLA, PAL, EPLD
ou CPLD, FPGA
SOC (System On Chip)
Un système électronique
numérique peut être
implémenté avec des
circuits logiques de
divers types :
3. 3
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)
ET cablé
OU cablé
Connexions programmables
Représentation standard
Constitution d’un réseau programmable
4. 4
Simple Programme Logic Device
Composants simples
réseau ET/OU programmable ou fixe
PAL (OTP en général), GAL reprogrammable
Différentes familles en fonction des
ressources rajoutés par le constructeur
xPLD
5. 5
Field Programmable Grid Array
Granularité plus fine que les CPLD ( macrocellules - complexes mais + nombreuses)
Exemple de référence
Famille Cyclone (FPGA
Low Cost d’ALTERA)
Concurrent: Spartan3 (chez
Xilinx)
Répartition des applications Source Altera
FPGA
Intégration matérielle de composants supplémentaires
RAM: appelé LUT (Look-Up Table)
Multiplexeurs divers
PLL
Multiplieurs câblés (FPGA haut de gamme => concurrence avec les DSP)
Réseau de routage réparti ( non centralisé contrairement aux CPLD)
6. REFERENCES DES CIRCUITS LOGIQUES PROGRAMMABLES
6
Ex: PAL 16 L 8
Références des PALs
Références des FPGAs
8. 8
CPU board structure
●Use resistance controlling 12 layer high precision PCB board to make sure the frequency of the
signal on board up to 200MHz
●Use Cyclone III EP3C40F780C8(option Cyclone III EP3C80,EP3C120' option C7 C6 speed level)
●EPCS16AS mode configuration, combining 100M internet'support CycloneIII special remote
system upgrade function
●Standard 32M DDR2 memory. Highest executive frequency 166.667MHZ (option C6 speed level
is 200MHZ)
●1MB(256K×32)SRAM
●8MB NOR Flash-ROM
●64MB NAND Flash-ROM
●USB-Blaster Rev.C on board
●Mini USB2.0 device interface
FPGA : EP3C40F780C8
9. 9
System board:
●Support CycloneII,CycloneIII series core board
●800×600 large resolution full color LCD and 4 line resistance touch type screen
●1 4-phase step motor
●1 adjustable speed,measurable current step motor
●1 canonical sequence interface
●2 PS2 interface
●1 USB device interface
●1 USB host interface
●1 Ethernet network interface
●1 16×16 point array LED
●1 4×4 key array
●8 bits dynamic 7-segment LED
●USB-Blaster Rev.C on board
●Mini USB2.0 device interface
●RS232 standard series port
●High speed SD card interface
●50MHz system clock on board
●4 LED user setting
●4 key user setting
●1 7-segment LED
●1 reset key
●1 extended interface
●AS program designing interface and JTAG interface
10. 10
●12 LED user setting
●12 key user setting
●12 key input user setting
●Liquid driving module on board
●1 SD card interface
●Touch control screen controller
●2 extension interface
●1 digital clock source, supply more clock
●Audio Codec:1 audio input interface'1 Mic input interface'1 audio output interface and 1
●earphone interface
●1 analogy signal source'supply frequency,amplitude adjustable sine wave,square wave,triangular
wave and sawtooth wave
Extended interface of the system board 1 : (Standard)
●8 bits double channel parallel AD module sampling frequency 28MSPS
●12 bits high-speed parallel DA module sampling frequency 30MSPS
●12 bits high-speed seriesAD/DA module
●1 video coding、decoding module
●1 full colorVGA module
●1 infrared receive send module
●1 real-time clock RTC module
●1 I2C EEPROM module
●1 digital temperature sensor module
●1 high-speed extended module
●6 high-speed signal measurable channel
11. 11
Software Experiments
EDA experiment and electronics design competition
content:
●7 men voting machine
●Gray code conversion…
●BCD code adder
●4 men quiz buzzer
●4 bits parallel multiplier
●Design basic trigger
●Variable step size add-subtract counter
●Controlled pulse generator
●Plus-minus pulse width modulation signal generator
●Sequence detector
●Taxi fare register
●Multifunctional digital clock
●Music memory player
●Digital stopwatch
●Frequency meter
●Traffic light controller
●Coded lock
●VGA color bar generator and image display controller design
12. 12
NIOSII32 bits processor demo experiment
●Hello experiment
●DIP seitch、key and LED experiment
●Key scan & 8 bits 7 segment display experiment
●Motor velocity measurement
●Timer experiment
●Sequence port communication experiment
●SPI interface audio Codec experiment
●High-speedAD and high-speed DA experiment
●SRAM&DMA experiment
●Flash ROM operation experiment
●Image point array LCD display experiment
●USB communication experiment(Include USB controller)
●Ethernet communication experiment(include Ethernet controller)
●Audio CODEC experiment
●PS2 key experiment
●Infrared communication experiment
●Wire digital temperature meter experiment
DSP Builder Design application demo experiment
●From DSP Builder to HDL——Based on DSP Builder signal generator
●From DSP Builder to SOPC Builder——Software controlled Chirp signal generator
●IP core is used in DSP Builder——Take FFT core for example
13. 13
Comprehensive development experiment
●SD card reading and writing experiment
●CF card reading and writing experiment
●Design direct current motor closed loop speed adjustment
●Easy digital oscilloscope design
●Easy frequency analysis design
●USB interface file reader design
●Video collection display design
●Color LCD principle and plotting application experiment
●Based on MP3 multimedia player design(option MP3 extended board)
●Based on RFID design(option RFID extended board)
●Based on NIOSII calculator design experiment
●Based on NIOSII Belly-worship snake design experiment
14. 14
VHDL: Introduction
Programmation ou description?
Les deux portes
travaillent en //
Le langage est capable de DECRIRE
des comportements CONCURRENTS ( // )
Des comportements séquentiels
Synthèse ou modélisation
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
15. 15
15
Structure générale
Le fichier texte de description: xxx.vhd
Le mode transfert des
signaux de l’entity
VHDL: Concepts de base
Déclaration des Bibliothèques
Commentaires enVHDL commencent par --
Déclaration de l’entité de Démultiplexeur
Déclaration de l’architecture
de Démultiplexeur
16. 16
Un outils de développement: Quartus II d’Altera
Flot de conception
Entrée schématique Entrée syntaxique
Langages :VHDL
Diagrammes d’états
Simulation
comportementale
Simulation Après
synthèse
Simulation
temporelle
Vérification des erreurs de
schémas et de syntaxe
SYNTHETISEUR
Il convertit en fonction du circuit cible
(CPLD ou FPGA: suivant le modèle
choisi) le projet en portes logiques et
bascules de bases.
De plus, on peut lui spécifier des
contraintes technologiques tel que la
vitesse de fonctionnement
Optimisation
Placement/Routage
dans circuit choisi
CIRCUIT
CPLD
FPGA
VHDL
VHDL
VHDL VHDL
JEDEC
EDIF, XNF
STIMULI ou
TESTBENCH
STIMULI ou
TESTBENCH
STIMULI ou
TESTBENCH
VITAL, VHDL
VITAL, VHDL, SDF
SYNTHETISEURS CONNUS:
- FPGA Express (Synosys)
-EXEMPLAR (ExemplAr)
-SYNPLICITY (Synplicity)
Outils de Placement et Routage au circuit interne:
Chaque outil est propre à chaque fabricant
La programmation du circuit se fait soit
-En utilisant un Programmateur
-En téléchargeant le code JEDEC directement
sur l’objet technique (JTAG ou ISP)
17. 17
Méthodologie de conception
Guide pratique du débutant
Décomposition du cahier des charges en fonctions élémentaires
Classification de la fonction
Logique combinatoire
La sortie ne dépend pas de l’état passé
Un vecteur d’entrée = un vecteur de sortie
unique
Des exemples:
• Multiplexeurs
• Additionneurs
• Décodeur 7 segments
• Encodeurs de priorité
Logique séquentielle
La sortie dépend de son état passé
Système nécessitant une horloge (systèmes
dits synchrones)
Des exemples:
• Compteurs
• Registres à décalage
• Machine d’état (automate)
VHDL: Concepts de base
• SEQUENTIELLE: utilisation d’un processus (PROCESS)
• COMBINATOIRE: instructions dites concurrentes
18. 18
Les questions à se poser
Exemple: faire une porte ET4 entrée avec des ET2 entrées
On créera 1 composant ET2
(entity+architecture) Utilisé 3
fois pour décrire ET4
ET4 est un composant
(entity+architecture)
Il faut un SIGNAL
VHDL: Concepts de base
Le bloc est-il utilisé plusieurs fois
Si oui il vaut mieux créer un composant (entity+ architecture)
Sinon le bloc est synthétisé par les lignes de codes directement
Le bloc est-il combinatoire ou séquentiel?
Si séquentiel alors description avec le mot clé PROCESS + instructions autorisées
On répertorie les signaux INTERNES (mot clé SIGNAL)
On repère et on nomme les entrées de chaque blocs ( on évite d’utiliser
les mêmes noms)
On identifie les fonctions et on les dessine sur papier
A
B
S
ET2
A
B
S
ET2
A
B
S
ET2
Fil1
Fil2
X1
X2
X3
X4
Y
ET4
19. Compteur
H
En
Q
R
Compteur
H
En
Q
R
Décodeur
7 Segments
In Out
Décodeur
7 Segments
In Out
CLK
U2
U1 U3
U4
Fil1[3..0]
Fil2[3..0]
Seg1[6..0]
Seg2[6..0]
19
VHDL: Concepts de base
Un autre exemple: Horloge BCD 2 digits
Blocs décodeurs 7 segments - combinatoire
Blocs compteurs – séquentiel
Les Blocs compteurs sont cascadé pour la propagation de la retenue
Après 9 on a 0 avec 1 de retenue! Donc Affichage 10
Ce fil est interne au composant :
on le déclarera
SIGNAL FILS: bit_vector(3 downto 0);
Sorties pilotant les Leds
de l’afficheur 2
Séquentiel donc process
COMPT: PROCESS(CLK)
Begin
….
END PROCESS;
20. 20
Les librairies
Facilite la tâche du concepteur
Rajout de fonctionnalités supplémentaires
Exemples
Applicatifs
VHDL: Concepts de base
La librairie IEEE
A mettre au début de la 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
• Q<=Q+1; -- Q étant par exemple 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); avec TEMP integer range 0 to 255;
Pour utiliser des fonctions arithmétiques sur ces STD_LOGIC_VECTOR
USE IEEE.NUMERIC_STD.all;
Et aussi USE IEEE.std_logic_arith.all;
21. 21
VHDL: Concepts de base
Le rajout de use IEEE.std_logic_unsigned.all; permet
De travailler avec les opérateurs arithmétiques standart
de mélanger des entiers avec des std_logic_vector: A<= A +1;
IEEE.std_logic_unsigned.all et
IEEE.std_logic_arith.all sont des
anciennes bibliothèques
Ne pas mettre en même temps:
IEEE.numeric_std.all;
IEEE.std_logic_arith.all;
Préfèrez l’emploi de
IEEE.numeric_std.all;
Complément sur les opérations arithmétiques
Le rajout de use IEEE.numeric_std.all; permet
De travailler avec des valeurs signées et non signées
• signal A,B: signed(3 downto 0);
• signal tempo: unsigned(3 downto 0);
De convertir un std_logic_vector en signed ou unsigned
• A<= signed(SW(3 downto 0));
• B<=unsigned(RES);
De convertir des signed ou unsigned en std_logic_vector
• LEDG(3 downto 0)<=std_logic_vector(tempo);
De redimensionner des vecteurs
• Permet d’étendre le bit de signe correctement!
• signal A,B: signed(LARG downto 0);
A<= resize(signed(SW(LARG downto 1)),LARG+1);
De travailler avec les opérateurs arithmétiques standart
• >, >=, =<,<, + ,- etc….
Pour recopier le bit de poids fort:
A<= A(3)&A
A savoir
22. 22
Les opérateurs
Logiques (boolean, bit, std_ulogic):
AND, OR, NAND, NOR, XOR,XNOR, NOT
Relationnels ( retournent un boolean):
=, /=, <, <=, >, >=
Arithmétiques:
+, -, *, /, **, MOD, REM, ABS
Concaténations d’éléments de tableaux &:
"bon" & "jour" => "bonjour"
Ne pas confondre 1 bit
‘0’ ou ‘1’
Avec un vecteur de bits
” 11 ” ou ” 1101110 ”
Un bus (ou ensemble de
fils électrique) est
représenté sous forme
d’un vecteur de bits
STD_LOGIC_VECTOR (3 DOWNTO 0);
VHDL: Concepts de base
Littéraux
Caractères: ’0’, ’x’,’a’,’%’
Chaînes: ”11110101”,”xx”,”bonjour”,”$@&”
Chaînes de bits: B”0010_1101”, X”2D”, O”055”
(Notation pour les vecteurs de bits dans différentes bases)
Décimaux:27, -5, 4e3, 76_562, 4.25
Basés: 2#1001#, 8#65_07, 16#C5#e2
(Notation pour les valeurs entières dans différentes bases)
Encodeur
X[3..0]
Y[1..0]
23. 23
Assignation simples
library IEEE;
use IEEE.std_logic_1164.all;
--librairie pour inclure type std_logic
--portes ET
--3 entrées E2 E1 E0
-- 1 sortie S0
entity ET3 is
port (
E : IN std_logic_vector (2 downto 0);
S : OUT std_logic
);
end ET3;
--definition de l'architecture
architecture arch_ET3 of ET3 is
Begin
S<=E(2) and E(1) and E(0);
-- E(2) accès au fil 2
end arch_ET3;
library IEEE;
use IEEE.std_logic_1164.all;
entity exemple is
port (
E : IN std_logic_vector(2 downto 0);
S1 : OUT std_logic; --1 fil
S2,S3 : OUT std_logic_vector(3 downto 1); --3 fils S1[3:1]
S4 : OUT std_logic_vector(2 downto 0)
);
end exemple;
--définition de l'architecture
architecture arch_exemple of exemple is
begin
S1 <= '0';
S2 <= '1‘ & E(1 downto 0);
-- operateur COLLER (ou CONCATENE) &
-- S2(3) S2(2) S2(1)
-- '1' E(1) E(0)
S3 <= "101";
S4 <= "111" XOR E; --manip sur les bus directement
end arch_exemple;
Exemple 1 Exemple 2
Bit Poids fort
Bit Poids faible
Logique combinatoire: Instructions concurrentes
24. 24
Logique combinatoire: Instructions concurrentes
Assignation conditionnelle
Structure WHEN/ELSE
---- Solution 1: WHEN/ELSE------
LIBRARY ieee;
use ieee.std_logic_1164.all;
entity encoder is
port ( x: in std_logic_vector (3 downto 0);
y: out std_logic_vector (1 downto 0));
end encoder;
architecture encoder1 of encoder is
begin
y <= "00" when x="0001" else
"01" when x="0010" else
"10" when x="0100" else
"11" when x="1000" else
"ZZ";
end encoder1;
Exemple d’application:
encodeur clavier pour PIC
Intérêt: réduire le nombre d’entrée du PIC
signal <= signal_1 when expresion_boolénne else
………
signal_n when expresion_boolénne else
signal par défaut;
X[0]
X[1]
X[2]
X[3]
VCC
Encodeur
X[3..0]
Y[1..0]
n x m
Encodeur
(m-1:0)
......
X(1)
X(0)
X(n-2)
X(n-1)
25. 25
Logique combinatoire: Instructions concurrentes
with expression select
signal <= signal1when valeur 1,
signal2 when valeur2,
------
signalN par défaut when others ;
Le multiplexeur: on aiguille une
enrée vers la sortie en fonction d’un
numéro d’aiguillage
MUX : 1 voie parmi 4
---- Solution 2: WITH/SELECT------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity Combin3 is
port
(
C : in integer range 0 to 3;
E : in std_logic_vector (3 downto 0);
S : out std_logic
);
end Combin3;
architecture arch_combin3 of Combin3 is
begin
with c select
S <= E(0) when 0,
E(1) when 1,
E(2) when 2,
E(3) when 3;
end arch_combin3;
Autre possibilté:
std_logic_vector(1 downto 0)
S <= E(0) when "00",
E(1) when "01",
E(2) when "10",
E(3) when "11";
Assignation sélective
Structure WITH/SELECT
E0
E1
E2
E3 S
C1
C0
26. 26
Logique combinatoire: Instructions concurrentes
Instanciation (placement) de composants déjà crées
Découpage du projet en fonctions: création de composants adéquats
Assemblage des composants créés pour structurer le projet
MOT CLE: PORTMAP
Ma Référence :port map ( liste ordonnée de signaux) ;
• ou
Ma Référence : port map ( port=> signal , port => signal ) ;
Analogie avec ORCAD: on
choisit un composant de la
bibliothèque en le
référencant sur la feuille
Exemple: résistance R1
Un 555: U1
Exemple applicatif: Comment faire un additionneur 4 bits?
library IEEE;
use IEEE.std_logic_1164.all;
entity add1full is
port(
Ci : IN std_logic;
X,Y : IN std_logic;
S,Cout : OUT std_logic
);
end add1full;
architecture arch_add1full of add1full is
begin
S <= X xor Y xor Ci;
Cout <= (X and Y) or (X and Ci) or (Y and Ci);
end arch_add1full;
Full Adder
etape 1: On crée un composant ADDITIONNEUR 1 bits
27. 27
Logique combinatoire: Instructions concurrentes
étape 2: On valide le composant ( compilation /simulation)
architecture arch_add4full of add4full is
-- déclaration du composant add1full
component add1full is
port(
Ci : IN std_logic;
X,Y : IN std_logic;
S,Cout : OUT std_logic
);
end component add1full;
-- déclaration des fils internes pour le report carry
signal Fil1,Fil2,Fil3:std_logic;
begin
-- placement des 4 aditionneurs complets
U0 : add1full port map (Cin,A(0),B(0),Res(0),Fil1);
U1 : add1full port map (Fil1,A(1),B(1),Res(1),Fil2);
U2 : add1full port map
(X=>A(2),Y=>B(2),S=>Res(2),
Cout=>Fil3,Ci=>Fil2);
U3 : add1full port map (Fil3,A(3),B(3),Res(3),Cout);
end arch_add4full;
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;
étape3: On structure mon niveau supérieur ( comment faire 4 bits avec 1 bit?)
28. 28
Logique combinatoire: Concepts de bases
library IEEE;
use IEEE.std_logic_1164.all;
ENTITY ET2 IS
PORT
(
A,B : IN STD_LOGIC;
S : OUT STD_LOGIC
);
END ET2;
ARCHITECTURE arch_ET2 OF ET2 IS
BEGIN
S<= A and B;
END arch_ET2;
library IEEE;
use IEEE.std_logic_1164.all;
ENTITY ET4 IS
PORT ( X1,X2,X3,X4 : IN STD_LOGIC;
Y : OUT STD_LOGIC );
END ET4;
ARCHITECTURE arch_ET4 OF ET4 IS
-- partie déclarative COMPOSANT ET2
COMPONENT ET2 is
PORT
(A,B : IN STD_LOGIC;
S : OUT STD_LOGIC);
END COMPONENT ET2;
-- partie déclarative SIGNAL
--pas de IN ou OUT car signal INTERNE
SIGNAL FIL1,FIL2: STD_LOGIC ;
BEGIN
-- 1ere porte ET2 placée
U1:ET2 port map (A=>X1,B=>X2,S=>FIL1);
-- 2ème porte ET2 placée
U2:ET2 port map (A=>X3,B=>X4,S=>FIL2);
-- 3ème porte ET2 placée
U3:ET2 port map (A=>FIL1,B=>FIL2,S=>Y);
-- on pourrait faire à la place !!!!
-- Y<= X1 and X2 and X3 and X4
END arch_ET4;
On commence par faire ET2
Deux fichiers ET2 et ET4 .vhd avec
chacun une entity+une architecture
Les fils de
connexions
INTERNES
PORT
MAP pour
placement
et
connexion
Comment créer une ET4
29. 29
Logique combinatoire: Instructions concurrentes
Bilan
Pour décrire des systèmes combinatoires les
instructions types « concurrentes » seront
préférées
L’ordre des instructions est SANS
IMPORTANCE ( car en parallèle)
Il est souhaite de scinder les projets en
composants simples
APPROCHE METHODOLOGIQUE TOP-DOWN
Utilisation des bibliothèques IEEE
--les libraries
library IEEE;
use IEEE.std_logic_1164.all;
……….
ENTITY LENIVEAUTOP (
………..)
End ENTITY
ARCHITECTURE …..
COMPONENT Truc
…
END COMPONENT
COMPONENT Machin
…
END COMPONENT
SIGNAL: ……….
SIGNAL: ……..
XX<=“1110”;
YY<= A AND B;
U1: Truc PORT MAP( …….);
S<= “10” when (A=B) else
“00”;
U2: Machin PORT MAP( …….);
With (Toto) select
G<= ……
END ARCHITECTURE
Squelette de
description
VHDL
Déclaration de
composants
créés
Utilisation
des
ressources
disponibles
30. 30
Logique combinatoire: Exemple
UTILISATION D’UNE TABLE (LUT) POUR DECRIRE LE SYSTEME
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
--definition de l'architecture
architecture arch_dec_7seg of decod7seg is
-- definition d'un nouveau type
-- tableau de 16 elements de 7 bits
type MemROM is array(15 downto 0) of
std_logic_vector(6 downto 0);
--initialisaion du tableau
-- tableau vu comme une memoire(LUT)
signal Tableau : MemROM := (
"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
OutSeg <= Tableau(conv_integer(InSeg));
end arch_dec_7seg;
entity decod7seg is
port(
InSeg : IN std_logic_vector(3 downto 0);
OutSeg : OUT std_logic_vector(6 downto 0)
);
end decod7seg;
Anode commune
Segment actif à ‘0’
Création de nouveaux
types: TYPE
Tableau: ARRAY
Décodeurs 7 segments ?
31. 31
Logique combinatoire: Exemple
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
--création de TEMP pour résultat: extension de 1 bit
signal TEMP : std_logic_vector(LARG downto 0);
begin
TEMP <= ('0'&A)+('0'&B)+Cin;
--A et B étendu chacun de 1 bit.
Res <= TEMP(TEMP'HIGH-1 downto 0);
Cout <= TEMP(TEMP'HIGH);
--TEMP'HIGH renvoi indice poids fort
end arch1_add4full;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity adddirect is
generic (LARG:integer:=4);
-- paramètre générique
-- taille additionneur changer en 1 clic!
port (
Cin : IN std_logic;
A : IN std_logic_vector(LARG-1 downto 0);
B : IN std_logic_vector(A'range);
Res : OUT std_logic_vector(A'range);
Cout : OUT std_logic
);
end adddirect;
Les attributs des signaux -Exemple S[5:0]
S’HIGH renvoie 5 et S’LOW renvoie 0
S’RANGE renvoie 5 downto 0
S’event renvoie TRUE si changement d’état de S
Utilisation de GENERIC lors du PORT MAP
U1: generic(10)
adddirect PORT MAP(xxxxxx);
32. 32
Logique combinatoire: Exemple
26 ----- Logic unit: -----------
27 WITH sel(2 DOWNTO 0) SELECT
28 logic <= NOT a WHEN "000",
29 NOT b WHEN "001",
30 a AND b WHEN "010",
31 a OR b WHEN "011",
32 a NAND b WHEN "100",
33 a NOR b WHEN "101",
34 a XOR b WHEN "110",
35 NOT (a XOR b) WHEN OTHERS;
36 -------- Mux: ---------------
37 WITH sel(3) SELECT
38 y <= arith WHEN '0',
39 logic WHEN OTHERS;
40 END dataflow;
Arithmetic Logic Unit (ALU)
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4 USE ieee.std_logic_unsigned.all;
5 ----------------------------------------------
6 ENTITY ALU IS
7 PORT (a, b : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
8 sel : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
9 cin : IN STD_LOGIC;
10 y : OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
11 END ALU;
12 ----------------------------------------------
sel Operation Function Unit
0 000 y <= a
y <= a+1
y <= a-1
y <= b
y <= b+1
y <= b-1
y <= a+b
y <= a+b+Cin
Transfert a
Incrément a
Décrément a
Transfert b
Incrément b
Décrément b
Add a et b
Add a et b avec Carry
Arithmetic
0 001
0 010
0 011
0 100
0 101
0 110
0 111
1 000 y <= NOT a
y <= NOT b
y <= a AND b
y <= a OR b
y <= a NAND b
y <= a NOR b
y <= a XOR b
y <= a XNOR b
Complément a
Complément b
AND
OR
NAND
NOR
XOR
XNOR
Logic
1 001
1 010
1 011
1 100
1 101
1 110
1 111
Code opératoire
Sélection Op Arithmétique/Logique
13 ARCHITECTURE dataflow OF ALU IS
14 SIGNAL arith, logic : STD_LOGIC_VECTOR (7 DOWNTO 0);
15 BEGIN
16 ----- Arithmetic unit: ------
17 WITH sel(2 DOWNTO 0) SELECT
18 arith <= a WHEN "000",
19 a+1 WHEN "001",
20 a-1 WHEN "010",
21 b WHEN "011",
22 b+1 WHEN "100",
b-1 WHEN "101",
24 a+b WHEN "110",
25 a+b+cin WHEN OTHERS;
33. 33
Logique combinatoire: Exemple
Buffers 3 états
LIBRARY ieee;
USE ieee.std_logic_1164.all;
----------------------------------------------
ENTITY tri_state IS
PORT (
ena : in std_logic;
input : in std_logic_vector (7 downto 0);
output : out std_logic_vector (7 downto 0)
);
END tri_state;
----------------------------------------------
ARCHITECTURE tri_state OF tri_state IS
BEGIN
output <= input WHEN (ena='0') ELSE
(OTHERS => 'Z');
END tri_state;
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!!
34. 34
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;
process
begin
q <= d;
wait until H = ‘1’;
end process;
Process
begin
c <= a and b;
wait on a, b;
end process;
Process(a,b)
begin
c <= a and b;
end process;
Écritures
alternatives
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
35. 35
Logique séquentielle: le process
Réveil du process
Exemple: bascule D latch
Fonctionnement sur niveau
Processus activé
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity seq1 IS
port ( d, ena : in std_logic;
q : buffer std_logic
);
end seq1;
architecture archi of seq1 is
begin
process (ena,d)
begin
IF ena = '1'
then q<=d;
else q<=q;
end if;
end process ;
end archi;
36. 36
Logique séquentielle: le process
Rendre synchrone
Bascule D edge: fonctionnement sur front
Autre façon:
process(CLK)
begin
If (H=‘1’) and (H’event) then
q<=d;
end if;
end process;
architecture arch of Bascule_D is
begin
process(H)
begin
if rising_edge(H) then
q<=d;
end if;
end process;
end arch;
library ieee;
Use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Bascule_D is
port (
H, d : in std_logic;
q : out std_logic
);
end entity;
37. 37
Logique séquentielle: le process
Ecriture correcte des process
Les compilateurs imposent une certaine rigidité dans la description des process
Les règles à respecter
process(horl)
if (horl’event and horl = ‘1’) then
if (ena = ‘ 1 ’) then
contenu_registre <= valeur_in;
end if;
end if;
end process;
Ce qu’il faut faire!
En pratique le FPGA (ou CPLD)
possède une ou des broches
spécifiques pour le signal
d’horloge
CLK
ASTABLE
GCLK
CPLD
38. 38
Logique séquentielle: le process
Penser à l’initialisation du systèmes
Signaux reset et set: comportement défini par l’utilisateur
LIBRARY ieee;
USE ieee.std_logic_1164.all;
---------------------------------------
ENTITY dff IS
PORT ( d, clk, rst: IN STD_LOGIC;
q : OUT STD_LOGIC);
END dff;
---------------------------------------
ARCHITECTURE behavior OF dff IS
BEGIN
PROCESS (rst, clk)
BEGIN
IF (rst=‘0') THEN
q <= '0';
ELSIF (clk'EVENT AND clk='1') THEN
q <= d;
END IF;
END PROCESS;
END behavior;
Reset ASYNCHRONE
process (CLK)
Begin
if (CLK'event and CLK ='1') then
if (RESET =’1’) then
S <= ‘0’;
elsif (SET =’1’) then -- actif à ‘1’
S <= ‘1’;
else
S <= D;
end if;
end if;
end process ;
Reset et Set SYNCHRONE
On remarquera que RST a disparu de la
liste de sensibilité
Comportement
asynchrone de
la bascule
RESET
ASTABLE
C
VCC
R
39. 39
Logique séquentielle: le process
Mise à jour des signaux à la fin du process
Exemple 1: bascule avec sortie complémentée
---- Solution 1: NE MARCHE PAS---------------
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4 ---------------------------------------
5 ENTITY dff IS
6 PORT ( d, clk: IN STD_LOGIC;
7 q: BUFFER STD_LOGIC;
8 qbar: OUT STD_LOGIC);
9 END dff;
10 ---------------------------------------
11 ARCHITECTURE not_ok OF dff IS
12 BEGIN
13 PROCESS (clk)
14 BEGIN
15 IF (clk'EVENT AND clk='1') THEN
16 q <= d;
17 qbar <= NOT q;
18 END IF;
19 END PROCESS;
20 END not_ok;
LIGNE 17: Si d a changé
q ne changera qu’à la
fin du process
---- Solution 2: OK -------------------
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4 ---------------------------------------
5 ENTITY dff IS
6 PORT ( d, clk: IN STD_LOGIC;
7 q: BUFFER STD_LOGIC;
8 qbar: OUT STD_LOGIC);
9 END dff;
10 ---------------------------------------
11 ARCHITECTURE ok OF dff IS
12 BEGIN
13 PROCESS (clk)
14 BEGIN
15 IF (clk'EVENT AND clk='1') THEN
16 q <= d;
17 END IF;
18 END PROCESS;
19 qbar <= NOT q;
20 END ok;
LIGNE 19: On décris une
relation COMBINATOIRE
=> On sors du PROCESS!!!
40. 40
Logique séquentielle: le process
Mise à jour des signaux
Cas des compteurs Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Use ieee.std_logic_unsigned.all;
entity CMP4BITSRET is
PORT (
RESET, CLOCK : in std_logic;
RET : out std_logic;
Q : out std_logic_vector (3 downto 0)
);
end CMP4BITSRET;
architecture DESCRIPTION of CMP4BITSRET is
signal CMP: std_logic_vector (3 downto 0);
begin
process (RESET,CLOCK)
begin
if RESET ='1' then
CMP <= "0000";
elsif (CLOCK ='1' and CLOCK'event) then
CMP <= CMP + 1;
if (CMP = "1111") then
RET <= '1';
else
RET <= '0';
end if;
end if;
end process;
Q <= CMP;
end DESCRIPTION;
1110+1=1111 oui mais à la fin du process
Conclusion: état 1111 et pas de retenue!
Prochain front: 1111+1=0 on détecte 1111 ,
l’ancienne valeur et RET passe à 1
Oui mais trop tard!!
41. 41
Logique séquentielle: le process
Des solutions
process (RESET,CLOCK)
begin
if RESET='1' then
CMP <= "0000";
elsif (CLOCK ='1' and
CLOCK'event) then
CMP <= CMP + 1;
end if;
end process;
-- Validation de la retenue
RET <= '1' when (CMP = "1111")
else '0‘;
process (RESET,CLOCK)
begin
if RESET ='1' then
CMP <= "0000";
elsif (CLOCK ='1' and
CLOCK'event) then
CMP <= CMP + 1;
if (CMP = "1110") then
–- La retenue passera à un
quand CMP = 14 décimal
RET <= '1';
else
RET <= '0';
end if;
end if;
end process;
Version complètement
synchrone:
On anticipe pour avoir un
résultat correct
On décris le
combinatoire
HORS
PROCESS
Solution 2
Solution 1
42. 42
Logique séquentielle: les instructions
Assignations directes
S<= signal; Library ieee;
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;
architecture DESCRIPTION of CMP4BITS is
signal Q_BUS_INTERNE : std_logic_vector(3 downto 0));
begin
process (CLOCK)
begin
if (CLOCK ='1' and CLOCK'event) then
Q_BUS_INTERNE <= Q_BUS_INTERNE + 1;
end if;
end process;
Q <= Q_BUS_INTERNE; -- affectation du bus interne au
-- signal de sortie Q
end DESCRIPTION;
Q est défini en sortie
OR Q<=Q+1 signifie
Relire état courant et incrémente
Solution 1: définir BUFFER au lieu de OUT
Solution 2: couramment utilisée: passer par
un signal
43. 43
Logique séquentielle: les instructions
Assignation conditionnelle
Structure SI/SINON SI
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Use ieee.std_logic_unsigned.all;
entity BASCULET is
port (
D,CLK : in std_logic;
S : buffer std_logic);
end BASCULET;
Bascule T
Compteur
de GRAY
T comme TOGGLE ( basculement). La
sortie change d’état à chaque front (
utilisation pour la synthèse des compteurs)
Code binaire réfléchi (codeur de
position par exemple)
architecture DESCRIPTION of BASCULET is
Begin
PRO_BASCULET : process (CLK)
Begin
if (CLK'event and CLK='1') then
if (D=’1’) then
S <= not (S);
end if;
end if;
end process PRO_BASCULET;
end DESCRIPTION;
COMPTEUR GRAY
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE work.std_arith.all;
entity GRAY is
port (H,R :in std_logic;
Q :out std_logic_vector(2 downto 0));
end GRAY;
architecture ARCH_GRAY of GRAY is
signal X :std_logic_vector(2 downto 0);
begin
process(H,R)
begin
if R='1' then X <= "000";
elsif (H'event and H='1') then
if X = "000" then X <= "001";
elsif X = "001" then X <= "011";
elsif X = "011" then X <= "010";
elsif X = "010" then X <= "110";
elsif X = "110" then X <= "111";
elsif X = "111" then X <= "101";
elsif X = "101" then X <= "100";
elsif X = "100" then X <= "000";
end if;
end if;
end process;
Q <= X;
end ARCH_GRAY;
44. 44
Logique séquentielle: les instructions
Assignation conditionnelle
Structure CASE/IS
Utile pour décrire des grafcets, machine d’états
CAS possibles de l’expression EST
LORSQUE signal = valeur1 => instructions
séquentielles;
LORSQUE signal = valeur2 =>instructions
séquentielles;
LORSQUE signal = valeur3 =>instructions
séquentielles;
LORSQUE signal = AUTRES =>instructions
séquentielles;
FIN DE CAS;
Syntaxe:
Case selecteur is
when condition1 => instructions ;
…….
when condition2 => instructions ;
----
when others => instructions ;
end case ;
45. 45
Logique séquentielle: les instructions
Exemple de CASE/IS
Description d’un registre à décalage
Reg_dec: PROCESS (h)
VARIABLE stmp: std_logic_vector(3 DOWNTO 0);
BEGIN
If (h=‘1’ and h’event) then
CASE selection IS
--chargement parallèle
WHEN ”11”=> stmp := d_entree;
-- --Décalage à gauche
WHEN ”10”=>stmp:= stmp(2 DOWNTO 0) & edg;
-- Décalage à droite
WHEN ”01”=>stmp:= edd &stmp(3 DOWNTO 1);
--mémorisation
WHEN OTHERS => stmp:= stmp;
END CASE;
sortie <= stmp;
End if;
END PROCESS Reg_dec;
Schéma de principe d’un registre à décalage SIMPLE
registre à décalage à droite ou à gauche
On peut utiliser une variable à la
place d’un signal
Afféctation d’une variable
Syntaxe Mavariable:= ma valeur;
Contrairement au signal la valeur est
mise à jour de suite
la sortie est SYNCHRONE
Pas de retard supplémentaire car utilisation
d’une variable
Si emploi d’un signal à la place d’une
variable affectation EN DEHORS DU
PROCESS ( voir chapitre Mise à jour des
signaux et page suivante pour un exemple)
0
3 2 1
2 1 0 ed
0 1 0 0
1 0 0 1 ed = 1
Exemple
Nouvelle Valeur
&
46. 46
Logique séquentielle: des exemples
Registre à décalage simple
Sortie série ( 1 seule sortie)
2 LIBRARY ieee;
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 );
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;
47. 47
Logique séquentielle: des exemples
Registre à décalage
Sortie parallèle
Choix du sens
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE work.std_arith.all;
entity DECAL_DG is
port (H,R,SENS : in std_logic;
IN_OUT,OUT_IN : inout std_logic;
sortie : out std_logic_vector(3 downto 0)
);
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";
elsif (H'event and H='1') then
if SENS = '1' then
Q <= Q(2 downto 0) & OUT_IN;
else
Q <= IN_OUT & Q(3 downto 1);
end if;
end if;
end process;
OUT_IN <= Q(3) when SENS = '1' else 'Z';
IN_OUT <= Q(0) when SENS = '0' else 'Z';
sortie <= Q;
end ARCH_DECAL_DG;
Emploi de signaux et non de
variables
Affectation en dehors du process
48. 48
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));
END ram;
---------------------------------------------------
ARCHITECTURE ram OF ram IS
TYPE vector_array IS ARRAY (0 TO words-1) OF STD_LOGIC_VECTOR (bits-1 DOWNTO 0);
SIGNAL memory: vector_array; -- Déclaration d’un signal du type créé précédemment
BEGIN
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);
END ram;
Création d’un nouveau
type: TYPE
C’est un tableau de vecteurs
49. 49
Logique séquentielle: des exemples
Diviseur de fréquence
Diviseur par comptable
Possibilité de faire par décomptage aussi
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_arith.all;
entity DIV_FREQ1 is
port (H :in std_logic;
N :in std_logic_vector(3 downto 0);
DIV : out std_logic);
end DIV_FREQ1;
architecture ARCH_DIV_FREQ1 of DIV_FREQ1 is
signal Q :std_logic_vector(3 downto 0);
begin
process(H)
begin
if (H'event and H='1') then
if Q = 15 then Q <= N;
else Q <= Q + 1;
end if;
end if;
end process;
DIV <= '1' when Q = 15 else '0';
end ARCH_DIV_FREQ1;
Application et utilisation d’un diviseur de
fréquence
•On évitera de cascader la sortie du diviseur
sur l’horloge du bloc suivant
•La bonne méthode:
Horloge du système la même pour
tous les blocs
La sortie du diviseur est une entrée de
validation du bloc suivant
Si En=‘1’ alors on compte
50. 50
Logique séquentielle: des exemples
Application et utilisation d’un diviseur de fréquence
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
entity COMPTCAS is
port (H,R,EN :in std_logic;
CO :out std_logic;
Q :out std_logic_vector(3
downto 0));
end COMPTCAS;
architecture ARCH_COMPTCAS of
COMPTCAS is
signal X :std_logic_vector(3 downto
0);
begin
process(H,R)
begin
if R='1' then X <= "0000";
elsif (H'event and H='1') then
if EN = '1' then X <= X + 1;
else X <= X;
end if;
end if;
end process;
Q <= X;
CO <= '1' when X = 15 else '0';
end ARCH_COMPTCAS;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
entity COMPT12 is
port (H,RAZ,EN : in std_logic;
CO : out std_logic;
Q :out std_logic_vector(11 downto 0));
end COMPT12;
architecture ARCH_COMPT12 of COMPT12 is
signal X :std_logic_vector(11 downto 0);
signal CO1,CO2,CO3,EN1 :std_logic;
component COMPTCAS
port (H,R,EN : in std_logic;
CO : out std_logic;
Q : out std_logic_vector(3 downto 0));
end component;
begin
COMPTEUR1 : COMPTCAS port map(H,RAZ,EN,CO1,Q(3 downto 0));
COMPTEUR2 : COMPTCAS port map(H,RAZ,CO1,CO2,Q(7 downto 4));
EN1 <= CO1 and CO2;
COMPTEUR3 : COMPTCAS port map(H,RAZ,EN1,CO3,Q(11 downto 8));
CO <= CO1 and CO2 and CO3;
end ARCH_COMPT12;
COMPOSANT HAUT NIVEAU
51. 51
Logique séquentielle: des exemples
Détection d’un front
Détection d’un changement d’état d’un signal
Contrainte: DESCRIPTION SYNCHRONE
Detection: PROCESS
VARIABLE detect : std_logic_vector(1 DOWNTO 0);
BEGIN
WAIT UNTIL rising_edge (clk); -- c'est donc synchrone de clk
front_montant <= '0';
front_descendant <= '0' ;
detect(1) := detect(0);
detect(0) := signal_lent;
IF detect = "01" THEN
front_montant <= '1';
END IF;
IF detect = "10" THEN
front_descendant <= '1';
END IF;
END PROCESS;
Rappel:
la variable prend sa valeur instantanément
Le signal prend sa valeur à la sortie du process
Équivalent à
Process(clk)
If (clk=‘1’ and clk’event)