COURS VHDL PROGRAMMATION ET _ETAPES pour comprendre

MariamHafsa 507 views 51 slides Mar 08, 2024
Slide 1
Slide 1 of 51
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51

About This Presentation

programmation vhdl


Slide Content

Elément1:Circuits FPGA et Langage VHDL
FPGA : Field Programmable GridArray
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
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
Connexions programmables
Introduction
Deux formes canoniques pour les équations logiques
Somme de produits S=a.b+ c.d
Produits de sommeS=(z+f).(e +x)
ETcablé
OUcablé
Connexions programmables
Représentation standard
Constitution d’un réseau programmable

4
Simple Programme LogicDevice
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
Field Programmable GridArray
Granularitéplus fine que les CPLD ( macrocellules-complexes mais + nombreuses)
Exemple de référence
Famille Cyclone(FPGA
LowCostd’ALTERA)
Concurrent: Spartan3(chez
Xilinx)
Répartition des applicationsSource 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)

REFERENCES DES CIRCUITS LOGIQUES PROGRAMMABLES
6
Ex: PAL 16 L 8
Références des PALs
Références des FPGAs

7
Cyclone III EDA/SOPC System PlatformKit de Développement :

8
CPU boardstructure
●Use resistancecontrolling12 layer high precisionPCB boardto makesure the frequencyof the
signal on boardup to 200MHz
●Use Cyclone III EP3C40F780C8(option Cyclone III EP3C80,EP3C120' option C7 C6 speed level)
●EPCS16 AS mode configuration, combining100M internet'supportCycloneIIIspecialremote
system upgrade function
●Standard 32M DDR2 memory. Highestexecutivefrequency166.667MHZ (option C6 speed level
is200MHZ)
●1MB(256K×32)SRAM
●8MB NOR Flash-ROM
●64MB NAND Flash-ROM
●USB-BlasterRev.Con board
●Mini USB2.0 deviceinterface
FPGA : EP3C40F780C8

9
System board:
●Support CycloneII,CycloneIIIseriescoreboard
●800×600 large resolutionfull colorLCD and 4 line resistancetouchtype screen
●1 4-phase stepmotor
●1 adjustablespeed,measurablecurrentstepmotor
●1 canonical sequenceinterface
●2 PS2 interface
●1 USB deviceinterface
●1 USB host interface
●1 Ethernet network interface
●1 16×16 point arrayLED
●1 4×4 key array
●8 bits dynamic7-segment LED
●USB-BlasterRev.Con board
●Mini USB2.0 deviceinterface
●RS232 standard seriesport
●High speed SD cardinterface
●50MHz system clockon board
●4 LED user setting
●4 key user setting
●1 7-segment LED
●1 reset key
●1 extendedinterface
●AS program designinginterface and JTAG interface

10
●12 LED user setting
●12 key user setting
●12 key input user setting
●Liquiddrivingmodule on board
●1 SD cardinterface
●Touchcontrol screencontroller
●2 extension interface
●1 digital clocksource, supplymore clock
●Audio Codec:1 audio input interface'1 Micinput interface'1 audio output interface and 1
●earphoneinterface
●1 analogysignal source'supplyfrequency,amplitudeadjustablesine wave,squarewave,triangular
waveand sawtoothwave
Extended interface of the system board1 : (Standard)
●8 bits double channelparallelAD module samplingfrequency28MSPS
●12 bits high-speed parallelDA module samplingfrequency30MSPS
●12 bits high-speed seriesAD/DA module
●1 videocoding、decodingmodule
●1 full colorVGA module
●1 infraredreceivesendmodule
●1 real-time clockRTC module
●1 I2C EEPROM module
●1 digital temperaturesensormodule
●1 high-speed extendedmodule
●6 high-speed signal measurablechannel

11
Software Experiments
EDA experimentand electronicsdesign competition
content:
●7 men votingmachine
●Gray code conversion…
●BCD code adder
●4 men quiz buzzer
●4 bits parallelmultiplier
●Design basic trigger
●Variable stepsize add-subtractcounter
●Controlledpulse generator
●Plus-minus pulse widthmodulation signal generator
●Sequencedetector
●Taxi fareregister
●Multifunctionaldigital clock
●Music memory player
●Digital stopwatch
●Frequencymeter
●Trafficlight controller
●Codedlock
●VGA colorbar generatorand image display controllerdesign

12
NIOSII32 bits processor demoexperiment
●Hello experiment
●DIP seitch、keyand LED experiment
●Key scan & 8 bits 7 segment display experiment
●Motorvelocitymeasurement
●Timerexperiment
●Sequenceport communication experiment
●SPI interface audio Codec experiment
●High-speed AD and high-speed DA experiment
●SRAM&DMA experiment
●Flash ROM operationexperiment
●Image point arrayLCD display experiment
●USB communication experiment(IncludeUSB controller)
●Ethernet communication experiment(includeEthernet controller)
●Audio CODEC experiment
●PS2 key experiment
●Infraredcommunication experiment
●Wiredigital temperaturemeterexperiment
DSP BuilderDesign application demoexperiment
●FromDSP Builderto HDL——Basedon DSP Buildersignal generator
●FromDSP Builderto SOPC Builder——Software controlledChirpsignal generator
●IP coreisusedin DSP Builder——TakeFFT corefor example

13
Comprehensivedevelopmentexperiment
●SD cardreadingand writingexperiment
●CF cardreadingand writingexperiment
●Design direct currentmotorclosedloopspeed adjustment
●Easydigital oscilloscope design
●Easyfrequencyanalysisdesign
●USB interface file readerdesign
●Videocollection display design
●ColorLCD principleand plottingapplication experiment
●Basedon MP3 multimediaplayerdesign(optionMP3 extendedboard)
●Basedon RFID design(optionRFID extendedboard)
●Basedon NIOSII calculatordesign experiment
●Basedon NIOSII Belly-worshipsnakedesign experiment

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

1515
Structure générale
Lefichier texte de description: xxx.vhd
Le mode transfert des
signaux de l’entity
VHDL: Concepts de base
Déclaration des Bibliothèques
Commentaires en VHDL commencent par --
Déclaration de l’entité de Démultiplexeur
Déclaration de l’architecture
de Démultiplexeur

16
Un outils de développement: QuartusII 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
Ilconvertitenfonctionducircuitcible
(CPLDouFPGA:suivantlemodèle
choisi)leprojetenporteslogiqueset
basculesdebases.
Deplus,onpeutluispécifierdes
contraintestechnologiquestelquela
vitessedefonctionnement
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
Méthodologiede conception
Guide pratique du débutant
Décomposition du cahier des charges en fonctions élémentaires
Classification de la fonction
Logique combinatoire
La sortie nedépend pasde 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épendde 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
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 papierA B S ET2 A B S ET2 A B S ET2 Fil1 Fil2 X1 X2 X3 X4 Y ET4

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ès9 on a0 avec 1 de retenue! Donc Affichage 10
Ce fil est interne aucomposant :
on le déclarera
SIGNAL FILS: bit_vector(3 downto0);
Sorties pilotant les Leds
de l’afficheur 2
Séquentiel donc process
COMPT:PROCESS(CLK)
Begin
….
END PROCESS;

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_logicet 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_vectoret 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 aussiUSE IEEE.std_logic_arith.all;

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.allet
IEEE.std_logic_arith.allsontdes
anciennesbibliothèques
Ne pas mettre en même temps:
IEEE.numeric_std.all;
IEEE.std_logic_arith.all;
Préfèrezl’emploide
IEEE.numeric_std.all;
Complément sur les opérations arithmétiques
Le rajout de use IEEE.numeric_std.all; permet
De travailleravec des valeurssignéeset non signées
•signal A,B: signed(3 downto0);
•signal tempo: unsigned(3 downto0);
De convertir un std_logic_vectoren signedou unsigned
•A<= signed(SW(3 downto0));
•B<=unsigned(RES);
De convertirdes signedou unsigneden std_logic_vector
•LEDG(3 downto0)<=std_logic_vector(tempo);
De redimensionner des vecteurs
•Permet d’étendre le bit de signe correctement!
•signal A,B: signed(LARG downto0);
A<= resize(signed(SW(LARG downto1)),LARG+1);
De travailler avec les opérateurs arithmétiques standart
•>, >=, =<,<, + ,-etc….
Pour recopierle bit de poidsfort:
A<= A(3)&A
A savoir

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
Assignation simples
libraryIEEE;
use IEEE.std_logic_1164.all;
--librairie pour inclure type std_logic
--portes ET
--3 entrées E2 E1 E0
--1 sortie S0
entityET3 is
port (
E : IN std_logic_vector(2 downto0);
S : OUT std_logic
);
end ET3;
--definitionde 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;
libraryIEEE;
use IEEE.std_logic_1164.all;
entityexemple is
port (
E : IN std_logic_vector(2 downto0);
S1 : OUT std_logic; --1 fil
S2,S3 : OUT std_logic_vector(3 downto1); --3 fils S1[3:1]
S4 : OUT std_logic_vector(2 downto0)
);
end exemple;
--définition de l'architecture
architecture arch_exempleof exemple is
begin
S1 <= '0';
S2 <= '1‘ & E(1 downto0);
--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
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 downto0);
y: out std_logic_vector(1 downto0));
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 whenexpresion_boolénneelse
………
signal_nwhenexpresion_boolénneelse
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
Logique combinatoire: Instructions concurrentes
withexpressionselect
signal <=signal1whenvaleur 1,
signal2 whenvaleur2,
------
signalNpar défaut whenothers;
Le multiplexeur: on aiguille une
enréevers 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 downto0);
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 downto0)
S <= E(0) when "00",
E(1) when "01",
E(2) when "10",
E(3) when "11";
Assignation sélective
Structure WITH/SELECTE0 E1 E2 E3 S C1 C0

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ééspour structurer leprojet
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érencantsur 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 xorY xorCi;
Cout<= (X and Y) or (X and Ci) or (Y and Ci);
end arch_add1full;
Full Adder
etape1: On crée un composant ADDITIONNEUR 1 bits

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 aditionneurscomplets
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;
libraryIEEE;
use IEEE.std_logic_1164.all;
entityadd4full is
port(
Cin: IN std_logic;
A : IN std_logic_vector(3 downto0);
B : IN std_logic_vector(3 downto0);
Res: OUT std_logic_vector(3 downto0);
Cout : OUT std_logic
);
end add4full;
étape3: On structure mon niveau supérieur ( comment faire 4 bits avec 1 bit?)

