Vous êtes sur la page 1sur 51

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

Elément1 : Circuits FPGA et Langage VHDL


FPGA : Field Programmable Grid Array
V : VHSIC (Very High Speed Integrated Circuit)
H : Hardware
D : Description
L : Language

Animé par le professeur:


Mohammed NAHID
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 Montage du circuit Programmation Programmation
non programmé sur site éventuelle
 Capacité de programmation In-Situ
• composants dits ISP via interface JTAG
 Contexte de compétitivité mondiale
 Importance du Time-To-Market

 Un système électronique
numérique peut être Circuit Numérique
implémenté avec des
STANDARD (Conçu et SPECIFIQUE
circuits logiques de Réalisé par le Fabricant) à l'Application
divers types : Séquentiables
Configurables (Full Custom)
Une fonction (Semi Custom)
par circuit
MicroProcesseurs
PLA, PAL, EPLD MicroControleurs
à Mémoire ou CPLD, FPGA DSP

Spécialisés
RAM, ROM Mixtes : FPGA + Micro + RAM

Périphériques
PLDs standard, ASICs 2
SOC(System On Chip)
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é

Constitution d’un réseau programmable

3
xPLD

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

4
FPGA

Field Programmable Grid Array


 Granularité plus fine que les CPLD ( macrocellules - complexes mais + nombreuses)
 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)
Répartition des applications Source Altera

Exemple de référence
Famille Cyclone (FPGA
Low Cost d’ALTERA)
Concurrent: Spartan3 (chez 5
Xilinx)
REFERENCES DES CIRCUITS LOGIQUES PROGRAMMABLES

 Références des PALs


Ex: PAL 16 L 8

 Références des FPGAs

6
Kit de Développement : Cyclone III EDA/SOPC System Platform

7
FPGA : EP3C40F780C8

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)
●EPCS16 AS 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
8
●Mini USB2.0 device interface
●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
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
9
●8 bits dynamic 7-segment LED
●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 series AD/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
10
●6 high-speed signal measurable channel
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

11
 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-speed AD 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 12
 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

13
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

Les deux portes


Synthèse ou modélisation travaillent en //

14
VHDL: Concepts de base
Le fichier texte de description: xxx.vhd

Structure générale Déclaration des Bibliothèques

Commentaires en VHDL commencent par --

Déclaration de l’entité de Démultiplexeur


Le mode transfert des
signaux de l’entity

Déclaration de l’architecture
15
de Démultiplexeur
Flot de conception
Un outils de développement: Quartus II d’Altera
Entrée schématique Entrée syntaxique Diagrammes d’états
Langages :VHDL
VHDL VHDL VHDL
Vérification des erreurs de Simulation
schémas et de syntaxe STIMULI ou
comportementale
VHDL TESTBENCH
SYNTHETISEURS CONNUS: SYNTHETISEUR
- FPGA Express (Synosys) Il convertit en fonction du circuit cible
-EXEMPLAR (ExemplAr) (CPLD ou FPGA: suivant le modèle
VITAL, VHDL
choisi) le projet en portes logiques et Simulation Après
-SYNPLICITY (Synplicity)
bascules de bases. synthèse
STIMULI ou
De plus, on peut lui spécifier des
contraintes technologiques tel que la TESTBENCH
vitesse de fonctionnement
EDIF, XNF
Outils de Placement et Routage au circuit interne: Optimisation VITAL, VHDL, SDF
Simulation
Chaque outil est propre à chaque fabricant Placement/Routage
temporelle
dans circuit choisi STIMULI ou
JEDEC TESTBENCH
La programmation du circuit se fait soit
-En utilisant un Programmateur CIRCUIT
CPLD
-En téléchargeant le code JEDEC directement FPGA 16
sur l’objet technique (JTAG ou ISP)
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 processus (PROCESS)

Logique combinatoire Logique séquentielle

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 Système nécessitant une horloge (systèmes


unique dits synchrones)

Des exemples: Des exemples:

