Vous êtes sur la page 1sur 267

Chapitre : Introduction

Implantation des circuits numériques


•Avec des éléments discrets
•Avec des microprocesseurs, micro contrôleurs, DSP
•Avec des circuits à architecture programmable PAL, GAL, FPGA
•Avec des circuits intégrés ASIC

PLD : Programmable Logic Device, CPLD : Complex PLD, PAL: Programmable Array Logic, GAL: Generic Array Logic,
FPGA : Field Programmable Gate Array, ASIC : application-specific integrated circuit
Formation VHDL Introduction Vahid MEGHDADI

1
Circuit avec des éléments discrets

•Circuit figé
•Circuit imprimé difficile à
modifier
•Intégration limitée
•Coût élevé
•Justifié pour de petits
circuits

Formation VHDL Introduction Vahid MEGHDADI

2
Circuit à fonctionnement programmable

•A base des microprocesseurs, Microcontrôleurs, DSP


•En modifiant le programme on modifie la fonction
•Plus souple que les circuits à éléments discrets

•Vitesse limitée (mais qui


augmente sans cesse) Microprocesseur Pér
•Parallélisme compliqué (mais iph
faisable)
éri
•Intégration encore limitée Mémoire que
•Adapté à des opérations
séquentielles
Formation VHDL Introduction Vahid MEGHDADI

3
Circuit à architecture programmable

•Une quantité importante de portes logiques


•Des matrices d'interconnections
programmables
•Modification du fonctionnement sur le circuit
(ISP)
•Souplesse assurée
•Coût de fabrication faible (pour un nombre limité)
•Intégration forte
•Adapté à des applications gourmandes en logique
•Temps de développement dépend de l'application
• Compliqué pour implanter des algorithmes complexes
Formation VHDL Introduction Vahid MEGHDADI

4
Les ASIC

Application Specific Integrated Circuit

• Coût très bas mais pour de gros tirages


• Temps de développement important
• Pas de modifications une fois fabriqué
• Nécessitant un fondeur pour la fabrication

Formation VHDL Introduction Vahid MEGHDADI

5
ASIC ou FPGA ?

ASICs FPGAs

High performance

Low development cost


Low power
Short time to market
Low cost in
high volumes Reconfigurability

Formation VHDL Introduction Vahid MEGHDADI

6
Evolution : Méthodes de CAO

Conception physique (layout)

Conception structurelle TTL

Conception logique

Conception fonctionnelle RTL


Programmation Verilog/VHDL

Synthèse comportemental
Formation VHDL Introduction Vahid MEGHDADI

7
Démonstrateurs

Circuit de développement SpartanIII

Formation VHDL Introduction Vahid MEGHDADI

8
Exemple

Une carte polyvalente et reconfigurable

Extension

JTAG

Formation VHDL Introduction Vahid MEGHDADI

9
Logique (FPGA) ou software (µP et DSP) ?

• Vitesse
• Possibilité de parallélisme (calcul dans l’espace ou dans le temps)
• Exemple y=Ax²+Bx+C

DSP FPGA

Formation VHDL Introduction Vahid MEGHDADI

10
Intérêt de la logique par rapport à µP

• Jeu d’instruction peut ne pas contenir l’opération voulue


• Processeur peut contenir des circuits qui ne servent à rien dans
notre application (Par exemple URAT)
• Processeur a besoin de la mémoire pour garder le programme
et les valeurs intermédiaires
• Le nombre de bits pour présenter les données peut être trop ou
peu
• Parallélisme très limité par software

Formation VHDL Introduction Vahid MEGHDADI

11
Fonction combinatoires

Utilisation d’un PLA (Programmable Logic Array) ou PLD


I I1 I
0 2

PLA1
PLA2
PLA3
O0 O1 O2 O3

Le circuit peut être reprogrammé sans changer le circuit


imprimé à condition de n’utiliser qu’un seul PLA ou prévoir
l’interconnexion entre PLA indépendant des modifs éventuelles!
Formation VHDL Introduction Vahid MEGHDADI

12
PLA

Formation VHDL Vahid MEGHDADI

13
CPLD

Complex Programmable Logic Device

Les CPLD contiennent un grand nombre de PLD


interconnectés par des liaisons programmables

I/O I/O
PLD PLD
I/O I/O
PLD Global PLD
Interconnection

I/O Matrix I/O


PLD PLD

Formation VHDL Introduction Vahid MEGHDADI

14
Architecture des FPGA
Feild Programmable Gate Array

CLB CLB CLB CLB CLB CLB CLB

CLB CLB CLB CLB CLB CLB CLB

CLB CLB CLB CLB CLB CLB CLB

CLB= Configurable Logic


Block CLB CLB CLB CLB CLB CLB CLB

CLB CLB CLB CLB CLB CLB CLB

CLB CLB CLB CLB CLB CLB CLB

CLB CLB CLB CLB CLB CLB CLB

Formation VHDL Introduction Vahid MEGHDADI

15
FPGA architecture interne

BLE= Basic Logic Element


K Out
Inputs LUT D FF

Clock
Programmable Programmable
IO Logic (CLB)
BLE
#1
N
N
I Outputs
I
Inputs BLE
#N

Clock

Programmable
Routing

Formation VHDL Introduction Vahid MEGHDADI

16
Architecture de CLB

Inputs Look-Up
Out
Table
(LUT)
Out = f (in0, in1, in2, in3)

State
Clock

Enable

Formation VHDL Introduction Vahid MEGHDADI

17
FPGA Xilinx

Plusieurs familles de FPGA


•Série 4000
•Spartan
•Spartan (II, III, VI)
•Virtex (II, IV, V, VI, VII)
•Artix
•Kintex
•Zynq (SoC)
Formation VHDL Introduction Vahid MEGHDADI

18
Spartan

Le nombre de broches I/O, le nombre de CLB


différentie les FPGA de la famille.

Formation VHDL Introduction Vahid MEGHDADI

19
Spartan II

Ajout de la RAM

Formation VHDL Introduction Vahid MEGHDADI

20
La famille Spartan II

Formation VHDL Introduction Vahid MEGHDADI

21
Spartan 3

Formation VHDL Vahid MEGHDADI

22
La famille Virtex

•Les LUT transformables en registre à décalage

•Plus de CLB, plus de mémoire, plus de slices par CLB

•Plus de I/O

•Multiplieurs câblés à partir de Virtex II

•DSP slices

•Microprocesseur embarqué (PowerPC)

Formation VHDL Introduction Vahid MEGHDADI

23
La famille Virtex

Formation VHDL Introduction Vahid MEGHDADI

24
La famille Virtex-II pro

Formation VHDL Introduction Vahid MEGHDADI

25
Virtex 5 et le LUT

LUT à 6 entrées et 2 sorties: permettant de construire des


logiques plus sophistiques dans un seul slice.
Formation VHDL Vahid MEGHDADI

26
Virtex 5 et les blocs DSP

Formation VHDL Vahid MEGHDADI

27
Série 7

Formation VHDL Vahid MEGHDADI

28
Conception circuit

o Les blocs reconfigurables


o Structure régulière de “logic cells”, connectée par un réseau d’interconnexions
o La configuration est stocké dans un SRAM, qui doit être chargé au démérrage
EPROM

Formation VHDL Introduction Vahid MEGHDADI

29
Design flow

HDL o Hardware design is traditionally done by modeling


(VHDL / the system in a hardware description language
Verilog)
o An FPGA “compiler” (synthesis tool) generates a
Synthesize netlist,

Netlist

Map
o which is then mapped to the FPGA technology,
Place o the inferred components are placed on the chip,
Route o and the connecting signals are routed through the
interconnection network.
Bitstream

Formation VHDL Introduction Vahid MEGHDADI

30
Synthèse HDL

HDL
(VHDL / process(clk, reset)
Verilog)
begin
if reset = ‚1‘ then
Synthesize output <= ‚0‘;
elsif rising_edge(clk) then
output <= a XOR b;
Netlist end if;
end process;
Map

Place Register
a
Route  D Q output
b

clk
clear
Bitstream
reset
Formation VHDL Introduction Vahid MEGHDADI

31
Technology Mapping

Register
HDL
a
(VHDL /  D Q output
Verilog) b

clk
clear
Synthesize
reset

Netlist

Map

Place

Route

Bitstream

Formation VHDL Introduction Vahid MEGHDADI

32
Placement & Routage

HDL
(VHDL /
Verilog)

Synthesize

Netlist

Map
Place

Route

Bitstream

Formation VHDL Introduction Vahid MEGHDADI

33
Insertion d’un microprocesseur (SoC)

IP core MicroBlaze (soft) PowerPC(dure), Multiplieurs dures, RAM, etc

MicroBlaze
Block RAM

18 bit Configuration
Multipliers Logic Block
(CLB)
Digital Clock
Manager Programmable I/Os
Formation VHDL Introduction Vahid MEGHDADI

34
Système embarqué traditionnel

Power Supply
Ethernet Audio CLK
CLK
MAC Codec

GP I/O Interrupt
Controller
Timer
Address
Decode
Unit
CPU UART
L
(uP / DSP) Co- C
Memory Proc. custom
CLK Controller IF-logic

SRAM SRAM SRAM Display


SDRAM SDRAM Controller

Images by H.Walder
Formation VHDL Introduction Vahid MEGHDADI

35
Système embarqué traditionnel

Power Supply
Ethernet Audio CLK
CLK
MAC FPGA Codec

GP I/O Interrupt
Controller
Timer
Address
Decode
Unit
CPU UART
L
(uP / DSP) Co- C
Memory Proc. custom
CLK Controller IF-logic

SRAM SRAM SRAM Display


SDRAM SDRAM Controller

Images by H.Walder
Formation VHDL Introduction Vahid MEGHDADI

36
System on Chip Configurable (CSoC)

Audio
Codec EPROM

Power Supply

L
C

SRAM SRAM SRAM SDRAM SDRAM


Images by H.Walder
Formation VHDL Introduction Vahid MEGHDADI

37
Avantages

 Moins de composantes physiques

 Cycle de conception plus rapide

 Programmable sur le circuit (Mise à jour, modification...)

 Plus performant grâce à l’intégration


 Horloge peut être plus rapide dans la puce que sur le circuit imprimé
 Optimisation entre modules possible

Formation VHDL Introduction Vahid MEGHDADI

38
CPUs Embarqués

 PowerPC 405 (hard core)


– 32 bit embedded PowerPC RISC architecture
– Up to 450 MHz
– 2x 16 kB instruction and data caches
– Memory management unit (MMU)
– Hardware multiply and divide
– Coprocessor interface
– Embedded in Virtex-II Pro and Virtex-4
– PLB (Proc. Local Bus) and OCM (On-Chip
memory) bus interfaces

 MicroBlaze (soft core)


– 32 bit RISC architecture
– 2-64 kB instruction and data caches
– Barrel Shifter
– Hardware multiply and divide
– OPB (On-chip Peripheral Bus)
and LMB (Local Memory Bus) bus interfaces

Formation VHDL Introduction Vahid MEGHDADI

39
Architecture de MicroBlaze

Formation VHDL Introduction Vahid MEGHDADI

40
CSoC Design Flow (Hardware)

HDL
Platform
(VHDL /
Description
Verilog)  Description de plate-forme est assemblée
dans un netlist
Netlist
Synthesize  Soit, il est mapé, placé et routé dans le
Generation FPGA

Netlist
Netlist VHDL

Map

Place
XST Xilinx ISE  Soit, il est importé dans ISE pour être
(VHDL Edit, Map,
(Map, Place & Route)
Place & Route) utilisé dans un système plus large à base
Route de FPGA

Bitstream
Formation VHDL Introduction Vahid MEGHDADI

41
CSoC Design Flow (Software)

*.a User sources


Library
Platform Generation *.h *.c
Description *.h

Compile &
Netlist
Link
Generation

Netlist
Update
Bitstream *.elf

XST or ISE
(Map, Place & Route)

Bitstream
Program
with
executable
Bitstream
Code
Formation VHDL Introduction Vahid MEGHDADI

42
Circuit de développement

Formation VHDL Introduction Vahid MEGHDADI

43
Formation VHDL Vahid MEGHDADI

44
Chapitre : Introduction A VHDL

Introduction au langage

VHDL

Formation VHDL Introduction A VHDL Vahid MEGHDADI

45
VHDL