28
Logique combinatoire: Concepts de bases
libraryIEEE;
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;
libraryIEEE;
use IEEE.std_logic_1164.all;
ENTITY ET4 IS
PORT ( X1,X2,X3,X4 : INSTD_LOGIC;
Y : OUTSTD_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
SIGNALFIL1,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;
Oncommence par faire ET2
Deuxfichiers ET2 et ET4 .vhdavec
chacun une entity+une architecture
Les fils de
connexions
INTERNES
PORT
MAPpour
placement
et
connexion
Comment créer une ET4

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: TrucPORT MAP( …….);
S<= “10” when (A=B) else
“00”;
U2: MachinPORT MAP( …….);
With (Toto) select
G<= ……
END ARCHITECTURE
Squelette de
description
VHDL
Déclaration de
composants
créés
Utilisation
des
ressources
disponibles

30
Logique combinatoire: Exemple
UTILISATION D’UNE TABLE (LUT) POUR DECRIRE LE SYSTEME
libraryIEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
--definitionde l'architecture
architecture arch_dec_7seg of decod7seg is
--definitiond'un nouveau type
--tableau de 16 elementsde 7 bits
type MemROMisarray(15 downto0) of
std_logic_vector(6 downto0);
--initialisaiondu 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_integerdans
IEEE.std_logic_unsigned.all
OutSeg<= Tableau(conv_integer(InSeg));
end arch_dec_7seg;
entitydecod7seg is
port(
InSeg: IN std_logic_vector(3 downto0);
OutSeg: OUT std_logic_vector(6 downto0)
);
end decod7seg;
Anode commune
Segment actif à ‘0’
Création de nouveaux
types: TYPE
Tableau:ARRAY
Décodeurs 7 segments ?

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éearchitecture arch1_add4full of adddirectis
--création de TEMP pour résultat: extension de 1 bit
signal TEMP : std_logic_vector(LARG downto0);
begin
TEMP <= ('0'&A)+('0'&B)+Cin;
--A et B étendu chacun de 1 bit.
Res<= TEMP(TEMP'HIGH-1 downto0);
Cout <= TEMP(TEMP'HIGH);
--TEMP'HIGH renvoi indice poids fort
end arch1_add4full;
libraryIEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entityadddirectis
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 downto0);
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 downto0
S’eventrenvoie TRUE si changement d’état de S
Utilisation de GENERIC lors du PORT MAP
U1: generic(10)
adddirectPORT MAP(xxxxxx);

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 <= arithWHEN '0',
39 logic WHEN OTHERS;
40 END dataflow;
ArithmeticLogicUnit (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
0000 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
Adda et b
Adda et b avec Carry
Arithmetic
0001
0010
0011
0100
0101
0110
0111
1000 y <= NOT a
y <= NOT b
y <= a AND b
y <= aOR 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
1001
1010
1011
1100
1101
1110
1111
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+cinWHEN OTHERS;

33
Logique combinatoire: Exemple
Buffers 3 états
LIBRARY ieee;
USE ieee.std_logic_1164.all;
----------------------------------------------
ENTITY tri_stateIS
PORT (
ena: in std_logic;
input : in std_logic_vector(7 downto0);
output : out std_logic_vector(7 downto0)
);
END tri_state;
----------------------------------------------
ARCHITECTURE tri_stateOF tri_stateIS
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
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 processMonEtiquette;
process
begin
q <= d;
waituntilH= ‘1’;
end process;
Process
begin
c <= a and b;
waiton 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/elsepar exemple)
Les signaux sont mis àjour uniquement àla fin du process

35
Logique séquentielle: le process
Réveil du process
Exemple: bascule D latch
Fonctionnement sur niveau
Processus activé
libraryieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entityseq1 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'
thenq<=d;
elseq<=q;
end if;
end process;
end archi;

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;
endprocess;
architecture archof Bascule_Dis
begin
process(H)
begin
if rising_edge(H) then
q<=d;
end if;
end process;
end arch;
libraryieee;
Use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entityBascule_Dis
port (
H, d : in std_logic;
q : out std_logic
);
end entity;

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’eventand 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’horlogeCLK
ASTABLE GCLK
CPLD

38
Logique séquentielle: le process
Penser à l’initialisation du systèmes
Signaux resetet set: comportement défini par l’utilisateur
LIBRARY ieee;
USE ieee.std_logic_1164.all;
---------------------------------------
ENTITY dffIS
PORT ( d, clk, rst: IN STD_LOGIC;
q : OUT STD_LOGIC);
END dff;
---------------------------------------
ARCHITECTURE behaviorOF dffIS
BEGIN
PROCESS (rst, clk)
BEGIN
IF (rst=‘0') THEN
q <= '0';
ELSIF (clk'EVENTAND clk='1') THEN
q <= d;
END IF;
END PROCESS;
END behavior;
Reset ASYNCHRONE
process (CLK)
Begin
if (CLK'eventand 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 basculeRESET
ASTABLE C VCC R

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 dffIS
6 PORT ( d, clk: IN STD_LOGIC;
7 q: BUFFER STD_LOGIC;
8 qbar: OUT STD_LOGIC);
9 END dff;
10 ---------------------------------------
11 ARCHITECTURE not_okOF dffIS
12 BEGIN
13 PROCESS (clk)
14 BEGIN
15 IF (clk'EVENTAND 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 dffIS
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 dffIS
12 BEGIN
13 PROCESS (clk)
14 BEGIN
15 IF (clk'EVENTAND clk='1') THEN
16 q <= d;
17 END IF;
18 END PROCESS;
19 qbar<= NOT q;
20 END ok;
LIGNE 19: Ondécris une
relation COMBINATOIRE
=> Onsors du PROCESS!!!

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 downto0)
);
end CMP4BITSRET;
architecture DESCRIPTION of CMP4BITSRET is
signal CMP: std_logic_vector(3 downto0);
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
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
Ondécris le
combinatoire
HORS
PROCESS
Solution 2
Solution 1

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 downto0)
);
end CMP4BITS;
architecture DESCRIPTION of CMP4BITS is
signal Q_BUS_INTERNE : std_logic_vector(3 downto0));
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
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'eventand 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 downto0));
end GRAY;
architecture ARCH_GRAY of GRAY is
signal X :std_logic_vector(2 downto0);
begin
process(H,R)
begin
if R='1' then X <= "000";
elsif(H'eventand H='1') then
if X = "000" then X <= "001";
elsifX = "001" then X <= "011";
elsifX = "011" then X <= "010";
elsifX = "010" then X <= "110";
elsifX = "110" then X <= "111";
elsifX = "111" then X <= "101";
elsifX = "101" then X <= "100";
elsifX = "100" then X <= "000";
end if;
end if;
end process;
Q <= X;
end ARCH_GRAY;

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 selecteuris
whencondition1 => instructions ;
…….
whencondition2 => instructions ;
----
whenothers=> instructions ;
end case;

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 selectionIS
--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éctationd’une variable
SyntaxeMavariable:= ma valeur;
Contrairementau 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
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 shiftregIS
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 behaviorOF shiftregIS
12 signalinternal: std_logic_vector(n-1 downto0);
13 begin
14 process(clk, rst)
15 begin
16 if(rst='1') then
17 internal <= (others=> '0');
18 elsif(clk‘eventandclk='1') then
19 internal <= d & internal(internal‘leftdownto1);
20 End if;
21 endprocess;
22 q <= internal(0);
23 END behavior;

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 : inoutstd_logic;
sortie: out std_logic_vector(3 downto0)
);
end DECAL_DG;
architecture ARCH_DECAL_DG of DECAL_DG is
signal Q :std_logic_vector(3 downto0);
begin
process(H,R)
begin
if R='1' then Q <= "0000";
elsif(H'eventand H='1') then
if SENS = '1' then
Q <= Q(2 downto0) & OUT_IN;
else
Q <= IN_OUT & Q(3 downto1);
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
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_arrayIS 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'EVENTAND 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
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 downto0);
DIV : out std_logic);
end DIV_FREQ1;
architecture ARCH_DIV_FREQ1 of DIV_FREQ1 is
signal Q :std_logic_vector(3 downto0);
begin
process(H)
begin
if (H'eventand 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;
Applicationetutilisationd’undiviseurde
fréquence
•Onéviteradecascaderlasortiedudiviseur
surl’horlogedublocsuivant
•Labonneméthode:
Horlogedusystèmelamêmepour
touslesblocs
Lasortiedudiviseurestuneentréede
validationdublocsuivant
SiEn=‘1’alorsoncompte

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;
entityCOMPTCAS is
port (H,R,EN :in std_logic;
CO :out std_logic;
Q :out std_logic_vector(3
downto0));
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'eventand 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 downto0));
end COMPT12;
architecture ARCH_COMPT12 of COMPT12 is
signal X :std_logic_vector(11 downto0);
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 downto0));
end component;
begin
COMPTEUR1 : COMPTCAS port map(H,RAZ,EN,CO1,Q(3 downto0));
COMPTEUR2 : COMPTCAS port map(H,RAZ,CO1,CO2,Q(7 downto4));
EN1 <= CO1 and CO2;
COMPTEUR3 : COMPTCAS port map(H,RAZ,EN1,CO3,Q(11 downto8));
CO <= CO1 and CO2 and CO3;
end ARCH_COMPT12;
COMPOSANT HAUT NIVEAU

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'estdoncsynchronede 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)
Tags