• Multiplexeurs • Compteurs

• Additionneurs • Registres à décalage

• Décodeur 7 segments • Machine d’état (automate)

• Encodeurs de priorité 17
VHDL: Concepts de base
Les questions à se poser
 On identifie les fonctions et on les dessine sur papier
 On repère et on 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étisé par les lignes de codes directement
Exemple: faire une porte ET4 entrée avec des ET2 entrées

X1 A
Il faut un SIGNAL
ET2 S
X2 B
Fil1 On créera 1 composant ET2
A
ET2 S (entity+architecture) Utilisé 3
B
Y fois pour décrire ET4
X3 A Fil2
ET2 S
X4 B ET4 ET4 est un composant
(entity+architecture) 18
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
CLK H U1 Q In U3 Out SIGNAL FILS: bit_vector(3 downto 0);
Fil1[3..0] Décodeur
Compteur Seg1[6..0]
7 Segments
En R

H U2 Q In U4 Out
Décodeur Seg2[6..0]
Compteur Fil2[3..0] 7 Segments
R
Sorties pilotant les Leds
En
de l’afficheur 2

Séquentiel donc process


COMPT: PROCESS(CLK)
Begin
….
19
END PROCESS;
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 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

 Pour utiliser des fonctions arithmétiques sur ces STD_LOGIC_VECTOR


 USE IEEE.NUMERIC_STD.all;
 Et aussi USE IEEE.std_logic_arith.all;

Exemples • Q<=Q+1; -- Q étant par exemple un std_logic_vector et 1 est un entier!!


Applicatifs • A<B -- A et B des std_logic_vector
• Data<=CONV_STD_LOGIC_VECTOR(TEMP,8); avec TEMP integer range 0 to 255;
20
VHDL: Concepts de base
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); A savoir
• signal tempo: unsigned(3 downto 0);
IEEE.std_logic_unsigned.all et
 De convertir un std_logic_vector en signed ou unsigned IEEE.std_logic_arith.all sont des
anciennes bibliothèques
• A<= signed(SW(3 downto 0));
• B<=unsigned(RES);
Ne pas mettre en même temps:
 De convertir des signed ou unsigned en std_logic_vector
• LEDG(3 downto 0)<=std_logic_vector(tempo); IEEE.numeric_std.all;
IEEE.std_logic_arith.all;
 De redimensionner des vecteurs
• Permet d’étendre le bit de signe correctement!
• signal A,B: signed(LARG downto 0); Préfèrez l’emploi de
A<= resize(signed(SW(LARG downto 1)),LARG+1); IEEE.numeric_std.all;

 De travailler avec les opérateurs arithmétiques standart


• >, >=, =<,<, + ,- etc….
Pour recopier le bit de poids fort:
 Le rajout de use IEEE.std_logic_unsigned.all; permet A<= A(3)&A
 De travailler avec les opérateurs arithmétiques standart
 de mélanger des entiers avec des std_logic_vector: A<= A +1;
21
VHDL: Concepts de base

Littéraux Ne pas confondre 1 bit


 Caractères: ’0’, ’x’,’a’,’%’ ‘0’ ou ‘1’
 Chaînes: ”11110101”,”xx”,”bonjour”,”$@&”
Avec un vecteur de bits
 Chaînes de bits: B”0010_1101”, X”2D”, O”055”