V VHSIC
(Very High Speed Integradted Circuit)

H Hardware

D Description

L Language

Formation VHDL Introduction A VHDL Vahid MEGHDADI

46
Un peu d’histoire

•Début des années 80


•la nécessité d’un langage non ambigu des systèmes
matériels pour intégration à grande échelle
•normalisation pour être indépendant du fournisseur

•Norme définitive adoptée en 1987 : IEEE Std 1076

•La norme a été revue en 93, 2000 et 2002

•Les premiers outils de synthèse en 1995

Formation VHDL Introduction A VHDL Vahid MEGHDADI

47
Qu’est ce que on attend de VHDL

•VHDL est utilisé pour

•Décrire des circuits numériques

•Décrire des machines à états

•Préparer des signaux de test pour simuler cette écriture

Formation VHDL Introduction A VHDL Vahid MEGHDADI

48
Qu’est ce que on attend des outils de synthèse

•Une fois le programme en VHDL est écrit, il faut maintenant


le réaliser
•Synthèse logique : générer des fonctions logiques à partir
du programme
•Implémentation : adapter la logique synthétisée à la cible
(FPGA, CPLD)
•Génération : Générer un fichier binaire à télé-charger sur
le « device »
Formation VHDL Introduction A VHDL Vahid MEGHDADI

49
Démarche de synthèse

Cahier des charges

Partitionnement logicielle/matérielles

Spec matérielles Spec logicielles

ASIC

CPLD Cartes Software

Discret

Formation VHDL Introduction A VHDL Vahid MEGHDADI

50
Niveau d’abstraction

Synthèse Comportemental
comportemental

RTL VHDL
Synthèse
logique
Logique
Placement
routage
Layout

Formation VHDL Introduction A VHDL Vahid MEGHDADI

51
Formation VHDL Introduction A VHDL Vahid MEGHDADI

52
Chapitre : Structure du VHDL

Il existe 5 catégories d’unité de conception


•L’entité (mot clé entity)
Circuit Décrit un système vu extérieur (boîte noire)
principal
•L’architecture (mot clé architecture)
Décrit l’intérieur (le fonctionnement) d’une boîte noire.

•La configuration (mot clé configuration)

Package •La déclaration de paquetage (mot clé package)


(librairie) •Le corps de paquetage (mot clé package body)

Formation VHDL Structure du VHDL Vahid MEGHDADI

53
Domaine concurrent et séquentiel

Description d’un système matériel


•description d’action concurrentes (ex. plusieurs
blocs d’un circuit peuvent fonctionner en parallèle
•description d’action en séquence (ex. automates)

Deux jeux d’instructions en VHDL


•Instructions concurrentes : elles s’exécutent en
même temps
•Instructions séquentielles : elles s’exécutent les
une après les autres
Formation VHDL Structure du VHDL Vahid MEGHDADI

54
Classes d’objets

Quatre classes d’objets en VHDL :


•Les constantes
Comme les autres langages, elles ont une valeur fixe
•Les variables
Comme les autres langages, elles ont une valeur
immédiatement modifiable par affectation
•Les signaux
Notion nouvelle, la valeur ne se modifie pas immédiatement

•fichier (n’est pas abordé dans ce cours)

Formation VHDL Structure du VHDL Vahid MEGHDADI

55
Types d’objets

•Les objets d’un programme VHDL sont tous typés.


Avant toute utilisation d’une constante, d’une
variable ou d’un signal, il faut les déclarer.

•La déclaration des objets s’effectue uniquement dans


la partie déclarative du programme.

Formation VHDL Structure du VHDL Vahid MEGHDADI

56
Les opérateurs

Par ordre de priorité croissante


•Opérateur logique : and, or, nand, nor, xor, xnor,
sll, srl, sra, rol, ror
•Opérateur de comparaison : =, /=, <, <=, >, >=
•Opérateur d’addition : +, -, &
•Opérateur mathématique : *, /, mod, rem
•Opérateur de signe : -
•Opérateur divers : **, abs, not

Formation VHDL Structure du VHDL Vahid MEGHDADI

57
Programmer en VHDL

Définition de l’entité (boîte noire avec les ports d’entrée/sortie)


Définition de l’architecture interne de cette boîte noire
Déclaration des constantes, des signaux, des fonctions, des
procédures, des blocs hiérarchiques utilisés dans le
programme
Corps du programme consistant
Les instructions concurrentes
Les instructions séquentielles encapsulées dans des
« process »
(Les commentaires sont précédés de deux tirés : -- exemple)
Formation VHDL Structure du VHDL Vahid MEGHDADI

58
Formation VHDL Structure du VHDL Vahid MEGHDADI

59
Formation VHDL Vahid MEGHDADI

60
Chapitre : Entité

•L'entité définit les ports (vue externe) et leur mode (in, out,
inout, buffer)

•Paramétrer le modèle (paramètres génériques)

•Syntaxe:
entity nom_de_l_entite is
{generic(liste_des_parametres)}
{port(liste_des_port_avec_leutr_mode)}
end {nom_de_l_entite}

Formation VHDL Entité Vahid MEGHDADI

61
Entité

Entity name Port names Port type


Semicolon

ENTITY nand_gate IS
PORT(
a : IN STD_LOGIC; No Semicolon
b : IN STD_LOGIC; after last port
z : OUT STD_LOGIC
);
END nand_gate;

Reserved words Port modes (data flow directions)

Même chose mais en moins lisible !!


ENTITY nand_gate IS PORT(a,b: IN STD_LOGIC;z : OUT STD_LOGIC
);END nand_gate;

Formation VHDL Entité Vahid MEGHDADI

62
Exemples d’entité

entity NAND2 is E1 S
port(E1,E2: in std_logic;
S: out std_logic);
end NAND2; E2

entity COMPTEUR is
generic(N : integer := 20); E S
port(E1: in std_logic; /N
S: out std_logic_vector(4 downto 0));
end COMPTEUR ;

Formation VHDL Entité Vahid MEGHDADI

63
Exemple d’entité

Bascule D
D Q
entity BASCULE_D is
port (D,EN : in std_logic;
Q, Q_B : out std_logic);
End BASCULE_D EN Q_B

Formation VHDL Entité Vahid MEGHDADI

64
Chapitre : Architecture

•Définition de signaux et d'autres objets internes

•Description du fonctionnement ou de la structure de


l’entité à l’aide d’instructions concurrentes

Syntaxe:
architecture nom_de_l_architecture of nom_de_l_entite is
{partie déclarative}
begin

{suite d’instructions concurrentes}


end nom_de_l_architecture;
Formation VHDL Architecture Vahid MEGHDADI

65
Affectation aux signaux

•Affectation des signaux se fait par le signe <=

Signal A,B,C: std_logic; --declaration



A <= not B ;
B <= ‘1’ ;
C <= A and B ;

Formation VHDL Architecture Vahid MEGHDADI

66
Structure d’un programme VHDL

entity circuit is
port (CLK, RST: in std_logic;
B_DAT: inout std_logic_vector(7 downto 0);
…);
end circuit;

architecture comport of circuit is