” 11 ” ou ” 1101110 ”
(Notation pour les vecteurs de bits dans différentes bases)
 Décimaux:27, -5, 4e3, 76_562, 4.25 Un bus (ou ensemble de
 Basés: 2#1001#, 8#65_07, 16#C5#e2 fils électrique) est
(Notation pour les valeurs entières dans différentes bases) représenté sous forme
d’un vecteur de bits
Les opérateurs
 Logiques (boolean, bit, std_ulogic): X[3..0]
 AND, OR, NAND, NOR, XOR,XNOR, NOT
 Relationnels ( retournent un boolean): Y[1..0]
 =, /=, <, <=, >, >= Encodeur
 Arithmétiques:
 +, -, *, /, **, MOD, REM, ABS
 Concaténations d’éléments de tableaux &: STD_LOGIC_VECTOR (3 DOWNTO 0);

 "bon" & "jour" => "bonjour" 22


Logique combinatoire: Instructions concurrentes
Assignation simples
Exemple 1 Exemple 2
library IEEE; library IEEE;
use IEEE.std_logic_1164.all; use IEEE.std_logic_1164.all;
--librairie pour inclure type std_logic
entity exemple is
--portes ET port (
--3 entrées E2 E1 E0 E : IN std_logic_vector(2 downto 0);
-- 1 sortie S0 S1 : OUT std_logic; --1 fil
entity ET3 is
Bit Poids fort
S2,S3 : OUT std_logic_vector(3 downto 1); --3 fils S1[3:1]
port ( S4 : OUT std_logic_vector(2 downto 0)
E : IN std_logic_vector (2 downto 0); );
S : OUT std_logic end exemple;
);
end ET3; Bit Poids faible --définition de l'architecture
architecture arch_exemple of exemple is
--definition de l'architecture begin
architecture arch_ET3 of ET3 is S1 <= '0';
Begin S2 <= '1‘ & E(1 downto 0);
-- operateur COLLER (ou CONCATENE) &
S<=E(2) and E(1) and E(0);
-- E(2) accès au fil 2 -- S2(3) S2(2) S2(1)
end arch_ET3; -- '1' E(1) E(0)
S3 <= "101";
S4 <= "111" XOR E; --manip sur les bus directement
end arch_exemple;
23
Logique combinatoire: Instructions concurrentes
Assignation conditionnelle signal <= signal_1 when expresion_boolénne else
 Structure WHEN/ELSE ………
signal_n when expresion_boolénne else
signal par défaut;
---- Solution 1: WHEN/ELSE------
LIBRARY ieee;
use ieee.std_logic_1164.all; VCC X[0] X[3..0]
entity encoder is X[1]
port ( x: in std_logic_vector (3 downto 0); Y[1..0]
X[2]
y: out std_logic_vector (1 downto 0)); Encodeur
end encoder; X[3]

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 X(n-1)
"ZZ";
X(n-2) (m-1:0)
end encoder1;
Exemple d’application: nxm
...... Encodeur
encodeur clavier pour PIC X(1)
X(0)
Intérêt: réduire le nombre d’entrée du PIC 24
Logique combinatoire: Instructions concurrentes
Assignation sélective with expression select
 Structure WITH/SELECT signal <= signal1when valeur 1,
signal2 when valeur2,
------
Le multiplexeur: on aiguille une
signalN par défaut when others ;
enrée vers la sortie en fonction d’un
numéro d’aiguillage
---- Solution 2: WITH/SELECT------
library ieee;
MUX : 1 voie parmi 4 use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
E0
E1 Autre possibilté:
E2 std_logic_vector(1 downto 0) entity Combin3 is
E3 S
port
C0 (
C1 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 "00",
S <= E(0) when 0, E(1) when "01",
E(1) when 1, E(2) when "10",
E(2) when 2, E(3) when "11";
E(3) when 3;
end arch_combin3; 25
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 Analogie avec ORCAD: on
 Ma Référence :port map ( liste ordonnée de signaux) ; choisit un composant de la
• ou bibliothèque en le
 Ma Référence : port map ( port=> signal , port => signal ) ; référencant sur la feuille
Exemple applicatif: Comment faire un additionneur 4 bits? Exemple: résistance R1
Un 555: U1
etape 1: On crée un composant ADDITIONNEUR 1 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
Full Adder begin
S <= X xor Y xor Ci;
Cout <= (X and Y) or (X and Ci) or (Y and Ci);
end arch_add1full; 26
Logique combinatoire: Instructions concurrentes
étape 2: On valide le composant ( compilation /simulation)
étape3: On structure mon niveau supérieur ( comment faire 4 bits avec 1 bit?)
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
);

library IEEE; end component add1full;


use IEEE.std_logic_1164.all; -- déclaration des fils internes pour le report carry
signal Fil1,Fil2,Fil3:std_logic;
entity add4full is
begin
port( -- placement des 4 aditionneurs complets
Cin : IN std_logic; U0 : add1full port map (Cin,A(0),B(0),Res(0),Fil1);
A : IN std_logic_vector(3 downto 0); U1 : add1full port map (Fil1,A(1),B(1),Res(1),Fil2);
B : IN std_logic_vector(3 downto 0); U2 : add1full port map
Res : OUT std_logic_vector(3 downto 0); (X=>A(2),Y=>B(2),S=>Res(2),
Cout=>Fil3,Ci=>Fil2);
Cout : OUT std_logic
U3 : add1full port map (Fil3,A(3),B(3),Res(3),Cout);
);
end arch_add4full; 27
end add4full;
Logique combinatoire: Concepts de bases
library IEEE;
Comment créer une ET4 use IEEE.std_logic_1164.all;
On commence par faire ET2
ENTITY ET4 IS
library IEEE;
PORT ( X1,X2,X3,X4 : IN STD_LOGIC;
use IEEE.std_logic_1164.all;
Y : OUT STD_LOGIC );
END ET4;
ENTITY ET2 IS
PORT
ARCHITECTURE arch_ET4 OF ET4 IS
(
-- partie déclarative COMPOSANT ET2
A,B : IN STD_LOGIC;
COMPONENT ET2 is
S : OUT STD_LOGIC
PORT
);
(A,B : IN STD_LOGIC;
END ET2;
S : OUT STD_LOGIC);
END COMPONENT ET2; Les fils de
ARCHITECTURE arch_ET2 OF ET2 IS
-- partie déclarative SIGNAL connexions
BEGIN
--pas de IN ou OUT car signal INTERNE INTERNES
S<= A and B;
SIGNAL FIL1,FIL2: STD_LOGIC ;
END arch_ET2;
BEGIN
-- 1ere porte ET2 placée PORT
U1:ET2 port map (A=>X1,B=>X2,S=>FIL1); MAP pour
-- 2ème porte ET2 placée placement
U2:ET2 port map (A=>X3,B=>X4,S=>FIL2); et
-- 3ème porte ET2 placée connexion
U3:ET2 port map (A=>FIL1,B=>FIL2,S=>Y);
Deux fichiers ET2 et ET4 .vhd avec -- on pourrait faire à la place !!!!
-- Y<= X1 and X2 and X3 and X4 28
chacun une entity+une architecture END arch_ET4;
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

ARCHITECTURE …..
 L’ordre des instructions est SANS
IMPORTANCE ( car en parallèle) COMPONENT Truc

END COMPONENT
Déclaration de
 Il est souhaite de scinder les projets en COMPONENT Machin composants

composants simples END COMPONENT
créés
 APPROCHE METHODOLOGIQUE TOP-DOWN
SIGNAL: ……….
SIGNAL: ……..
 Utilisation des bibliothèques IEEE
XX<=“1110”;
YY<= A AND B; Utilisation
U1: Truc PORT MAP( …….); des
Squelette de S<= “10” when (A=B) else
ressources
“00”;
description U2: Machin PORT MAP( …….); disponibles
VHDL With (Toto) select
G<= ……

END ARCHITECTURE
29
Logique combinatoire: Exemple
Décodeurs 7 segments ?
 UTILISATION D’UNE TABLE (LUT) POUR DECRIRE LE SYSTEME
Création de nouveaux
library IEEE;
use IEEE.std_logic_1164.all; types: TYPE
Anode commune use IEEE.std_logic_unsigned.all; Tableau: ARRAY
Segment actif à ‘0’ --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
entity decod7seg is -- pour indexer tableau il faut un entier
port( -- fonction de conversion conv_integer dans
InSeg : IN std_logic_vector(3 downto 0); IEEE.std_logic_unsigned.all
OutSeg : OUT std_logic_vector(6 downto 0) OutSeg <= Tableau(conv_integer(InSeg));
end arch_dec_7seg;
);
end decod7seg; 30
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
library IEEE;
TEMP <= ('0'&A)+('0'&B)+Cin;
use IEEE.std_logic_1164.all;
--A et B étendu chacun de 1 bit.
use IEEE.std_logic_unsigned.all;
Res <= TEMP(TEMP'HIGH-1 downto 0);
Cout <= TEMP(TEMP'HIGH);
entity adddirect is
--TEMP'HIGH renvoi indice poids fort
generic (LARG:integer:=4);
end arch1_add4full;
-- paramètre générique
-- taille additionneur 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; S’RANGE renvoie 5 downto 0
A : IN std_logic_vector(LARG-1 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); 31
Logique combinatoire: Exemple
Arithmetic Logic Unit (ALU) Sélection Op Arithmétique/Logique

sel Operation Function Unit


0 000 y <= a Transfert a
0 001 y <= a+1 Incrément a
0 010 y <= a-1 Décrément a
0 011 y <= b Transfert b Arithmetic
0 100 y <= b+1 Incrément b
0 101 y <= b-1 Décrément b
0 110 y <= a+b Add a et b
0 111 y <= a+b+Cin Add a et b avec Carry
2 LIBRARY ieee; 1 000 y <= NOT a Complément a
3 USE ieee.std_logic_1164.all; 1 001 y <= NOT b Complément b
4 USE ieee.std_logic_unsigned.all; 1 010 y <= a AND b AND
5 ---------------------------------------------- 1 011 y <= a OR b OR Logic
6 ENTITY ALU IS 1 100 y <= a NAND b NAND
7 PORT (a, b : IN STD_LOGIC_VECTOR (7 DOWNTO 0); 1 101 y <= a NOR b NOR
8 sel : IN STD_LOGIC_VECTOR (3 DOWNTO 0); 1 110 y <= a XOR b XOR
9 cin : IN STD_LOGIC; 1 111 y <= a XNOR b XNOR
10 y : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)); Code opératoire
11 END ALU;
12 ---------------------------------------------- 26 ----- Logic unit: -----------
27 WITH sel(2 DOWNTO 0) SELECT
13 ARCHITECTURE dataflow OF ALU IS 28 logic <= NOT a WHEN "000",
14 SIGNAL arith, logic : STD_LOGIC_VECTOR (7 DOWNTO 0); 29 NOT b WHEN "001",
15 BEGIN 30 a AND b WHEN "010",
16 ----- Arithmetic unit: ------ 31 a OR b WHEN "011",
17 WITH sel(2 DOWNTO 0) SELECT 32 a NAND b WHEN "100",
18 arith <= a WHEN "000", 33 a NOR b WHEN "101",
19 a+1 WHEN "001", 34 a XOR b WHEN "110",
20 a-1 WHEN "010", 35 NOT (a XOR b) WHEN OTHERS;
21 b WHEN "011", 36 -------- Mux: ---------------
22 b+1 WHEN "100", 37 WITH sel(3) SELECT
b-1 WHEN "101", 38 y <= arith WHEN '0',
24 a+b WHEN "110", 39 logic WHEN OTHERS;
25 a+b+cin WHEN OTHERS; 40 END dataflow; 32
Logique combinatoire: Exemple

Buffers 3 états

LIBRARY ieee;
USE ieee.std_logic_1164.all;
----------------------------------------------
ENTITY tri_state IS
PORT (
ena : in std_logic; De manière générale il faut se poser la question:
input : in std_logic_vector (7 downto 0);
output : out std_logic_vector (7 downto 0) Le composant cible dispose t’il des ressources
); nécessaires pour synthétiser ma fonction
END tri_state;
---------------------------------------------- Pas de 3 états possibles si le composants n’en a pas!!
ARCHITECTURE tri_state OF tri_state IS
BEGIN
output <= input WHEN (ena='0') ELSE
(OTHERS => 'Z');
END tri_state;
33
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;

 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 H = ‘1’; wait on a, b; end process;
end process; end process; 34
Logique séquentielle: le process

Réveil du process
 Exemple: bascule D latch
 Fonctionnement sur niveau 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;

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; Processus activé 35
Logique séquentielle: le process

Rendre synchrone
 Bascule D edge: fonctionnement sur front
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;
Autre façon:
q : out std_logic
process(CLK)
);
begin
end entity;
If (H=‘1’) and (H’event) then
q<=d;
end if;
36
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 à respecter

CLK GCLK

ASTABLE CPLD

process(horl) Ce qu’il faut faire!


if (horl’event and horl = ‘1’) then
En pratique le FPGA (ou CPLD)
if (ena = ‘ 1 ’) then
possède une ou des broches
contenu_registre <= valeur_in; spécifiques pour le signal
end if; d’horloge
end if;
end process;
37
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
VCC
On remarquera que RST a disparu de la
C
liste de sensibilité
RESET
process (CLK)
ASTABLE R
Begin
if (CLK'event and CLK ='1') then
LIBRARY ieee; if (RESET =’1’) then
USE ieee.std_logic_1164.all; S <= ‘0’;
--------------------------------------- elsif (SET =’1’) then -- actif à ‘1’
ENTITY dff IS S <= ‘1’;
else
PORT ( d, clk, rst: IN STD_LOGIC;
S <= D;
q : OUT STD_LOGIC); end if;
END dff; Reset ASYNCHRONE end if;
--------------------------------------- end process ;
ARCHITECTURE behavior OF dff IS Comportement
BEGIN asynchrone de
PROCESS (rst, clk)
BEGIN la bascule
IF (rst=‘0') THEN
q <= '0';
ELSIF (clk'EVENT AND clk='1') THEN
q <= d;
END IF;
END PROCESS; 38
END behavior;
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;
---- Solution 2: OK -------------------
3 USE ieee.std_logic_1164.all;
2 LIBRARY ieee;
4 ---------------------------------------
3 USE ieee.std_logic_1164.all;
5 ENTITY dff IS
4 ---------------------------------------
6 PORT ( d, clk: IN STD_LOGIC;
5 ENTITY dff IS
7 q: BUFFER STD_LOGIC;
6 PORT ( d, clk: IN STD_LOGIC;
8 qbar: OUT STD_LOGIC);
7 q: BUFFER STD_LOGIC;
9 END dff;
8 qbar: OUT STD_LOGIC);
10 ---------------------------------------
9 END dff;
11 ARCHITECTURE not_ok OF dff IS
10 ---------------------------------------
12 BEGIN
11 ARCHITECTURE ok OF dff IS
13 PROCESS (clk)
12 BEGIN
14 BEGIN
13 PROCESS (clk)
15 IF (clk'EVENT AND clk='1') THEN
14 BEGIN
16 q <= d;
15 IF (clk'EVENT AND clk='1') THEN
17 qbar <= NOT q;
16 q <= d; LIGNE 19: On décris une
18 END IF;
17 END IF; relation COMBINATOIRE
19 END PROCESS; LIGNE 17: Si d a changé
18 END PROCESS; => On sors du PROCESS!!!
20 END not_ok; q ne changera qu’à la 19 qbar <= NOT q; 39
fin du process 20 END ok;
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;
architecture DESCRIPTION of CMP4BITSRET is
Use ieee.std_logic_unsigned.all;
signal CMP: std_logic_vector (3 downto 0);
entity CMP4BITSRET is
begin
PORT (
process (RESET,CLOCK)
RESET, CLOCK : in std_logic;
begin
RET : out std_logic;
if RESET ='1' then
Q : out std_logic_vector (3 downto 0)
CMP <= "0000";
);
elsif (CLOCK ='1' and CLOCK'event) then
end CMP4BITSRET;
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 40
Oui mais trop tard!!
Logique séquentielle: le process

Des solutions Solution 2

Solution 1 On décris le process (RESET,CLOCK)


combinatoire begin
process (RESET,CLOCK) HORS if RESET='1' then
begin PROCESS CMP <= "0000";
if RESET ='1' then elsif (CLOCK ='1' and
CMP <= "0000"; CLOCK'event) then
elsif (CLOCK ='1' and CMP <= CMP + 1;
CLOCK'event) then end if;
CMP <= CMP + 1; end process;
if (CMP = "1110") then
–- La retenue passera à un -- Validation de la retenue
quand CMP = 14 décimal RET <= '1' when (CMP = "1111")
RET <= '1'; else '0‘;
else
RET <= '0';
end if; Version complètement
end if; synchrone:
end process; On anticipe pour avoir un
résultat correct

41
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)
);
Q est défini en sortie end CMP4BITS;

OR Q<=Q+1 signifie architecture DESCRIPTION of CMP4BITS is


signal Q_BUS_INTERNE : std_logic_vector(3 downto 0));
Relire état courant et incrémente
begin
process (CLOCK)
Solution 1: définir BUFFER au lieu de OUT begin
if (CLOCK ='1' and CLOCK'event) then
Solution 2: couramment utilisée: passer par Q_BUS_INTERNE <= Q_BUS_INTERNE + 1;
un signal end if;
end process;
Q <= Q_BUS_INTERNE; -- affectation du bus interne au
-- signal de sortie Q
end DESCRIPTION;
42
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;
Library ieee; entity GRAY is
Use ieee.std_logic_1164.all; port (H,R :in std_logic;
Use ieee.numeric_std.all; Bascule T Q :out std_logic_vector(2 downto 0));
Use ieee.std_logic_unsigned.all; end GRAY;
T comme TOGGLE ( basculement). La architecture ARCH_GRAY of GRAY is
entity BASCULET is signal X :std_logic_vector(2 downto 0);
sortie change d’état à chaque front (
port ( begin
utilisation pour la synthèse des compteurs)
D,CLK : in std_logic; process(H,R)
S : buffer std_logic); Compteur begin
end BASCULET; if R='1' then X <= "000";
de GRAY
elsif (H'event and H='1') then
architecture DESCRIPTION of BASCULET is if X = "000" then X <= "001";
Begin elsif X = "001" then X <= "011";
PRO_BASCULET : process (CLK)
Code binaire réfléchi (codeur de elsif X = "011" then X <= "010";
Begin position par exemple) elsif X = "010" then X <= "110";
if (CLK'event and CLK='1') then elsif X = "110" then X <= "111";
if (D=’1’) then elsif X = "111" then X <= "101";
S <= not (S); elsif X = "101" then X <= "100";
end if; elsif X = "100" then X <= "000";
end if; end if;
end process PRO_BASCULET; end if;
end DESCRIPTION; end process;
Q <= X;
43
end ARCH_GRAY;
Logique séquentielle: les instructions
Assignation conditionnelle
 Structure CASE/IS
 Utile pour décrire des grafcets, machine d’états

Syntaxe:

Case selecteur is
when condition1 => instructions ;
…….
when condition2 => instructions ;
----
when others => instructions ;

end case ;

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;
44
FIN DE CAS;
Logique séquentielle: les instructions
 Exemple de CASE/IS
Schéma de principe d’un registre à décalage SIMPLE
 Description d’un registre à décalage

registre à décalage à droite ou à gauche

Reg_dec: PROCESS (h)


VARIABLE stmp: std_logic_vector(3 DOWNTO 0);
BEGIN
If (h=‘1’ and h’event) then Exemple
3 2 1 0
CASE selection IS
0 1 0 0
--chargement parallèle
WHEN ”11”=> stmp := d_entree; 2 1 0 ed 1 0 0 1 ed = 1
-- --Décalage à gauche & Nouvelle Valeur
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; On peut utiliser une variable à la
END CASE; la sortie est SYNCHRONE place d’un signal
sortie <= stmp; Pas de retard supplémentaire car utilisation Afféctation d’une variable
End if; d’une variable
END PROCESS Reg_dec; Syntaxe Mavariable:= ma valeur;
Si emploi d’un signal à la place d’une
variable affectation EN DEHORS DU Contrairement au signal la valeur est
PROCESS ( voir chapitre Mise à jour des mise à jour de suite
signaux et page suivante pour un exemple) 45
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; 46
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)
Emploi de signaux et non de begin
variables if R='1' then Q <= "0000";
elsif (H'event and H='1') then
if SENS = '1' then
Q <= Q(2 downto 0) & OUT_IN;
Affectation en dehors du process 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';
end ARCH_DECAL_DG;
47
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) Création d’un nouveau
BEGIN type: TYPE
IF (clk'EVENT AND clk='1') THEN
IF (wr_ena='1') THEN C’est un tableau de vecteurs
memory(addr) <= data_in;
END IF;
END IF;
END PROCESS;
data_out <= memory(addr);
END ram;

48
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; Application et utilisation d’un diviseur de
USE ieee.std_arith.all; fréquence
entity DIV_FREQ1 is
port (H :in std_logic;
N :in std_logic_vector(3 downto 0); •On évitera de cascader la sortie du diviseur
DIV : out std_logic); sur l’horloge du bloc suivant
end DIV_FREQ1;
architecture ARCH_DIV_FREQ1 of DIV_FREQ1 is
signal Q :std_logic_vector(3 downto 0); •La bonne méthode:
begin Horloge du système la même pour
process(H) tous les blocs
begin
if (H'event and H='1') then
La sortie du diviseur est une entrée de
if Q = 15 then Q <= N; validation du bloc suivant
else Q <= Q + 1; Si En=‘1’ alors on compte
end if;
end if;
end process;
DIV <= '1' when Q = 15 else '0';
end ARCH_DIV_FREQ1;
49
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;
LIBRARY ieee;
CO :out std_logic;
USE ieee.std_logic_1164.all; COMPOSANT HAUT NIVEAU
Q :out std_logic_vector(3 USE ieee.std_logic_unsigned.all;
downto 0)); entity COMPT12 is
end COMPTCAS; port (H,RAZ,EN : in std_logic;
architecture ARCH_COMPTCAS of CO : out std_logic;
COMPTCAS is Q :out std_logic_vector(11 downto 0));
signal X :std_logic_vector(3 downto end COMPT12;
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
port (H,R,EN : in std_logic;
if R='1' then X <= "0000";
CO : out std_logic;
elsif (H'event and H='1') then
Q : out std_logic_vector(3 downto 0));
if EN = '1' then X <= X + 1; end component;
else X <= X; begin
end if; 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 X = 15 else '0'; CO <= CO1 and CO2 and CO3;
end ARCH_COMPTCAS; end ARCH_COMPT12; 50
Logique séquentielle: des exemples

Détection d’un front


 Détection d’un changement d’état d’un signal
 Contrainte: DESCRIPTION SYNCHRONE
Équivalent à
Process(clk)
Detection: PROCESS
VARIABLE detect : std_logic_vector(1 DOWNTO 0); If (clk=‘1’ and clk’event)
BEGIN
WAIT UNTIL rising_edge (clk); -- c'est donc synchrone de clk
front_montant <= '0';
front_descendant <= '0' ;
detect(1) := detect(0); Rappel:
detect(0) := signal_lent; la variable prend sa valeur instantanément
IF detect = "01" THEN
front_montant <= '1'; Le signal prend sa valeur à la sortie du process
END IF;
IF detect = "10" THEN
front_descendant <= '1';
END IF;
END PROCESS;

51

Vous aimerez peut-être aussi