{partie déclarative de l'architecture}
begin
{zone des instructions concurrentes }
{comme des affectations, des process; …}
end comport;

Formation VHDL Architecture Vahid MEGHDADI

67
Exemple 1

A SUM
Demi-
additionneur
B C
A SUM
A B SUM C

B 0 0 0 0
C 0 1 1 0
1 0 1 0
1 1 0 1

Formation VHDL Architecture Vahid MEGHDADI

68
Exemple 1, programme

entity DEMI_ADD is
port (A,B: in std_logic;
SUM,C: out std_logic);
end DEMI_ADD;

architecture COMPORT of DEMI_ADD is


begin
SUM <= A xor B; --instruction concurrente
C <= A and B; --instruction concurrente
end COMPORT;

Formation VHDL Architecture Vahid MEGHDADI

69
Exemple d’une bascule RS

R Q

QB
S
entity RS_FF is
port (R,S: in std_logic;
Q,QB:out std_logic);
end RS_FF;

architecture FPGA of RS_FF is


begin
Q <= R nand QB;
QB <= S nand Q;
end

Formation VHDL Architecture Vahid MEGHDADI

70
Formation VHDL Vahid MEGHDADI

71
Formation VHDL Vahid MEGHDADI

72
Chapitre : Types en VHDL

Tout objet en VHDL doit être typé.


Un type définit
•l'ensemble des valeurs que l'on peut affecter à l'objet
•l'ensemble des opérations disponibles sur l'objet

Formation VHDL Types en VHDL Vahid MEGHDADI

73
Types, schéma global

Types

Scalaire composite Fichier Pointeur

Enregistre
énumérés Entier Réel Physique Tableau ment
(record)

Formation VHDL Vahid MEGHDADI

74
Déclaration de type

VHDL possède les types:


•scalaires dont la valeur est constituée d'un seul élément
•composites dont la valeur comprend plusieurs éléments
•accès ou pointeurs
•fichier
•On n'étudie que les deux premiers

Formation VHDL Types en VHDL Vahid MEGHDADI

75
Type scalaire

•énuméré
type T_FEU is (ROUGE, ORANGE, VERT);
signal FEU : T_FEU;

•entier
signal COMPT : integer range 0 to 15;

•flottante
signal MASSE : REAL; -- de -1e38 à 1e38

•physique qui est un entier avec l'unité correspondant


type TIME is range … to … --64 bits
units fs; ps=1000 fs; ns=1000 ps; …
hr=60 min;
end units;
T <= 5 ns;

Formation VHDL Types en VHDL Vahid MEGHDADI

76
Type énuméré

Ce type déclare toutes les valeurs qu'un objet de ce type


peut prendre.
type T_FEU is (ROUGE, ORANGE, VERT);
signal FEU : T_FEU;
type ETAT is (INIT, LECT, ECR, ATT);

Les types ci-dessous sont des types prédéfinis


type BOOLEAN is (FALSE, TRUE);
type BIT is ('0' , '1');

Formation VHDL Types en VHDL Vahid MEGHDADI

77
Type entier (scalaire)

C'est un type prédéfini


type integer is range
-2_147_483_648 to 2_147_483_647

On peut définir un sous type :


subtype nom_de_sous_type is
type_de_base contraintes;
subtype NATURAL is INTEGER
range 0 to INTEGER'high

Formation VHDL Types en VHDL Vahid MEGHDADI

78
Logique à valeurs multiples (scalaire)

•Il existe des signaux logiques à plusieurs états:


0, 1, haute impédance, don’t care, non déterminé, …

•Le type "std_logic" remplace le type "bit" pour permettre


d’avoir 9 états différents
•Utilisation de librairie IEEE.std_logic_1164
•exemple
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
signal SORTIE, Q: std_logic;

SORTIE <= ‘Z’; -- haute impédance
Q <= ‘1’;
Formation VHDL Types en VHDL Vahid MEGHDADI

79
Le type std_logic

‘L’
VDD
Le type std_logic : ‘0’
‘U’ non initialisé
‘X’ non connu ‘H’ ‘1’
‘0’ logique 0 Strong drive
‘1’ logique 1
‘Z’ haute impédance
‘W’ non connu
‘L’ logique 0 weak drive
‘H’ logique 1
‘-’ don’t care ‘0’

Formation VHDL Types en VHDL Vahid MEGHDADI

80
Type composite

Deux types sont considérés : tableau et record


•Un tableau est un ensemble d’éléments du même type
•Pour un ensemble de std_logic, nous avons le type prédéfini
std_logic_vector : on définit la taille et l'ordre des éléments
signal BUS1 : std_logic_vector (7 downto 0);
signal REG : std_logic_vector (0 to 31);

•On peut aussi définir un type tableau d’éléments composites


type MEMO is array (0 to 1023) of
std_logic_vector(7 downto 0);
signal A,B : MEMO;

Formation VHDL Types en VHDL Vahid MEGHDADI

81
Accès aux éléments

•Déclaration:
A,B: std_logic_vector(15 downto 0);

•Directement:
A(3) <= ‘1’;
B(15) <= ‘0’;

•Par tranches
A(15 downto 12) <= "1011";
B(0 to 2) <= "111" ; -- erreur
A(10 downto 2) <= B(15 downto 7);

Formation VHDL Types en VHDL Vahid MEGHDADI

82
Accès aux éléments de tableaux

• Par agrégat
• Notation positionnelle
A(3 downto 1) <= ('0', '1', B(15));
B <= ('1','1',others => '0');

• Notation par nommage


A <= (1 =>'1', 3 =>'1',others =>'0');

• Par concaténation
signal A,B,C,D : std_logic;
signal BYTE : std_logic_vector(7 downto 0);
signal Z_BUS,A_BUS : std_logic_vector(3 downto 0);
Z_BUS <= A & C & D & B;
BYTE <= Z_BUS & A_BUS;

Formation VHDL Types en VHDL Vahid MEGHDADI

83
Exemples

SIGNAL a: STD_LOGIC;
SIGNAL b: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL c: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL d: STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL e: STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL f: STD_LOGIC_VECTOR(8 DOWNTO 0);
……….
a <= ‘1’;
b <= ”0000”; -- Base Binaire par défaut
c <= B”0000”; -- Base Binaire explicite
d <= ”0110_0111”; -- Utiliser ‘_’ pour augmenter la lisibilité
e <= X”AF67”; -- Base Hexadecimale
f <= O”723”; -- Base Octale

Formation VHDL Types en VHDL Vahid MEGHDADI

84
Exemples

•type MY_WORD is array (15 downto 0) of std_logic;


•signal mem_addr : MY_WORD;
•mem_addr(10 downto 5) <= "101010";

•type YOUR_WORD is array (0 to 15) of std_logic;


•signal data_word : YOUR_WORD := “1101100101010110”;

•type T_VAR is array (0 to 7) of integer;


•constant setting : T_VAR := (2,4,6,8,10,12,14,16);

•type T_MATRIX is array (0 to 3, 1 to 2) of natural;


•variable data_arr : T_MATRIX :=((0,2), (1,3), (4,6), (5,7));
•data_arr(0,2) := 12;
•type array_name is array (type range <>) of element_type;-- taille est
-- définie quand on déclare l'objet
•type MATRIX is array (integer range <>) of integer;
•variable MATRIX8: MATRIX (2 downto -8) := (3, 5, 1, 4, 7, 9, 12, 14, 20, 18);

Formation VHDL Types en VHDL Vahid MEGHDADI

85
Enregistrement (record)

Ensemble d'éléments de types différents


type NAME is
record
identifier : type_indication;
:
identifier : type_indication;
end record;

type PAQUET is
record
mot_unique : std_logic_vector (7 downto 0);
data : std_logic_vector (23 downto 0);
CRC : std_logic_vector( 5 downto 0);
num : integer range 0 to 1023;
end record;
signal paq_rec : PAQUET;
paq_rec.CRC <= "111000";
Formation VHDL Types en VHDL Vahid MEGHDADI

86
Formation VHDL Vahid MEGHDADI

87
Formation VHDL Vahid MEGHDADI

88
Chapitre: zone concurrente

•Le corps de l'architecture est une zone concurrente: les


instructions s'exécutent toutes en même temps (en parallèle)
A
B I S
C

I <= A or B; S <= I and C


S <= I and C I <= A or B;

Formation VHDL Zone concurrente Vahid MEGHDADI

89
Instruction with

with HEX select


LED<= "1111001" when "0001", --1
"0100100" when "0010", --2
"0110000" when "0011", --3
"0011001" when "0100", --4
"0010010" when "0101", --5
"0000010" when "0110", --6
"1111000" when "0111", --7
"0000000" when "1000", --8 7
"0010000" when "1001", --9
"0001000" when "1010", --A
"0000011" when "1011", --b Circuit
"1000110" when "1100", --C combinatoire
"0100001" when "1101", --d
"0000110" when "1110", --E
4
"0001110" when "1111", --F
"1000000" when others; --0

Formation VHDL Zone concurrente Vahid MEGHDADI

90
Instruction when

LABEL1: -- optional label


SIG_NAME <= <expression> when <condition> else
<expression> when <condition> else
<expression>;

B_DAT <= REG1 when ENA1='0' else


REG2 when ENA2='0'else "ZZZZZZZZ";

ENA1
8 8
REG1
ENA2
8
REG2

Formation VHDL Zone concurrente Vahid MEGHDADI

91
Exemple

entity CIR is
port (A,B,C,D : in std_logic;
s : out std_logic);
end CIR;

architecture COMPORT1 of CIR is architecture COMPORT2 of CIR is


Begin signal inter1, inter2: std_logic;
S <= (A and B) nor (C nand D); Begin
end COMPORT1; inter1 <= A and B;
inter2 <= C nand D;
S <= inter1 nor inter2;
end COMPORT2;

Formation VHDL Zone concurrente Vahid MEGHDADI

92
Exemple ALU

entity ADDER is
port (A,B :in std_logic_vector(7 downto 0);
SEL : in std_logic;
S : out std_logic_vector(7 downto 0));
end ADDER;

architecture COMPORT of ADDER is


Begin
with SEL select
S <= A+B when '0',
A-B when others;
-- S <= A+B when SEL=‘0’ else A-B;
end COMPORT;

Formation VHDL Zone concurrente Vahid MEGHDADI

93
Formation VHDL Vahid MEGHDADI

94
Formation VHDL Vahid MEGHDADI

95
Formation VHDL Vahid MEGHDADI

96
Chapitre: zone séquentielle

•En VHDL, une zone séquentielle existe dans laquelle


une suite d'instructions s’exécutent les unes après
les autres.

•Cette zone se trouve dans les process, fonctions et


procédures.

Formation VHDL Zone séquentielle Vahid MEGHDADI

97
Process

• Process est une instruction concurrente complexe à


écrire dans une architecture

• Process définit une zone séquentielle

• Les différents process d'une architecture s'exécutent


tous en parallèle

Formation VHDL Process Vahid MEGHDADI

98
Syntaxe de process

•Syntaxe de process :
label : -- optionnel
process (liste de sensibilité)
{partie déclarative}
begin
suite d’instructions séquentielles
end process;

•Un process s'exécute quand un des signaux de la liste


de sensibilité change de valeur.

Formation VHDL Process Vahid MEGHDADI

99
Instructions séquentielles

•Ils s'écrivent uniquement dans une zone séquentielle


• instruction d'attente (wait)
• instruction d'affectation (temporisée)
• instruction conditionnelle (if)
• instruction case
• instruction de boucle

Formation VHDL Process Vahid MEGHDADI

100
Instructions wait

Elle s’utilise pour suspendre un process jusqu’un événement


• wait until condition;
•wait until A=‘ 1 ’;
•wait until CLK’event and CLK=’1’;

• wait for time expression;


•wait for 5 ns;

• wait on signal;
•wait on A , B

Formation VHDL Process Vahid MEGHDADI

101
Instructions if

if condition then
sequential statements
[elsif condition then
sequential statements ]
[elsif condition then
sequential statements ]
[else
sequential statements ]
end if;

Formation VHDL Process Vahid MEGHDADI

102
Instruction case

Permet de sélectionner une suite d’instructions à exécuter


en fonction de la valeur d’une expression.

case EXPRESSION is
when VAL1 => suite d’instructions séquentielles
when VAL2|VAL3|VAL4 => suite d’instr séquentielles
when VAL5 to VAL7 => suite d’instr séquentielles
when others => suite d’instr séquentielles
end case;

•L’ordre des branches n’a pas d’importance (sauf others)


•La branche « others » est obligatoire si toutes les valeurs
de l’expression ne sont pas énumérées.
Formation VHDL Process Vahid MEGHDADI

103
Instruction for

for I in 0 to 3 loop Synthèse Logique


-- logique logique
end loop; logique logique

Formation VHDL Process Vahid MEGHDADI

104
Exemple

Multiplexeur 4 voies

S1 S0

A
M
B Z
U
C X
4
D

Formation VHDL Process Vahid MEGHDADI

105
Exemple (avec if)

entity MUX_4 is
port (S1, S0, A, B, C, D: in std_logic;
Z: out std_logic);
end MUX_4;

architecture behav_MUX_4 of MUX_4 is


begin
P1: process (S1, S0, A, B, C, D) - - la liste de sensibilité
begin
if (( not S1 and not S0 )=’1’) then Z <= A;
elsif (( not S1 and S0) = ‘1’) then Z <=B;
elsif ((S1 and not S0) =’1’) then Z <=C;
else Z <=D;
end if;
end process P1;

end behav_MUX_4;

Formation VHDL Process Vahid MEGHDADI

106
Exemple (avec case)

entity MUX_4 is
port ( S : in std_logic_vector(1 downto 0);
A, B, C, D: in std_logic; Z: out std_logic );
end MUX_4;

architecture behav_MUX_4 of MUX_4 is


begin
P1: process (S, A, B, C, D) - - la liste de sensibilité
begin
case S is
when "00" => Z <= A;
when "01" => Z <= B;
when "10" => Z <= C;
when "11" => Z <= D; -- ou when others => Z <= D;
end case;
end process P1;

end behav_MUX_4;
Formation VHDL Process Vahid MEGHDADI

107
Exemple (avec for)

entity MUX_4 is
port (S : in integer range 0 to 3;
A: in std_logic_vector(0 to 3); Z: out std_logic );
end MUX_4;

architecture behav_MUX_4 of MUX_4 is


begin
P1: process (S, A) - - la liste de sensibilité
begin
For I in 0 to 3 loop
if S = I then
Z <= A(I);
end if;
end loop;
end process P1;

end behav_MUX_4;
Formation VHDL Process Vahid MEGHDADI

108
Affectation des signaux

•Dans une architecture (zone concurrente), l’affectation


est immédiate.
•Dans un process (zone séquentielle) l’affectation est
•immédiate pour des variables
•retardée jusqu’à la fin du process pour des signaux

Formation VHDL Process Vahid MEGHDADI

109
Affectation dans une architecture

Architecture CONCUR of EXEMPLE is


signal Z, A, B, C, D : std_logic;
begin
Z <= A and B;
Erreur multi sources
Z <= C and D;
end CONCUR;

A
B
Z
?
C
D
Formation VHDL Process Vahid MEGHDADI

110
Affectation dans un process

Architecture SEQ of EXEMPLE is


signal Z, A, B, C, D : std_logic;
begin
process(A, B, C, D)
begin C
Z
Z <= A and B; D

Z <= C and D;
end process; -- la valeur retenue est affectée maintenant
end CONCUR;

Formation VHDL Process Vahid MEGHDADI

111
Attention !

Le process ci-dessous ne
produira pas le signal ci-
contre
SIG

Process (x)
begin
SIG <= '0';
SIG <= '1'; SIG
SIG <= '0';
end process;

Formation VHDL Process Vahid MEGHDADI

112
Exemple d’appel multiple

EXEMPLE : process (A,B,M)


begin A:0
Y <= A; B:0
M <= B; M:0
Z <= M; Z :0
end process;

Un événement se produit : B -> 1 A:0


Y:0
B:1
M:1
Le process se réveille, alors : M:0
Z :0
Z :0

Formation VHDL Process Vahid MEGHDADI

113
Exemple d’appel multiple

EXEMPLE : process (A,B,M)


begin A:0
Y <= A; B:1
M <= B; M:1
Z <= M; Z :0
end process;

Un nouveau événement sur M, process se réveille encore

A:0
Y:0
B:1
M:1
M:1
Z :1
Z :0

Formation VHDL Process Vahid MEGHDADI

114
Les variables

•L'affectation se fait par le signe " := "


•Les variables ne sont déclarées que dans un process
•La valeur des variables est mise à jour dès l’exécution de
l’instruction d’affectation
•Les variables ne sont pas visibles à l’extérieur du process
•Les variables gardent leur valeur pour le réveil suivant

Formation VHDL Process Vahid MEGHDADI

115
Formation VHDL Vahid MEGHDADI

116
Chapitre : Hiérarchisation

• Conception d’un bloc et son utilisation dans un autre


circuit: instantiation ou instantiation multiple
1. Première étape: écrire l’entité et l’architecture du
module
2. Deuxième étape: introduire ce module au circuit
appelant (ce module s’appellera « component »)
3. Troisième étape: instantiation du module

Formation VHDL Hiérarchisation Vahid MEGHDADI

117
Déclaration du component

•Se fait dans la partie déclarative de l’architecture.


•On utilise le mot clé « component »

Exemple: entity DEMI_ADD is


port (A,B: in std_logic;
SUM,C: out std_logic);
end DEMI_ADD;

component DEMI_ADD
port(A,B : in std_logic;
SUM,C: out std_logic);
end component;

Formation VHDL Hiérarchisation Vahid MEGHDADI

118
Instantiation du component

•Utilisation du mot clé « port map »

Exemple:
component DEMI_ADD
port(A,B : in std_logic;
SUM,C: out std_logic);
end component;
Préférable
DEMI_ADD_INST: DEMI_ADD port map
Deux (A => SIG_A, B => SIG_B, SUM => SOMME, C => RETENUE);
façons
de faire DEMI_ADD_INST: DEMI_ADD port map (SIG_A,SIG_B, SOMME, RETENUE);

Formation VHDL Hiérarchisation Vahid MEGHDADI

119
Exemple addition

A Demi- SUM
B additionneur C

A SUM
A B SUM C

B 0 0 0 0
C 0 1 1 0
1 0 1 0
1 1 0 1

Formation VHDL Hiérarchisation Vahid MEGHDADI

120
Description flot de données

entity DEMI_ADD is
port (A,B: in std_logic;
SUM,C: out std_logic);
end DEMI_ADD;

architecture COMPORT of DEMI_ADD is


begin
SUM <= A xor B; --instruction concurrente
C <= A and B; --instruction concurrente
end COMPORT;

Formation VHDL Hiérarchisation Vahid MEGHDADI

121
Exemple d’architecture 2

A SUM N1 SUM
SUM
DEMI_ADD N2 DEMI_ADD
B C C N3
Cout
CIN

entity ADD_COMPLET is
port (A,B,CIN : in std_logic;
SUM,COUT : out std_logic);
end ADD_COMPLET;

Formation VHDL Hiérarchisation Vahid MEGHDADI

122
Instantiation

architecture COMPORT of ADD_COMPLET is

component DEMI_ADD Déclaration de


port(A,B : in std_logic;
SUM,C: out std_logic);
component
end component;
Instantiation
signal N1, N2, N3 : std_logic;
begin
ADD1: DEMI_ADD port map(A,B,N1,N2);
ADD2: DEMI_ADD port map(N1,CIN,SUM,N3);
COUT <= N2 or N3;
end COMPORT ;

Formation VHDL Hiérarchisation Vahid MEGHDADI

123
Chapitre : Déroulement d’un programme VHDL

•L’architecture est le lieu d’échange de l’information entre


les instructions concurrentes (les process en particulier).
•L’échange se fait uniquement par l’intermédiaire des
signaux
Signal a

process
process
Signal x,y
Signal t,u
process
Formation VHDL Déroulement d’un programme VHDL Vahid MEGHDADI

124
Déroulement de simulation

•La notion de temps ne s'utilise que pour spécifier l'ordre des


événements.
•Les seuls moyens d'avancer dans le temps sont :
•par un changement d'un signal en entrée
•par la commande wait for temps
•par la commande after temps
•Sinon, les signaux sont tous stables et les process dorment
tous.

Formation VHDL Déroulement d’un programme VHDL Vahid MEGHDADI

125
Deux files d'attente

1- A chaque événement est associé une liste des process à


réveiller
2- Après exécution de tous les process de la liste, une
nouvelle liste d'événement sur les signaux est établie
3- Une nouvelle liste des process à réveiller s'établit
4- Tant que cette liste n'est pas vide, on réitère à l'étape 2
5- Le circuit est stable et attend un nouvel événement

Formation VHDL Déroulement d’un programme VHDL Vahid MEGHDADI

126
Traitement des files

Repérer les
signaux changés

Repérer les
File process à réveiller File
signal process

Formation VHDL Déroulement d’un programme VHDL Vahid MEGHDADI

127
Avancement dans le temps

File File File File


signal process signal process

temps
En simulation, les événements sont également sur une liste.
Wait for 5 ns, ou A <= Z after 7 ns créent des événements
dans l'ordre sur cette liste.
Formation VHDL Déroulement d’un programme VHDL Vahid MEGHDADI

128
Chapitre : Circuits combinatoires

Un circuit combinatoire donne toujours les mêmes sorties


quand l’entrée est la même.
Un process est combinatoire si les conditions suivantes sont
toutes respectées :
•le process comporte une liste de sensibilité
•la liste de sensibilité comprend tous les signaux lus
•tous les signaux doivent être affectés quelle que soit les
entrées (Attention dans un "if" ou dans un "case")
•toutes les variables doivent être affectées avant d'être lues
Formation VHDL Circuits combinatoires Vahid MEGHDADI

129
Circuits combinatoires : équation logique

Architecture COMB1 of NONET is


begin
Architecture COMB3 of NONET is
--équation logique begin
S <= A nand B; --Traduction de la table
end COMB1; --de vérité dans un process
process(A,B)
begin
if A='1' and B='1' then
Architecture COMB2 of NONET is S <= '0';
begin else
--Traduction de la table S <= '1';
--de vérité dans un process end if;
S <= '0' when A='1' and B='1' end process;
else '1'; end COMB3;
end COMB2;

Formation VHDL Circuits combinatoires Vahid MEGHDADI

130
Exemple

Transcription d’une table de vérité

A(2) A(1) A(0) S(2) S(1) S(0)


0 0 0 0 0 0
0 0 1 0 0 1
0 1 0 0 1 1
0 1 1 0 1 0
1 0 0 1 1 0
1 0 1 1 1 1
1 1 0 1 0 1
1 1 1 1 0 0

Formation VHDL Circuits combinatoires Vahid MEGHDADI

131
Affectation avec if

Dans une zone séquentielle (process)

Architecture AVEC_IF of CIRCUIT


signal A,S : std_logic_vector (2 downto 0);
begin
process(A)
begin
if A = "000" then S <= "000";
elsif A ="001" then S <= "001";
elsif ...

end if;
end process;
end AVEC_IF;

Formation VHDL Circuits combinatoires Vahid MEGHDADI

132
Affectation avec case

Dans une zone séquentielle (process)


Architecture AVEC_CASE of CIRCUIT
signal A,S : std_logic_vector (2 downto 0);
begin
process(A)
begin
case A is
when "000" => S <= "000"
when "001" => S <= "001"
when "011" => S <= "010"

end case
end process;
end AVEC_CASE;

Formation VHDL Circuits combinatoires Vahid MEGHDADI

133
Affectation sélective

Dans une zone concurrente (architecture)

Architecture AVEC_WITH of CIRCUIT


signal A,S : std_logic_vector (2 downto 0);
begin
with A select
S <= "000" when "000" ,
"001" when "001" ,
"011" when "010" ,
"110" when "100" ,

"000" when others;
end AVEC_WITH;

Formation VHDL Circuits combinatoires Vahid MEGHDADI

134
Affectation non conditionnelle

Dans une zone concurrente (architecture)


Architecture DIRECT of CIRCUIT
signal A,S : std_logic_vector (2 downto 0);
begin
S(2) <= (A(2) and not A(1) and not A(0))
or (A(2) and not A(1) and A(0))
or (A(2) and A(1) and not A(0))
or (A(2) and A(1) and A(0));

S(1) <= (not A(2) and A(1) and not A(0))


or (not A(2) and A(1) and A(0))
or (A(2) and not A(1) and not A(0))
or (A(2) and not A(1) and A(0));

Formation VHDL Circuits combinatoires Vahid MEGHDADI

135
Affectation avec when

Dans une zone concurrente (architecture)


Architecture AVEC_WHEN of CIRCUIT
signal A,S : std_logic_vector (2 downto 0);
begin
S <= "000" when A= "000"
else "001" when A= "001"
else "011" when A= "010"
else "010" when A= "011"
else "110" when A= "100"
else "111" when A= "101"
else "101" when A= "110"
else "100" when A= "111"
else "000";
end AVEC_WHEN;

Formation VHDL Circuits combinatoires Vahid MEGHDADI

136
Exemple : ALU

entity ALU is
port(A : in std_logic_vector(7 downto 0);
B : in std_logic_vector(7 downto 0);
Sel: in std_logic_vector(1 downto 0);
Res: out std_logic_vector(7 downto 0));
end ALU;
-- Sel="00" => Addition
-- Sel="01" => Soustraction
-- Sel="00" => et logique bit à bit
-- Sel="00" => ou logique bit à bit
architecture behv of ALU is
begin
process(A,B,Sel)
….
end process;
end behv;

Formation VHDL Vahid MEGHDADI

137
Exemple : ALU (suite)

process(A,B,Sel)
begin
case Sel is
when "00" =>
Res <= A + B;
when "01" =>
Res <= A + (not B) + 1;
when "10" =>
Res <= A and B;
when "11" =>
Res <= A or B;
when others =>
Res <= "--";
end case;
end process;

Formation VHDL Vahid MEGHDADI

138
Exemple : Multiplieur

Le but est de réaliser un multiplieur 4 bits fois 4 bits

A 1001 0 A

B *1101 0 B(0) 0
--------- 4 4 4
B(1)
0000 1001 0
4
+0000 0000 5 B(2) 0
4
+0010 0100 res(0) (4 downto 1) 5 B(3)

+0100 1000
res(1) (4 downto 1) 5
----------
0111 0101 res(2) (4 downto 1)
res(7 downto 3)

Formation VHDL Vahid MEGHDADI

139
Exemple : Multiplieur (suite)

entity main is
Port ( A : in std_logic_vector(3 downto 0);
B : in std_logic_vector(3 downto 0);
RES : out std_logic_vector(7 downto 0));
end main;

architecture Behavioral of main is


begin
process (A,B)
variable result : std_logic_vector(7 downto 0);
begin
result := (others => '0');
for I in 0 to 3 loop
if B(I)='1' then
result(I+4 downto I) := result(I+4 downto I) + ('0' & A);
end if;
end loop;
RES <= result;
end process;
end Behavioral;
Formation VHDL Vahid MEGHDADI

140
Exemple : Multiplieur, résultat de synthèse

Formation VHDL Vahid MEGHDADI

141
Formation VHDL Vahid MEGHDADI

142
Formation VHDL Vahid MEGHDADI

143
Formation VHDL Vahid MEGHDADI

144
Chapitre : Circuits séquentiels

Un process comporte un point de mémorisation si au


moins une des conditions suivantes est vérifiée :
•la liste de sensibilité ne comprend pas tous les signaux
lus
•les signaux ne sont pas affectés quelle que soit la
branche
•une variable est lue avant d'être affectée

Formation VHDL Circuits séquentiels Vahid MEGHDADI

145
Latch

Bascule à verrouillage
entity L is
port (D,G : in std_logic;
Q : out std_logic);
end L;

architecture A of L is architecture A of L is
begin begin
process process (D,G)
begin begin
wait on D,G; if G='1' then Q <= D;
if G='1' then Q <= D; end if;
end if; end process;
end process; end A;
end A;
Formation VHDL Circuits séquentiels Vahid MEGHDADI

146
Registre simple (latch synchrone)

Un circuit synchrone sur le front d’un signal (CLK)


entity R is
port (D,CLK: in std_logic; process
Q: out std_logic); begin
end R; wait until CLK'event and CLK='1';
Q <= D;
architecture A of R is
end process;
begin
process
begin process (CLK)
wait on CLK; begin
if CLK='1' then Q <= D; if CLK'event and CLK='1' then
end if; Q <= D;
end process;
end A; end if
end process;
Formation VHDL Circuits séquentiels Vahid MEGHDADI

147
Registre avec SET ou RESET

entity R is
port (D,CLK,SET: in std_logic;
Q: out std_logic);
end R;

architecture A of R is
architecture A of R is
begin -- set synchrone
begin -- set asynchrone
process (CLK)
process (SET,CLK)
begin
begin
if CLK'event and CLK='1' then
if SET = '1' then Q <= '1';
if SET = '1' then Q <= '1';
elsif CLK'event and CLK='1'
else Q <= D;
then Q <= D;
end if;
end if;
end if;
end process;
end process;
end A;
end A;
Formation VHDL Circuits séquentiels Vahid MEGHDADI

148
Exemple 1

E2 E1 E0

D Q D Q D Q

CLK QB CLK QB CLK QB

RAZ

S2 S1 S0

E 2 2 S
D Q
H
CLK QB
RAZ

Formation VHDL Circuits séquentiels Vahid MEGHDADI

149
Exemple 1 (suite)

entity REG is
port (E : in std_logic_vector(2 downto 0);
H,RAZ : in std_logic;
S: out std_logic_vector(2 downto 0));
end REG;
architecture A of REG is
begin
TAMPON : process (H,RAZ)
begin
if RAZ = ‘0’ then
S <= "000";
elsif H’event and H = ‘1’ then
S <= E;
end if;
end process;
end A;
Formation VHDL Circuits séquentiels Vahid MEGHDADI

150
Exercice : registre à décalage série

Entree E2 S2 E1 S1 E0 S0 Sortie
D Q D Q D Q

CLK QB CLK QB CLK QB

RAZ

Entree
S
H

RAZ

Formation VHDL Circuits séquentiels Vahid MEGHDADI

151
Exercice: Registre à décalage série

Formation VHDL Circuits séquentiels Vahid MEGHDADI

152
Exercice : Registre à décalage série

Entree REG2 REG1 REG0


D Q D Q D Q
Sortie
CLK QB CLK QB CLK QB

RAZ

Entree
Sortie
H

RAZ

Formation VHDL Circuits séquentiels Vahid MEGHDADI

153
Exercice : Registre à décalage série 2 (suite)

Formation VHDL Circuits séquentiels Vahid MEGHDADI

154
Exercice : Registre à chargement parallèle et décalage sériel

E2 E1 E0
Sortie
Entree D Q D Q D Q
REG2 REG0
REG1
CLK QB CLK QB CLK QB

RAZ
LOAD

E 3

Entree Sortie
RAZ
H

Formation VHDL Circuits séquentiels Vahid MEGHDADI

155
Exercice : Registre à chargement parallèle et décalage sériel

Formation VHDL Circuits séquentiels Vahid MEGHDADI

156
Attention !

Les instructions suivantes sont


interdites dans une zone concurrente
A <= not A;
CMPT <= CMPT + 1;
REG <= REG (0) & REG(7 downto 1);
…...
+1

Formation VHDL Circuits


Attention
séquentiels
! Vahid MEGHDADI

157
Correction

On utilise un process D Q

synchronisé sur un front CLK


process (CLK)
begin
if rising_edge(CLK) then D Q +1
A <= not A;
-- CMPT <= CMPT + 1; CLK
-- etc;
end if;
end process;

Formation VHDL Circuits


Attention
séquentiels
! Vahid MEGHDADI

158
Attention sur les process synchrones!

Un seul « if » dans un process synchrone

process (CLK)
process (CLK) begin
begin if CLK'event and CLK='1' then
if CLK'event and CLK='1' then Q <= D;
Q <= D; end if
end if end process;

if TOTO=‘1’ then TRUC; process (TOTO)


end if begin
end process; if TOTO=‘1’ then TRUC;
end if
End process

Formation VHDL Circuits séquentiels Vahid MEGHDADI

159
Formation VHDL Vahid MEGHDADI

160
Chapitre : Machine à états finis

•Toute information du passé est sauvegardée dans l’état actuel du circuit

•L’état interne est préservé dans des registres (bascules). Une machine à 5
états comporte au moins 3 bascules.

•L’état prochaine dépend de l’état actuel et des entrées

•Le changement d’état se fait sur le front de l’horloge

•Machine de Moore : les sorties ne dépendent que de l’état courant.

•Machine de Mealy : les sorties dépendent de l’état courant et aussi des


entrées

Formation VHDL Machine à états finis Vahid MEGHDADI

161
Présentation graphique

•Les cercles présentent les états possibles


d’une machine à états finis
E1E2= "11"
•Les flèches représentent les changements
possible s0
E1E2= "10"
•Les conditions sont présentes sur les flèches

•Les changements d’état se réalisent sur le E1E2= "0-"


front de l’horloge s1
s2
•L’horloge est implicite

E1E2= "1-"
Formation VHDL Vahid MEGHDADI

162
Séparation des logiques

Dans un automate synchrone il existe


•une logique combinatoire permettant le calcul de l'état suivant
•une logique combinatoire permettant le calcul des sorties
•une partie synchrone qui se charge du changement d'état du système au
moment voulu.

Deux types de réalisation


•un seul process regroupant les parties combinatoire et séquentielle
•un process pour la partie séquentielle et deux process pour les parties
combinatoires
Formation VHDL Machine à états finis Vahid MEGHDADI

163
Implantation un seul process

État courant
type T_ETAT is (E1, E2, E3);
signal etat : T_ETAT;
... Logique D Q
Process(CLK) ENTREE combinatoire CLK
begin CLK Registre
if CLK'event and CLK='1‘ then
d’états
case etat is
when E1 => -- mise à jour des sorties pour état E1
if <cond> then ETAT <= E3; end if;
when E2 => -- mise à jour des sorties pour état E2
ETAT <= E3
when E3 => -- mise à jour des sorties pour état E3
if <cond> then ETAT <= E1;
elsif <cond> then ETAT <= E2;
end if;
end case;
end if
end process;

Formation VHDL Machine à états finis Vahid MEGHDADI

164
Implantation par des process séparés

Moore Mealy
E1
Fonction
combin- S1
atoire
E2
S2
F

Fonction
combin-
atoire
ETAT_COUR
ETAT_FUTUR Registre
d'états

G H

RAZ

Formation VHDL Machine à états finis Vahid MEGHDADI

165
Programmation logique séparée

•Déclaration des signaux :


signal E1,E2,S1,S2,H,RAZ : std_logic

•Déclaration des états :


type T_ETAT is ETAT1, ETAT2, ETAT3;
signal ETAT_COUR, ETAT_FUTUR : ETAT;

•Avancement dans l’état


REG : process (H, RAZ)
begin
if RAZ = ‘0’ then ETAT_COUR <= ETAT1;
elsif H’event and H = ‘1’ then
ETAT_COUR <= ETAT_FUTUR;
end if;
end process;
Formation VHDL Machine à états finis Vahid MEGHDADI

166
Programmation de la partie combinatoire G

G : process (E1,E2,ETAT_COUR) -- Tous les signaux


-- d’entrée sont dans la liste de sensibilité
begin
case ETAT_COUR is
when ETAT1 =>
-- suivant la valeur de E1 et E2 on
affecte à ETAT_FUTUR une valeur
when ETAT2 =>
-- suivant la valeur de E1 et E2 on
affecte à ETAT_FUTUR une valeur
when ETAT3 =>
-- suivant la valeur de E1 et E2 on
affecte à ETAT_FUTUR une valeur
end case;
end process;

Formation VHDL Machine à états finis Vahid MEGHDADI

167
Programmation de la partie combinatoire F

F : process (E1,E2,ETAT_COUR) -- Tous les signaux


-- d’entrée sont dans la liste de sensibilité
begin
case ETAT_COUR is
when ETAT1 =>
-- suivant la valeur de E1 et E2 on
-- affecte aux sorties les valeurs correspondantes
when ETAT2 =>
-- suivant la valeur de E1 et E2 on
-- affecte aux sorties les valeurs correspondantes
when ETAT3 =>
-- suivant la valeur de E1 et E2 on
-- affecte aux sorties les valeurs correspondantes
end case;
end process;

Formation VHDL Machine à états finis Vahid MEGHDADI

168
Rappels (1)

•Les fonctions F et G peuvent être décrites dans le


même process
•Si le process est synthétisé par un circuit séquentiel
synchronisé sur front d’horloge, il ne doit comporter
dans la liste de sensibilité que l’horloge et
éventuellement une RAZ asynchrone et rien d'autre :
process(CLK,RESET)
begin
if RESET='0' then ……………..
elsif CLK'event and CLK='1' then……………………….
end if;
end process,
Formation VHDL Machine à états finis Vahid MEGHDADI

169
Rappels (2)

•Si le process est synthétisé par un circuit


combinatoire, il doit comporter dans la liste de
sensibilité tous les signaux lus.

•S’il y a test d’un signal dans un process


combinatoire, il doit être complet (ne pas oublier le
else), et toutes les sortie doit être affectées dans
toutes les branches du test.

Formation VHDL Machine à états finis Vahid MEGHDADI

170
Exemple de la partie combinatoire F

F : process (E1,E2,ETAT_COUR) -- Tous les signaux


-- d’entrée sont dans la liste de sensibilité
begin
case ETAT_COUR is
when ETAT1 =>
if E1 = '0' and E2 = '0' then
S1 <= ‘0’; S2 <= ‘0’;
elsif E1 = ’1 ’ then
S1 <= ‘1’ ; S2 <= ‘0’;
else S1 <= ‘0’; S2 <= ‘1’;
end if;
when ETAT2 => -- S1 et S2 <= …...
when ETAT3 => -- S1 et S2 <= …...
end case;
end process;

Formation VHDL Machine à états finis Vahid MEGHDADI

171
Exemple de la partie combinatoire F

CLK HS

fclk=25MHz

Formation VHDL Vahid MEGHDADI

172
Conception RTL

HS <= '1' when etat_cour = PW else '0';


Formation VHDL Vahid MEGHDADI

173
Programme VHDL

FSM: process(etat_cour, count) when others => type t_etat is (PW, BP, DISP, FP);
begin if count = 0 then
case etat_cour is signal etat_cour, etat_futur : t_etat:=PW;
etat_futur <= PW;
when PW => else
if count = 96 then etat_futur <= FP;
etat_futur <= BP; end if;
else end case;
etat_futur <= PW; end process;
end if;
when BP =>
if count = 144 then
etat_futur <= DISP;
else
etat_futur <= BP;
end if;
when DISP =>
if count = 784 then
etat_futur <= FP;
else
etat_futur <= DISP;
end if;

Formation VHDL Vahid MEGHDADI

174
Formation VHDL Vahid MEGHDADI

175
Chapitre : Exemples

process(CLK)
begin
if CLK’event and CLK=‘1’ then
REG <= REG(0) & REG(7 downto 1); -- rotate right
REG <= ‘0’ & REG(7 downto 1); -- shift right logical
REG <= REG(7) & REG(7 downto 1);
end if;
end process

Les valeurs signées


Z <= (X(7) & X(7 downto 0)) + (Y(7) & Y(7 downto 0));

Les valeurs non signées


Z <= (‘0’ & X(7 downto 0)) + (‘0’ & Y(7 downto 0));

Formation VHDL Vahid MEGHDADI

176
Exemple 1: Timer

Exemple 1

CLK
Down counter

Vcc

D IRQ*
Q*
D_FF
CLK

RSET*

Formation VHDL Exemples Vahid MEGHDADI

177
Exemple 1 suite : Bascule D

entity D_FF is
Port ( CLK : in std_logic;
RESET : in std_logic;
D : in std_logic;
Q_BAR : out std_logic);
end D_FF;

architecture FPGA of D_FF is


begin
process (CLK, RESET)
begin
if RESET = '0' then --asynchronous RESET active High
Q_BAR <= '0';
elsif (CLK'event and CLK='1') then --CLK rising edge
Q_BAR <= not D;
end if;
end process;
end FPGA;

Formation VHDL Exemples Vahid MEGHDADI

178
Exemple 1 suite : Down counter

entity DOWN_COUNTER is
Port ( CLK,RESET : in std_logic;
COUNT : buffer std_logic_vector(3 downto 0));
end DOWN_COUNTER;

architecture FPGA of DOWN_COUNTER is


begin
process (CLK, RESET)
begin
if RESET='1' then
COUNT <= "0000";
elsif CLK='1' and CLK'event then
COUNT <= COUNT - 1;
end if;
end process;
end FPGA;

Formation VHDL Exemples Vahid MEGHDADI

179
Exemple 1 suite : Circuit complet (1)

entity test2 is
Port ( CLK_IN,ACK, RESET : in std_logic;
IRQ : out std_logic);
end test2;

architecture Behavioral of test2 is


component D_FF
Port ( CLK : in std_logic;
RESET : in std_logic;
D : in std_logic;
Déclaration Q_BAR : out std_logic);
end component;
des components
component DOWN_COUNTER
Port ( CLK,RESET : in std_logic;
COUNT : buffer std_logic_vector(3 downto 0));
end component;

signal COUNT : std_logic_vector(3 downto 0);


signal OR_OUT : std_logic;
Formation VHDL Exemples Vahid MEGHDADI

180
Exemple 1 suite : Circuit complet (2)

begin
FLIP_FLOP: D_FF port map (
CLK => OR_OUT,
RESET => ACK,
D => '1',
Q_BAR => IRQ
Instantiation );

des components DOWN : DOWN_COUNTER port map(


CLK => CLK_IN,
RESET => RESET,
COUNT => COUNT
);

OR_OUT <= COUNT(0) or COUNT(1) or COUNT(2) or COUNT(3);

end Behavioral;

Formation VHDL Exemples Vahid MEGHDADI

181
Exemple 2

Il nous faut la synthèse d’un feu tricolore. Le feu


rouge 30 secondes, le vert 26 secondes et l’orange 4
seconde. L’entrée du système est une horloge de
fréquence 1 Hz.

R
CLK
O
RAZ V

Formation VHDL Exemples Vahid MEGHDADI

182
Entité

L’entité du circuit est la suivante :

entity FEU3COL is
Port ( CLK : in std_logic;
RAZ : in std_logic;
R : out std_logic;
V : out std_logic;
O : out std_logic);
end FEU3COL;

Formation VHDL Exemples Vahid MEGHDADI

183
Architecture (1)

architecture COMPORT of FEU3COL is


type T_ETAT is (ROUGE, ORANGE, VERT);
signal ETAT : T_ETAT;
begin
process (CLK)
variable CMPT : integer range 0 to 31;
begin
if CLK'event and CLK='1' then
if RAZ = ‘1’ then
CMPT := 0;
ETAT <= ROUGE;
else
CMPT := CMPT+1;
case ETAT is
when ROUGE =>
if CMPT = 30 then
CMPT := 0;
ETAT <= VERT;
end if;

Formation VHDL Exemples Vahid MEGHDADI

184
Architecture (2)

when VERT =>


if CMPT = 26 then
CMPT := 0;
ETAT <= ORANGE;
end if;
when ORANGE =>
if CMPT = 4 then
CMPT := 0;
ETAT <= ROUGE;
end if;
when others =>
ETAT <= ROUGE;
end case;
end if;
end process;
R <= '1' when ETAT=ROUGE else '0';
O <= '1' when ETAT=ORANGE else '0';
V <= '1' when ETAT=VERT else '0';
end COMPORT;

Formation VHDL Exemples Vahid MEGHDADI

185
Rapport de mapping

Le résultat de mapping sur un spartan 2E : XC2s200

Selected Device : 2s200epq208-6

Number of Slices: 11 out of 2352 0%


Number of Slice Flip Flops: 8 out of 4704 0%
Number of 4 input LUTs: 18 out of 4704 0%
Number of bonded IOBs: 4 out of 146 2%
Number of GCLKs: 1 out of 4 25%

Formation VHDL Exemples Vahid MEGHDADI

186
Utilisation des process séparés

Formation VHDL Vahid MEGHDADI

187
Utilisantion des process séparés

process(etat, cmp)
process(CLK)
begin
begin
raz <= '0';
if CLK'event and CLK='1' then
next_etat <= etat;
if RESET = '1' or raz = '1' then
case etat is
cmp <= 0;
when rouge =>
else
if cmp = 3 then
cmp <= cmp + 1;
next_etat <= vert;
end if;
raz <= '1';
end if;
end if;
end process;
when orange =>
if cmp = 0 then
process(CLK)
next_etat <= rouge;
begin
raz <= '1';
if CLK'event and CLK='1' then
end if;
if RESET = '1' then
when others =>
etat <= rouge;
if cmp = 2 then
else
next_etat <= orange;
etat <= next_etat;
raz <= '1';
end if;
end if;
end if;
end case;
end process;
end process;
Formation VHDL Vahid MEGHDADI

188
Exemple 3

Gestion d’un clavier

Clavier

FPGA
CODE LIN

COL

Formation VHDL Exemples Vahid MEGHDADI

189
Entité

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity main is
Port ( RESET, CLK : in std_logic;
COL : in std_logic_vector(2 downto 0);
LIN : buffer std_logic_vector(3 downto 0);
CODE : out std_logic_vector(6 downto 0));
end main;

architecture Behavioral of main is

type T_ETAT is (LIN1, LIN2, LIN3, LIN4);


signal ETAT, NEXT_ETAT : T_ETAT;
signal COMB : std_logic_vector(6 downto 0);

Formation VHDL Exemples Vahid MEGHDADI

190
Partie combinatoire

begin
process (ETAT)
begin
case ETAT is
when LIN1 => NEXT_ETAT <= LIN2;
LIN <= "0111";
when LIN2 => NEXT_ETAT <= LIN3;
LIN <= "1011";
when LIN3 => NEXT_ETAT <= LIN4;
LIN <= "1101";
when LIN4 => NEXT_ETAT <= LIN1;
LIN <= "1110";
end case;
end process;

COMB <= LIN & COL;

Formation VHDL Exemples Vahid MEGHDADI

191
Partie machine à état

process (RESET, CLK)


begin
if RESET='1' then ETAT <= LIN1;
elsif CLK'event and CLK = '1' then
ETAT <= NEXT_ETAT;
end if;
end process;

Formation VHDL Exemples Vahid MEGHDADI

192
Partie décodage

DECODE: process (COMB)


begin
case COMB is
when "0111011" => CODE <= "0000110"; --1
when "0111101" => CODE <= "1011011"; --2
when "0111110" => CODE <= "1001111"; --3
when "1011011" => CODE <= "1100110"; --4
when "1011101" => CODE <= "1101101"; --5
when "1011110" => CODE <= "1111101"; --6
when "1101011" => CODE <= "0000111"; --7
when "1101101" => CODE <= "1111111"; --8
when "1101110" => CODE <= "1101111"; --9
when "1110011" => CODE <= "1110110"; --#
when "1110101" => CODE <= "0111111"; --0
when "1110110" => CODE <= "1110110"; --*
when others => CODE <= "0000000";
end case;
end process;
Formation VHDL Exemples Vahid MEGHDADI

193
Exemple 4, affichage multiplexé

Formation VHDL Vahid MEGHDADI

194
Préparation de l’horloge

Horloge de la carte est à 100 MHz


Supposons qu’une horloge à approximativement 50 KHz est nécessaire:
Une division par : 100 x 106 / 50 x 103 = 2000
Programme VHDL
CLK_EN_Gene : Process(CLK)
Begin
if CLK’event and CLK=‘1’ then CLK_EN
CLK_EN <= ‘0’; CLK
cmp <= cmp + 1; CLK CLK_EN
if cmp = 1999 then
CLK_EN <= ‘1’; CLK_EN_Gene
cmp <= 0;
end if;
end if;
End process;
cmp

Formation VHDL Vahid MEGHDADI

195
Machine à états

type T_ETAT is (SEG1, SEG2, SEG3, SEG4);


signal etat : T_ETAT;

process(CLK) -- une autre alternative


begin
if CLK’event and CLK=‘1’ then signal etat : integer range 0 to 3;
if CLK_EN = ‘1’ then
case ETAT is
when SEG1 => etat <= SEG2; process(CLK)
when SEG2 => etat <= SEG3; begin
when SEG3 => etat <= SEG4; if CLK’event and CLK=‘1’ then
when SEG4 => etat <= SEG1; etat <= etat + 1;
when others => etat <= SEG1; end if;
end case; end process;
end if;
end if;
end process;

Formation VHDL Vahid MEGHDADI

196
Circuit complet

with etat select with HEX select


An <= "0111" when SEG1,
SEG<= "1111001" when "0001", --1
"1011" when SEG2,
"0100100" when "0010", --2
"1101" when SEG3,
"0110000" when "0011", --3
"1110" when others;
"0011001" when "0100", --4
"0010010" when "0101", --5
with etat select
"0000010" when "0110", --6
HEX <= "0001" when SEG1,
"1111000" when "0111", --7
"1001" when SEG2,
"0000000" when "1000", --8
"0100" when SEG3,
"0010000" when "1001", --9
"0101" when others;
"0001000" when "1010", --A
"0000011" when "1011", --b
"1000110" when "1100", --C
"0100001" when "1101", --d
"0000110" when "1110", --E
"0001110" when "1111", --F
"1000000" when others; --0

Formation VHDL Vahid MEGHDADI

197
Exemple 5

Exemple d’un additionneur à 8 bits utilisant des


additionneurs complets
00111100
10011010
Optimisation vitesse + 10110110
01010000
y y0 y1 y7
x0 x1 x7
x a1 b1 a1 b1 a1 b1
0 Cin Cout Cin Cout Cin Cout C
s s s

z z0 z1 z7

Formation VHDL Exemples Vahid MEGHDADI

198
En VHDL

component FULL_ADD
port(A,B,CIN : in std_logic;
S,COUT : out std_logic);
end component;

BIT0 : FULL_ADD port map (X(0) , Y(0) , ’0’ , Z(0) , C(0));


BIT1 : FULL_ADD port map (X(1) , Y(1) , C(0) , Z(1) , C(1));
….
BIT7 : FULL_ADD port map (X(7) , Y(7) , C(6) , Z(7) , C(7));

Remarque : étant une instruction séquentielle,


l’instruction « FOR ... LOOP » n’est pas utilisable.
Par contre on peut utiliser l’instruction generate.
On peut faire bien sûr d’une manière plus simple et plus optimale :
Z <= X+Y;
Formation VHDL Exemples Vahid MEGHDADI

199
Structure à partage de ressources

Optimisation surface
x y
8 8
LOAD
Reg à décal

Reg à décal
a1 b1
D Q Cin s Reg à décal
Cout
CLK 8
z

CLK

Formation VHDL Exemples Vahid MEGHDADI

200
Solution

entity test is
Port ( X,Y : in STD_LOGIC_VECTOR (7 downto 0);
Z : out STD_LOGIC_VECTOR (7 downto 0);
CLK, LOAD : in STD_LOGIC);
end test;

architecture Behavioral of test is


component full_add
port(A,B,CIN : in std_logic;
S,COUT : out std_logic);
end component;
signal reg_x, reg_y, reg_z : std_logic_vector(7 downto 0):=(others => '0');
signal reg_z_in : std_logic:='0';
signal d:std_logic:='0';
signal q:std_logic:='0';
begin
FULL_ADDER: full_add port map(
reg_x(0), reg_y(0), q, reg_z_in, d);

Formation VHDL Vahid MEGHDADI

201
Solution (suite)

process(CLK, LOAD)
begin
if CLK'event and CLK='1' then
if LOAD = '1' then
reg_x <= X; reg_y <= y;
else reg_x <= '0' & reg_x(7 downto 1);
reg_y <= '0' & reg_y(7 downto 1);
end if;
end if;
end process;
process (CLK)
begin
if CLK'event and CLK='1' then q <= d;
end if;
end process;
process(CLK)
begin
if CLK'event and CLK='1' then
reg_z <= reg_z_in & reg_z(7 downto 1);
end if;
end process;

Z <= reg_z;

end Behavioral;
Formation VHDL Vahid MEGHDADI

202
Chronogramme

Le résultat est prêt après 8 coups d’horloge

Formation VHDL Vahid MEGHDADI

203
Exemple 6- UART en émission

Le but est de réaliser l’émetteur de l’UART avec les


caractéristiques suivantes:
-8 bits de data
-Deux bit de stop à 1
-Un bit de start à 0
-Pas de parité
-Vitesse d’émission à 19200

Formation VHDL Vahid MEGHDADI

204
Exemple 6- UART en émission

Formation VHDL Vahid MEGHDADI

205
Exemple 7- CNA AD5541A

Pour que le CNA produit une tension analogique à partir


d’une donnée de 16 bits, il faudra respecter le timing donné
par le constructeur.
Formation VHDL Vahid MEGHDADI

206
Exemple 7- AD5541A Timing Diagram

Générer une horloge à f=1/t1

DIN change sur le front


descendant de SCLK
Génération de CS

Génération de LDAC

La donnée est à envoyée en série (MSB d’abord)

Formation VHDL Vahid MEGHDADI

207
Exemple 7- AD5541A contraintes de Timing

Fclk=25MHz

On fixe à 1/25MHz=40ns

Formation VHDL Vahid MEGHDADI

208
Exemple 7- Interface CNA

Le but est de créer l’interface CNA pour simplifier le dialogue


avec le CAN. Ainsi, pour dialoguer avec l’interface, on n’aura
qu’un bus de 16 bits et un signal STRB (Strobe).

Formation VHDL Vahid MEGHDADI

209
Exemple 7- Conception

Une machine à état


- État repos (CS<=‘0’; DIN <= ‘Z’; LDAC <= ‘1’);
- Dès qu’on détecte ‘1’ sur STRB
- on envoie ‘1’ sur CS
- État change en envoie
- On envoie les 16 bits de DATA un par un (MSB d’abord)
- 16 bits envoyés, on attend une période d’horloge (état
tempo)
- Etat fin pour finaliser (LDAC <= ‘1’)

Formation VHDL Vahid MEGHDADI

210
Exemple 7- Programmation un seul process

when envoi =>


signal cmp : integer range 0 to 15;
CS <= '0';
signal reg : std_logic_vector (15 downto 0);
DIN <= reg(cmp);
type T_etat is (repos, envoi, tempo, fin);
cmp <= cmp - 1;
signal etat : T_etat := repos;
if cmp = 0 then
process(CLK)
etat <= tempo;
begin
end if;
if CLK'event and CLK='0' then
when tempo =>
case etat is
DIN <= 'Z';
when repos =>
CS <= '1';
CS <= '1';
etat <= fin;
LDAC <= '0';
when others => -- etat = fin
cmp <= 15;
LDAC <= '1';
DIN <= 'Z';
cmp <= 15;
if STRB = '1' then
etat <= repos;
reg <= DATA;
end case;
etat <= envoi;
end if;
end if;
Formation VHDL end process; Vahid MEGHDADI

211
Exemple 7- Conception robuste

Formation VHDL Vahid MEGHDADI

212
Exemple 7- Résultat de simulation

Formation VHDL Vahid MEGHDADI

213
Exemple 7- Programme

process(CLK)
entity AD5541A is begin
Port ( CLK : in STD_LOGIC; if CLK'event and CLK='1' then
DATA : in STD_LOGIC_VECTOR (15 downto 0); if STRB = '1' then
STRB : in STD_LOGIC; reg <= DATA;
CS : out STD_LOGIC; end if;
DIN : out STD_LOGIC; end if;
LDAC : out STD_LOGIC; end process;
SCLK : out STD_LOGIC);
end AD5541A; process(CLK)
begin
architecture Behavioral of AD5541A is if CLK'event and CLK='1' then
type t_etat is (repos, e_cs, envoie, tempo, e_ldac); etat_cour <= etat_futur;
signal etat_cour, etat_futur : t_etat:= repos; end if;
signal count : integer range 0 to 31:=0; end process;
signal raz : std_logic;
signal reg : std_logic_vector(15 downto 0); process(CLK)
Begin begin
if CLK'event and CLK='1' then
SCLK <= not CLK; if raz = '1' then
DIN <= reg(16-count) when etat_cour = envoie else 'Z'; count <= 0;
CS <= '1' when etat_cour = e_CS else '0'; else
LDAC <= '0' when etat_cour=e_ldac else '1'; count <= count + 1;
end if;
end if;
end process;
Formation VHDL Vahid MEGHDADI

214
Exemple 7- Programme

process(etat_cour, count, STRB)


begin
etat_futur <= etat_cour;
raz <= '0';
case etat_cour is when tempo =>
when repos => if count = 17 then
raz <= '1'; etat_futur <= e_ldac;
if STRB = '1' then end if;
etat_futur <= e_cs;
end if; when others => -- ldac
if count = 18 then
when e_cs => etat_futur <= repos;
if count = 0 then end if;
etat_futur <= envoie;
end if; end case;
end process;
when envoie =>
if count = 16 then end Behavioral;
etat_futur <= tempo;
end if;

Formation VHDL Vahid MEGHDADI

215
Chapitre : Notions avancés

Notions
avancés
Formation VHDL Vahid MEGHDADI

216
Généricité

C’est un moyen de transmettre des infos à un bloc pour


le rendre un bloc paramétrable.

Exemples : une porte ET à N entrées, un registre à


décalage de taille N, un multiplexeur N vers 1, …

Syntaxe :
generic (param1 : type de param1 := valeur par défaut;
param2 : type de param2 := valeur par défaut;
...);

Formation VHDL Généricité Vahid MEGHDADI

217
Exemple

Porte ET à N entrées :
entity PORTE_ET is
generic(N : integer := 2);
port(ENTREE : in std_logic_vector(1 to N);
SORTIE : out std_logic);
end entity;

process (ENTREE)
variable V : std_logic;
begin
V := '1';
for I in 1 to N loop
V := V and ENTREE(I);
end loop;
SORTIE <= V;
end process;

Formation VHDL Généricité Vahid MEGHDADI

218
Appel d’un bloc paramétrable

component PORTE_ET
generic(N :integer := 2);
port(ENTREES : in std_logic_vector(1 to N);
SORTIE : out std_logic);
end component;

architecture A of B is
begin

INST : PORTE_ET generic map(N => 5)


port map(ENTREES => A,
SORTIE => Z);

end A;

Formation VHDL Généricité Vahid MEGHDADI

219
Paquetage

•Il donne la possibilité de regrouper des parties


communes pour le travail d'une équipe
•Présente des types et des sous-types
•Présente des objets (signaux, constants)
•Présente la déclaration des sous-programmes
•On peut y déclarer des alias

Formation VHDL Paquetage Vahid MEGHDADI

220
Syntaxe de Paquetage

Package <nom_de_paquetage> is
suite de déclarations>
end {<nom_de_paquetage>};

package pak_test is

subtype OCTET is std_logic_vector(7 downto 0);


subtype MOT is std_logic_vector(15 downto 0);
Exemple:
constant PAQUET_SIZE : integer := 11;

function INT_TO_7SEG (constant CHIFFRE :


in std_logic_vector(3 downto 0)) return OCTET;
end pak_test;

Formation VHDL Paquetage Vahid MEGHDADI

221
Paquetage de composants

Le paquetage permet aussi de grouper la déclaration d'un


ensemble de composants.
Exemple :
package STANDARD_CELL is
component INVERSEUR
port (E : in bit; S : out bit);
end component;
component PORTE_OU
port (A,B : in bit; S : out bit);
end component;
….
end STANDARD CELL;

Formation VHDL Paquetage Vahid MEGHDADI

222
Corps de Paquetage

Décrit l'algorithme des sous-programmes du paquetage.


Ces algorithmes sont lisibles grâce au paquetage.
Syntaxe :
package body <nom_de_paquetage> is
{corps de sous-programmes}
end <nom_de_paquetage>;

Formation VHDL Paquetage Vahid MEGHDADI

223
Exemple de Corps de Paquetage

package body pak_test is

function INT_TO_7SEG (constant CHIFFRE : in std_logic_vector


(3 downto 0)) return OCTET is
variable SEG : std_logic_vector(7 downto 0);
begin
case CHIFFRE is
when "0001" => SEG := "01111001" ; --1
when "0010" => SEG := "00100100" ; --2
…….
when "1111" => SEG := "00001110" ; --F
when others => SEG := "01000000" ; --0
end case;
return SEG;
end INT_TO_7SEG;

end pak_test;
Formation VHDL Paquetage Vahid MEGHDADI

224
Utilisation de paquetage

•On crée d'abord une librairie


•Sous ISE, new source --> VHDL library
•Ecrire le paquetage et son corps
•Ajouter à la librairie que l'on souhaite
•Sous ISE, sélectionner le fichier et ensuite--> move
to library
•Dans le programme utilisant cette librairie :
library <mon_lib>
use <mon_lib>.<mon_paquetage>

Formation VHDL Paquetage Vahid MEGHDADI

225
Configuration

Une entité peut avoir plusieurs architectures


Un rôle de configuration : choisir l'architecture
correspondante
Exemple : Pour l'entité additionneur on peut
envisager 3 architectures différentes : A, B et C
ADDITIONNEUR(A)
ADDITIONNEUR(B)
ADDITIONNEUR(C)
A chaque instanciation de l'entité, un seul couple
entité/architecture peut être compilé.
Formation VHDL Configuration Vahid MEGHDADI

226
Choix de l'architecture

Deux façons pour relier une architecture précise à une


entité :
•Dans une unité de compilation autonome : la
configuration
•Dans la partie déclarative d'un bloc ou d'une
architecture (configuration "à la volée")
(Par défaut c'est la dernière compilée qui sera prise en
compte)

Formation VHDL Configuration Vahid MEGHDADI

227
Exemple de Configuration

Entity SIM is end;


architecture ESSAI1 of SIM is
component ADD
Entity ADD is port (A,B : in integer;
S : out integer);
port (A,B : in integer; end component;
S : out integer); signal X,Y,SUM : integer;
end ADD; begin
INST1 : ADD port map (X,Y,SUM);
architecture FONCTION of ADD is X <= 12, 55 after 100 ns;
Y <= 0, 100 after 200 ns;
begin end ESSAI1;
S <= A+B; configuration CONF of SIM is
end FONCTION; for ESSAI1
for INST1 : ADD
use entity work.ADD(FONCTION)
end for;
end for;
end CONF;
Formation VHDL Configuration Vahid MEGHDADI

228
Exemple de Configuration "à la volée"

Entity SIM is end;


architecture ESSAI1 of SIM is
component ADD
Entity ADD is port (A,B : in integer;
port (A,B : in integer; S : out integer);
S : out integer); end component;
end ADD; for all : ADD
use entity work.ADD(FONCTION);
-- ou
architecture FONCTION of ADD is -- for INST2 : ADD
begin -- use entity work.ADD(FONCTION);
S <= A+B;
signal X,Y,SUM : integer;
end FONCTION;
begin
INST2 : ADD port map (X,Y,SUM);
X <= 12, 55 after 100 ns;
Y <= 0, 100 after 200 ns;
end ESSAI1;
Formation VHDL Configuration Vahid MEGHDADI

229
Les sous-programmes

But des sous-programmes


•Pour écrire des algorithmes réutilisables
•Pour augmenter la lisibilité
Deux classes des sous-programmes
•Les procédures
•Les fonctions

Formation VHDL Les sous-programmes Vahid MEGHDADI

230
Procédure

•Mot clé procedure


•L'appel d'une procédure est une instruction (concurrente
ou séquentielle)
•Peut retourner plusieurs valeurs
•Peut agir sur les signaux globaux
•Peut se synchroniser (avec wait dedans)
•Corps d'une procédure est une zone séquentielle

Formation VHDL Les sous-programmes Vahid MEGHDADI

231
Fonction

•Mot clé function


•L'appel est à droite d'une affectation
•L'appel peut se faire dans la zone concurrente ou
séquentielle
•Retourne une seule valeur
•Rend immédiatement sa valeur
•Corps d'une fonction est une zone séquentielle

Formation VHDL Les sous-programmes Vahid MEGHDADI

232
Ecriture des sous-programmes

Un sous-programme est constitué


•D'une déclaration : interface
•D'un corps : algorithme

Syntaxe de la déclaration
•procedure <nom> (liste des paramètre);
•function <nom> (liste des paramètre) return type_du_résultat;

Formation VHDL Les sous-programmes Vahid MEGHDADI

233
Déclaration des sous-programmes

Liste_des_paramètre :
{classe_d'objet} PARAM1 :{mode} type{:=valeur_par_défaut}
•class_d'objet : signal, variable, constant
•mode : in, out, inout

Restriction
•pas de paramètres out ou inout dans la déclaration d'une
fonction
•pas de variable transmise à une fonction
•classe d'objet par défaut est "constant" pour les "in" et
"variable" pour les "out" et "inout"
Formation VHDL Les sous-programmes Vahid MEGHDADI

234
Corps de sous-programme

Entête is -- function ou procedure


{zone de déclarations}
begin
{partie instruction séquentielle}
end {nom_de_sous-programme}

Exemple
function MIN (signal A,B : integer) return integer is
begin
if A < B then return A
else return B
end if;
end MIN;

Formation VHDL Les sous-programmes Vahid MEGHDADI

235
Appel de sous-programme

Différentes formes d'appel


•Par position (même ordre que la déclaration)
•RESULTAT <= MIN (SIG1, 5);
•Par nom (ordre non important)
•RESULTAT <= MIN (B=> 5, A=> SIG1);
•RESULTAT <= MIN (A=> SIG1, B=> 5);

Formation VHDL Les sous-programmes Vahid MEGHDADI

236
Exemple

-- HEX-to-seven-segment decoder
-- HEX: in STD_LOGIC_VECTOR (3 downto 0);
-- LED: out STD_LOGIC_VECTOR (6 downto 0);
--
-- segment encoding
-- 0
-- ---
-- 5 | | 1
-- --- <- 6
-- 4 | | 2
-- ---
-- 3

Formation VHDL Exemples Vahid MEGHDADI

237
Programmation concurrente

with HEX select


LED<= "1111001" when "0001", --1
"0100100" when "0010", --2
"0110000" when "0011", --3
"0011001" when "0100", --4
"0010010" when "0101", --5
"0000010" when "0110", --6
"1111000" when "0111", --7
"0000000" when "1000", --8
"0010000" when "1001", --9
"0001000" when "1010", --A
"0000011" when "1011", --b
"1000110" when "1100", --C
"0100001" when "1101", --d
"0000110" when "1110", --E
"0001110" when "1111", --F
"1000000" when others; --0

Formation VHDL Exemples Vahid MEGHDADI

238
Utilisation de fonction

function DECODE (signal HEX: std_logic_vector(3 downto 0))


return std_logic_vector(6 downto 0) is
begin
case HEX is
when "0001" => return "1111001"; --1
when "0010" => return "0100100"; --2
when "0011" => return "0110000"; --3
when "0100" => return "0011001"; --4
when "0101" => return "0010010"; --5
when "0110" => return "0000010"; --6
when "0111" => return "1111000"; --7
when "1000" => return "0000000"; --8
when "1001" => return "0010000"; --9
when "1010" => return "0001000"; --A
………...
when others => return "00000001"; -- rien afficher
end case;
end;
Formation VHDL Exemples Vahid MEGHDADI

239
Les Attributs

•Attribut sur les signaux:


•signal_name'attribut
•l'attribut synthétisable : event
•wait until CLK'event and CLK='1';

•attribut sur le type array


•type MYARR is array (-2 to 4) of integer;
•MYARR’left returns -2
•MYARR’right 4
•MYARR’high 4
•MYARR'low -2
•MYARR’reverse_range 4 downto to -2

Formation VHDL Les Attributs Vahid MEGHDADI

240
Alias

Intérêt
•Donne un nom différent à un objet
•l'ancien nom reste utilisable
Syntaxe
•alias nouveau_nom : type_ou_sous_type is ancien_nom
Exemple
variable V32 : std_logic_vector (0 to 31);
alias P_8 : std_logic_vector (0 to 7) is V23(0 to 7);
alias D_8 : std_logic_vector (0 to 7) is V32(24 to 31);
alias SIGNE : std_logic is V32(0);
...
SIGNE := '1'; -- identique que V32(0) <= ‘1’;
Formation VHDL Alias Vahid MEGHDADI

241
Encodage d'état dans une machine à état

•Encodage d'états peut se faire manuellement :


type t_etat is (S1, S2, S3, S4, S5);
-- encodage binaire
attribute enum_code : string;
attribute enum_code of t_etat : type is "000 001 010 011 100";
-- S1 est codé en "000", S2 en "001", S3 en "011" et …
signal etat : t_etat;

•On peut laisser le compilateur choisir le codage


type t_etat is (S1, S2, S3, S4, S5);
signal etat : t_etat;

Formation VHDL Encodage d'état dans une machine à état Vahid MEGHDADI

242
Codage one-hot

La méthode préférée pour les circuits énormes est le codage


one-hot
type t_etat is (S1, S2, S3, S4, S5);
-- encodage binaire
attribute enum_code : string;
attribute enum_code of t_etat : type is "00001 00010 00100 01000
10000";
-- S1 est codé en "00001", S2 en "00010", S3 en "00100" et …
signal etat : t_etat;

Ne pas oublier d'initialiser l'état avec un signal RESET

Formation VHDL Encodage d'état dans une machine à état Vahid MEGHDADI

243
If Generate

If-generate permet de architecture A of generate_test is


signal clk_r : std_logic:= '1';
synthétiser un circuit begin
suivant une condition U1: if CLK_DIV generate
process(CLK)
begin
Exemple : if CLK'event and CLK='1' then
clk_r <= not clk_r;
end if;
entity generate_test is end process;
generic ( CLK_DIV : boolean :=TRUE); end generate;
Port ( CLK : in std_logic;
U2: if not CLK_DIV generate clk_r <= clk;
sortie : out std_logic); end generate;
end generate_test;
sortie <= clk_r;

end A;
Formation VHDL If generate Vahid MEGHDADI

244
for Generate

for-generate permet de répéter un circuit plusieurs fois.


Exemple :
BIT0 : FULL_ADD port map (X(0) , Y(0) , ’0’ , Z(0) , C(0));
BIT1 : FULL_ADD port map (X(1) , Y(1) , C(0) , Z(1) , C(1));
….
BIT7 : FULL_ADD port map (X(7) , Y(7) , C(6) , Z(7) , C(7));

LABEL : for i in 1 to 7 generate


ADDITION : FULL_ADD port map (X(i), Y(i), C(i-1), Z(i), C(i);
end generate
BIT0: FULL_ADD port map (X(0) , Y(0) , ’0’ , Z(0) , C(0));
Formation VHDL For generate Vahid MEGHDADI

245
Formation VHDL Vahid MEGHDADI

246
Formation VHDL Vahid MEGHDADI

247
Conseils de synthèse

•Utiliser le nom du fichier le même que le nom de l'entité


•Ne pas mettre plus d'un couple entity/architecture dans un
fichier
•les noms des signaux peuvent être jusqu'à 256 caractères.
Ne pas hésiter de donner un nom signifiant à des signaux
(constant, variable, type, etc)
•Quand vous appelez un component, utilisez les paramètres
de passage par nom :
•U1 : HALF_ADD port map(A =>oper1, B=>oper2, SUM =>somme,
C=>retenue);

Formation VHDL Conseils de synthèse Vahid MEGHDADI

248
Conseils (2)

•Ne jamais utiliser des signaux ou des variables pour des


constantes. (cela gaspille les ressources énormément)

•Xilinx recommande de n'utiliser que les std_logic pour les


types des ports dans les entités.

•Eviter, si c'est possible, l'utilisation de "buffer" pour les


signaux de sortie qui sont lus dans l'architecture. A la place,
déclarer un signal interne avec la même valeur et utiliser "out"
pour le signal de sortie
Formation VHDL Conseils de synthèse Vahid MEGHDADI

249
Conseils (3)

•Privilégier l'utilisation des signaux par rapport aux


variables

•Les instructions wait for xx ns, et after xx ns ne se


synthétise pas

•Les valeurs initiales ne sont normalement pas tenue


compte :
•variable/signal SUM : std_logic_vector(3 downto 0) := "1100";

Formation VHDL Conseils de synthèse Vahid MEGHDADI

250
Ordre des opérations

Ordre dans une expression arithmétique


ADD <= A1 + A2 + A3 + A4;
ADD <= (A1+A2) + (A3+A4)

Donnent le même résultat mais pas forcement le même circuit


A1
A2
A3 ADD
A4

A1
A2 ADD
A3 Un circuit plus rapide
A4
Formation VHDL Conseils de synthèse Vahid MEGHDADI

251
"if" ou "case", la différence

Pour un circuit de décodage, "if" produit


un circuit à priorité tandis que "case", un
circuit équilibré
•Utiliser "case" pour un décodage architecture A of if_ex is
begin
complexe IF_PRO: process (SEL,A,B,C,D)
begin
•Utiliser "if" pour favoriser les chemins if (SEL=”00”) then MUX_OUT <= A;
elsif (SEL=”01”) then MUX_OUT <= B;
lents elsif (SEL=”10”) then MUX_OUT <= C;
elsif (SEL=”11”) then MUX_OUT <= D;
else MUX_OUT <= '0';
entity if_ex is end if;
port (SEL: in std_logic_vector(1 downto 0); end process; --END IF_PRO
A,B,C,D: in std_logic; end BEHAV;
MUX_OUT: out std_logic);
end if_ex;

Formation VHDL Conseils de synthèse Vahid MEGHDADI

252
Circuit résultant

Formation VHDL Conseils de synthèse Vahid MEGHDADI

253
Utilisant "case"

architecture BEHAV of case_ex is


begin
CASE_: process (SEL,A,B,C,D)
begin
entity case_ex is case SEL is
port (SEL: in std_logic_vector when “00” => MUX_OUT <= A;
(1 downto 0); when “01” => MUX_OUT <= B;
A,B,C,D: in std_logic; when “10” => MUX_OUT <= C;
MUX_OUT: out std_logic); when “11” => MUX_OUT <= D;
end case_ex; when others=> MUX_OUT <= '0';
end case;
end process;
end BEHAV;

Formation VHDL Conseils de synthèse Vahid MEGHDADI

254
Circuit résultant

Formation VHDL Conseils de synthèse Vahid MEGHDADI

255
Génération des latch

Une instruction "if" incomplet synthétise un latch :


if A=B then C <= '1';
end if;

Si ce n'est pas ce que l'on souhaite, il faut ajouter la branche


else.
Si on souhaite générer un registre et non pas un latch, on
peut sensibiliser le process à un front (montant par
exemple) d'une horloge.

Formation VHDL Conseils de synthèse Vahid MEGHDADI

256
Partage des ressources

Process (A,B,C,COND) COND


Variable Z1,Z1;
begin
Z1 := A+B; B
Z2 := A+C;
if COND='1' then A
Z <= Z1;
else Z <= Z2; C
end if;
end process;
COND
Process (A,B,C,COND)
variable TMP :...
begin
B
if COND='1' then
TMP := B;
else TMP := C;
end if; C
C <= TMP + A;
end process; A
Formation VHDL Conseils de synthèse Vahid MEGHDADI

257
Validation d'horloge

Eviter de générer l'horloge dans un circuit combinatoire


gate_clk<= (IN1 and IN2 and CLK);
process (gate_clk)
begin
if (gate_clk’event and gate_clk=’1’)
then
if (LOAD=’1’) then
OUT1 <= DATA;
end if;
end if;
end process;

Formation VHDL Conseils de synthèse Vahid MEGHDADI

258
Validation d'horloge (suite)

ENABLE <= IN1 and IN2 and LOAD;


process (CLOCK)
begin
if (CLOCK’event and CLOCK=’1’) then
if (ENABLE=’1’) then
DOUT <= DATA;
end if;
end if;
end process;

Formation VHDL Conseils de synthèse Vahid MEGHDADI

259
Occupation sur le FPGA

CLB CLB

Chaîne de
Spartan-II, Virtex retenue
Spartan-III, Virtex-II

SET
I3 CE
I2 O D Q
I1 RST
I0

LUT
I3 SET
I2 O CE
I1 D Q
I0 RST

Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

260
Registre à décalage

Utilisation des bascules

4
Z-1 Z-1 Z-1 Z-1 Z-1 Z-1

Ce registre à décalage demande combien de slice ?

12 car 2 bascules par slice sont disponibles.

Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

261
Utilisation des LUT

Multiplexeur

A SEL1 I3
B SEL2 I2 O
A I1
B I0

SEL1 SEL2

Ce multiplexeur demande combien de slice ?

Un seul slice.
Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

262
Additionneur complet

Cout
A I3
+ sum I2 O Cout
B
I1
Cin
I0

I3
A
Sum=f(A,B,Cin) I2 O Sum
B I1
I0
Cout=g(A,B,Cin) Cin

Un slice.
Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

263
Additionneur complet Xilinx

LUT Cout

A
0 1
B Sum

Cin

Un seul slice pour l'additionneur complet.


Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

264
La chaîne de retenu

Connexion rapide
SET
I3 CE
I2 O D Q
I1 RST
I0

LUT
I3 SET
I2 O CE
I1 D Q
I0 RST

Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

265
Addition 8 bits

S8
B7
A7 S7
B6
S6
A6

B5
A5 S5
Il suffit 4 slices pour une B4
S4
A4
addition sur 8 bits
B3 S3
A3
B2 S2
A2

B1
A1 S1
B0
A0 S0

Formation VHDL Occupation sur le FPGA Vahid MEGHDADI

266
Exercice

Réalisation d’un UART


Baud rate=9600 bit/sec, 8 bits, sans parité, 1 bit de stop

Bit de start 8 bits de data Bit de stop Data suivant

8
RX Interface DOUT

CLK=16*bit rate STRB


UART
Formation VHDL Vahid MEGHDADI

267

Vous aimerez peut-être aussi