Vous êtes sur la page 1sur 252

Chapitre : Introduction

Implantation des circuits numriques


Avec des lments discrets
Avec des microprocesseurs, micro contrleurs, DSP
Avec des circuits architecture programmable PAL, GAL, FPGA
Avec des circuits intgrs 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

Circuit avec des lments discrets

Circuit fig
Circuit imprim difficile
modifier
Intgration limite
Cot lev
Justifi pour de petits
circuits
Formation VHDL

Introduction

Vahid MEGHDADI

Circuit fonctionnement programmable


A base des microprocesseurs, Microcontrleurs, DSP
En modifiant le programme on modifie la fonction
Plus souple que les circuits lments discrets

Vitesse limite (mais qui


augmente sans cesse)

Microprocesseur

Paralllisme compliqu (mais


faisable)
Intgration encore limite

Mmoire

Pr
iph
ri
que

Adapt des oprations


squentielles
Formation VHDL

Introduction

Vahid MEGHDADI

Circuit architecture programmable

Une quantit importante de portes logiques


Des matrices d'interconnections
programmables
Modification du fonctionnement sur le circuit
(ISP)
Souplesse assure
Cot de fabrication faible (pour un nombre limit)
Intgration forte
Adapt des applications gourmandes en logique
Temps de dveloppement dpend de l'application
Compliqu pour implanter des algorithmes complexes
Formation VHDL

Introduction

Vahid MEGHDADI

Les ASIC

Application Specific Integrated Circuit

Cot trs bas mais pour de gros tirages


Temps de dveloppement important
Pas de modifications une fois fabriqu
Ncessitant un fondeur pour la fabrication

Formation VHDL

Introduction

Vahid MEGHDADI

ASIC ou FPGA ?

ASICs

FPGAs

High performance
Low development cost
Low power
Short time to market
Low cost in
high volumes

Formation VHDL

Reconfigurability

Introduction

Vahid MEGHDADI

Evolution : Mthodes de CAO

Conception physique (layout)


Conception structurelle TTL
Conception logique

Conception fonctionnelle RTL


Programmation Verilog/VHDL
Synthse comportemental
Formation VHDL

Introduction

Vahid MEGHDADI

Dmonstrateurs
Circuit de dveloppement SpartanIII

Formation VHDL

Introduction

Vahid MEGHDADI

Exemple
Une carte polyvalente et reconfigurable
Extension
JTAG

Formation VHDL

Introduction

Vahid MEGHDADI

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

Vitesse
Possibilit de paralllisme (calcul dans lespace ou dans le temps)
Exemple y=Ax+Bx+C

FPGA

DSP

Formation VHDL

Introduction

Vahid MEGHDADI

10

Intrt de la logique par rapport P

Jeu dinstruction peut ne pas contenir lopration voulue


Processeur peut contenir des circuits qui ne servent rien dans

notre application (Par exemple URAT)


Processeur a besoin de la mmoire pour garder le programme

et les valeurs intermdiaires


Le nombre de bits pour prsenter les donnes peut tre trop ou

peu
Paralllisme trs limit par software

Formation VHDL

Introduction

Vahid MEGHDADI

11

Fonction combinatoires
Utilisation dun PLA (Programmable Logic Array) ou PLD
I

I1

I
2

PLA1
PLA2
PLA3
O0

O1

O2

O3

Le circuit peut tre reprogramm sans changer le circuit


imprim condition de nutiliser quun seul PLA ou prvoir
linterconnexion entre PLA indpendant 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
interconnects par des liaisons programmables

I/O
I/O

I/O
PLD
PLD

PLD
Global
Interconnection

PLD
Formation VHDL

PLD

Matrix

I/O

I/O

I/O
PLD

Introduction

Vahid MEGHDADI

14

Architecture des FPGA


Feild Programmable Gate Array

CLB= Configurable Logic


Block

Formation VHDL

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

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

CLB

Introduction

Vahid MEGHDADI

15

FPGA architecture interne


BLE= Basic Logic Element
Inputs

Programmable
IO

K
LUT

Out

D FF

Clock

Programmable
Logic (CLB)

BLE
#1

N
Outputs

I
I
Inputs

BLE
#N

Clock

Programmable
Routing

Formation VHDL

Introduction

Vahid MEGHDADI

16

Architecture de CLB

Inputs

Look-Up
Table
(LUT)

Out

Out = f (in0, in1, in2, in3)

State
Clock
Enable
Formation VHDL

Introduction

Vahid MEGHDADI

17

FPGA Xilinx

Plusieurs familles de FPGA


Srie 4000
Spartan
Spartan (II, IIE et III)
Virtex (II, pro, IV et V)

Formation VHDL

Introduction

Vahid MEGHDADI

18

Spartan

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


diffrentie 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

La famille Virtex

Les LUT transformables en registre dcalage


Plus de CLB, plus de mmoire, plus de slices par CLB
Plus de I/O
Multiplieurs cbls partir de Virtex II
Microprocesseur embarqu (PowerPC)

Formation VHDL

Introduction

Vahid MEGHDADI

22

La famille Virtex

Formation VHDL

Introduction

Vahid MEGHDADI

23

La famille Virtex-II pro

Formation VHDL

Introduction

Vahid MEGHDADI

24

Conception circuit
o
o

EPROM

Les blocs reconfigurables


Structure rgulire de logic cells, connecte par un rseau dinterconnexions
La configuration est stock dans un SRAM, qui doit tre charg au dmrrage

Formation VHDL

Introduction

Vahid MEGHDADI

25

Design flow

HDL
(VHDL /
Verilog)

Synthesize

Hardware design is traditionally done by modeling


the system in a hardware description language
o An FPGA compiler (synthesis tool) generates a
netlist,
o

Netlist
Map
Place
Route

which is then mapped to the FPGA technology,


o the inferred components are placed on the chip,
o and the connecting signals are routed through the
interconnection network.
o

Bitstream
Formation VHDL

Introduction

Vahid MEGHDADI

26

Synthse HDL

HDL
process(clk, reset)

(VHDL /
Verilog)

begin
if reset = 1 then
output <= 0;
elsif rising_edge(clk) then
output <= a XOR b;
end if;

Synthesize
Netlist

end process;

Map
Place
Route

Register
a
b

D
clk

Bitstream

output

clear

reset
Formation VHDL

Introduction

Vahid MEGHDADI

27

Technology Mapping
Register

HDL
(VHDL /
Verilog)

a
b

D
clk

Synthesize

output

clear

reset

Netlist
Map
Place
Route

Bitstream
Formation VHDL

Introduction

Vahid MEGHDADI

28

Placement & Routage

HDL
(VHDL /
Verilog)

Synthesize
Netlist
Map
Place
Route
Bitstream
Formation VHDL

Introduction

Vahid MEGHDADI

29

Insertion dun microprocesseur (SoC)

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

MicroBlaze
Block RAM
Configuration

18 bit
Multipliers

Logic Block
(CLB)

Digital Clock
Manager
Formation VHDL

Programmable I/Os
Introduction

Vahid MEGHDADI

30

Systme embarqu traditionnel

Ethernet
MAC

Audio
Codec

Power Supply

CLK
CLK

Interrupt
Controller

GP I/O
Address
Decode
Unit

CPU

UART

(uP / DSP)
CLK

SRAM

Memory
Controller

SRAM

SRAM

SDRAM

Timer

CoProc.

SDRAM

custom
IF-logic

L
C

Display
Controller

Images by H.Walder

Formation VHDL

Introduction

Vahid MEGHDADI

31

Systme embarqu traditionnel

Ethernet
MAC

Audio
FPGA Codec

Power Supply

CLK
CLK

Interrupt
Controller

GP I/O
Address
Decode
Unit

CPU

UART

(uP / DSP)
CLK

SRAM

Memory
Controller

SRAM

SRAM

SDRAM

Timer

CoProc.

SDRAM

custom
IF-logic

L
C

Display
Controller

Images by H.Walder

Formation VHDL

Introduction

Vahid MEGHDADI

32

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

33

Avantages

 Moins de composantes physiques


 Cycle de conception plus rapide
 Programmable sur le circuit (Mise jour, modification...)
 Plus performant grce lintgration
 Horloge peut tre plus rapide dans la puce que sur le circuit imprim
 Optimisation entre modules possible

Formation VHDL

Introduction

Vahid MEGHDADI

34

CPUs Embarqus

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

35

Architecture de MicroBlaze

Formation VHDL

Introduction

Vahid MEGHDADI

36

CSoC Design Flow (Hardware)


HDL
Platform
(VHDL /
Description
Verilog)

Netlist
Synthesize
Generation

 Description de plate-forme est assemble

dans un netlist
 Soit, il est map, plac et rout dans le
FPGA

Netlist
Netlist

VHDL

Map
Place
XST
(Map, Place & Route)

Route

Bitstream

Formation VHDL

Xilinx ISE
(VHDL Edit, Map,
Place & Route)

 Soit, il est import dans ISE pour tre

utilis dans un systme plus large base


de FPGA

Introduction

Vahid MEGHDADI

37

CSoC Design Flow (Software)

Platform
Description

*.h

*.h

*.c

Compile &
Link

Netlist
Generation

Netlist

User sources

*.a

Library
Generation

Update
Bitstream

*.elf

XST or ISE
(Map, Place & Route)

Bitstream
Formation VHDL

Bitstream
with
executable
Code
Introduction

Program

Vahid MEGHDADI

38

Circuit de dveloppement

Formation VHDL

Introduction

Vahid MEGHDADI

39

Formation VHDL

Vahid MEGHDADI

40

Chapitre : Introduction A VHDL

Introduction au langage
VHDL
Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

41

VHDL

V
H
D
L
Formation VHDL

VHSIC
(Very High Speed Integradted Circuit)

Hardware
Description
Language

Introduction A VHDL

Vahid MEGHDADI

42

Un peu dhistoire
Dbut des annes 80
la ncessit dun langage non ambigu des systmes
matriels pour intgration grande chelle
normalisation pour tre indpendant du fournisseur
Norme dfinitive adopte en 1987 : IEEE Std 1076
La norme a t revue en 93, 2000 et 2002
Les premiers outils de synthse en 1995

Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

43

Quest ce que on attend de VHDL

VHDL est utilis pour


Dcrire des circuits numriques
Dcrire des machines tats
Prparer des signaux de test pour simuler cette criture

Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

44

Quest ce que on attend des outils de synthse


Une fois le programme en VHDL est crit, il faut maintenant
le raliser
Synthse logique : gnrer des fonctions logiques partir
du programme
Implmentation : adapter la logique synthtise la cible
(FPGA, CPLD)
Gnration : Gnrer un fichier binaire a tl-charger sur
le device
Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

45

Dmarche de synthse

Cahier des charges


Partitionnement logicielle/matrielles

Spec matrielles

Spec logicielles

ASIC
CPLD

Cartes

Software

Discret

Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

46

Niveau dabstraction

Synthse
comportemental
Synthse
logique
Placement
routage

Comportemental
RTL

VHDL

Logique
Layout

Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

47

Formation VHDL

Introduction A VHDL

Vahid MEGHDADI

48

Chapitre : Structure du VHDL

Il existe 5 catgories dunit de conception


Lentit (mot cl entity)
Circuit
principal

Dcrit un systme vu extrieur (bote noire)

Larchitecture (mot cl architecture)


Dcrit lintrieur (le fonctionnement) dune bote noire.

La configuration (mot cl configuration)


Package
(librairie)
Formation VHDL

La dclaration de paquetage (mot cl package)


Le corps de paquetage (mot cl package body)
Structure du VHDL

Vahid MEGHDADI

49

Domaine concurrent et squentiel

Description dun systme matriel


description daction concurrentes (ex. plusieurs
blocs dun circuit peuvent fonctionner en parallle
description daction en squence (ex. automates)
Deux jeux dinstructions en VHDL
Instructions concurrentes : elles sexcutent en
mme temps
Instructions squentielles : elles sexcutent les
une aprs les autres
Formation VHDL

Structure du VHDL

Vahid MEGHDADI

50

Classes dobjets

Quatre classes dobjets en VHDL :


Les constantes
Comme les autres langages, elles ont une valeur fixe
Les variables
Comme les autres langages, elles ont une valeur
immdiatement modifiable par affectation
Les signaux
Notion nouvelle, la valeur ne se modifie pas immdiatement
fichier (nest pas abord dans ce cours)
Formation VHDL

Structure du VHDL

Vahid MEGHDADI

51

Types dobjets

Les objets dun programme VHDL sont tous typs.


Avant toute utilisation dune constante, dune
variable ou dun signal, il faut les dclarer.
La dclaration des objets seffectue uniquement dans
la partie dclarative du programme.

Formation VHDL

Structure du VHDL

Vahid MEGHDADI

52

Les oprateurs
Par ordre de priorit croissante
Oprateur logique : and, or, nand, nor, xor, xnor,
sll, srl, sra, rol, ror
Oprateur de comparaison : =, /=, <, <=, >, >=
Oprateur daddition : +, -, &
Oprateur mathmatique : *, /, mod, rem
Oprateur de signe : Oprateur divers : **, abs, not
Formation VHDL

Structure du VHDL

Vahid MEGHDADI

53

Programmer en VHDL

Dfinition de lentit (bote noire avec les ports dentre/sortie)


Dfinition de larchitecture interne de cette bote noire
Dclaration des constantes, des signaux, des fonctions, des
procdures, des blocs hirarchiques utiliss dans le
programme
Corps du programme consistant
Les instructions concurrentes
Les instructions squentielles encapsules dans des
process
(Les commentaires sont prcds de deux tirs : -- exemple)
Formation VHDL

Structure du VHDL

Vahid MEGHDADI

54

Formation VHDL

Structure du VHDL

Vahid MEGHDADI

55

Formation VHDL

Vahid MEGHDADI

56

Chapitre : Entit

L'entit dfinit les ports (vue externe) et leur mode (in, out,
inout, buffer)
Paramtrer le modle (paramtres gnriques)
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

57

Entit
Entity name

Port names

Port type

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

Reserved words

Semicolon

No Semicolon
after last port

Port modes (data flow directions)

Mme chose mais en moins lisible !!


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

Entit

Vahid MEGHDADI

58

Exemples dentit

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

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

Formation VHDL

Entit

E1

E2

S
/N

Vahid MEGHDADI

59

Exemple dentit

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

Formation VHDL

Entit

D
EN

Q
Q_B

Vahid MEGHDADI

60

Chapitre : Architecture

Dfinition de signaux et d'autres objets internes


Description du fonctionnement ou de la structure de
lentit laide dinstructions concurrentes
Syntaxe:
architecture nom_de_l_architecture of nom_de_l_entite is
{partie dclarative}
begin
{suite dinstructions concurrentes}
end nom_de_l_architecture;
Formation VHDL

Architecture

Vahid MEGHDADI

61

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

62

Structure de l'architecture

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 dclarative de l'architecture}
begin
{zone des instructions concurrentes }
{comme des affectations, des process; }
end comport;

Formation VHDL

Architecture

Vahid MEGHDADI

63

Exemple darchitecture 1

SUM
Demiadditionneur

B
A

SUM

B
C

Formation VHDL

Architecture

C
A

SUM

Vahid MEGHDADI

64

Description flot de donnes

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

65

Exemple dune bascule RS


Q

QB

entity RS_FF (R,S: in std_logic;


Q,QB:out std_logic);
end entity;
architecture FPGA of RS_FF is
begin
Q <= R nand QB;
QB <= S nand Q;
end

Formation VHDL

Architecture

Vahid MEGHDADI

66

Chapitre : Types en VHDL

Tout objet en VHDL doit tre typ.


Un type dfinit
l'ensemble des valeurs que l'on peut affecter l'objet
l'ensemble des oprations disponibles sur l'objet

Formation VHDL

Types en VHDL

Vahid MEGHDADI

67

Dclaration de type

VHDL possde les types:


scalaires dont la valeur est constitue d'un seul lment
composites dont la valeur comprend plusieurs lments
accs ou pointeurs
fichier
On n'tudie que les deux premiers

Formation VHDL

Types en VHDL

Vahid MEGHDADI

68

Type scalaire
numr
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

69

Type numr

Ce type dclare 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 prdfinis


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

Formation VHDL

Types en VHDL

Vahid MEGHDADI

70

Type entier (scalaire)

C'est un type prdfini


type integer is range
-2_147_483_648 to 2_147_483_647

On peut dfinir 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

71

Logique valeurs multiples (scalaire)

Il existe des signaux logiques plusieurs tats:


0, 1, haute impdance, dont care, non dtermin,
Le type "std_logic" remplace le type "bit" pour permettre
davoir 9 tats diffrents
Utilisation de librairie IEEE.std_logic_1164
exemple
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
signal SORTIE, Q: std_logic;

SORTIE <= Z; -- haute impdance


Q <= 1;
Formation VHDL

Types en VHDL

Vahid MEGHDADI

72

Le type std_logic

Le type std_logic :
U
non initialis
X
non connu
0
logique 0
Strong drive
1
logique 1
Z
haute impdance
W
non connu
L
logique 0
weak drive
H
logique 1
-
dont care

Formation VHDL

VDD

Types en VHDL

Vahid MEGHDADI

73

Type composite

Deux types sont considrs : tableau et record


Un tableau est un ensemble dlments du mme type
Pour un ensemble de std_logic, nous avons le type prdfini
std_logic_vector : on dfinit la taille et l'ordre des lments
signal BUS1 : std_logic_vector (7 downto 0);
signal REG : std_logic_vector (0 to 31);

On peut aussi dfinir un type tableau dlments composites


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

Formation VHDL

Types en VHDL

Vahid MEGHDADI

74

Accs aux lments

Dclaration:
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

75

Accs aux lments de tableaux


Par agrgat
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 concatnation
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

76

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 dfaut

c <= B0000;

-- Base Binaire explicite

d <= 0110_0111;

-- Utiliser _ pour augmenter la lisibilit

e <= XAF67;

-- Base Hexadecimale

f <= O723;

-- Base Octale

Formation VHDL

Types en VHDL

Vahid MEGHDADI

77

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 VAR is array (0 to 7) of integer;
constant SETTING: VAR := (2,4,6,8,10,12,14,16);
type MY_MATRIX is array (0 to 3, 1 to 2) of natural;
variable DATA_ARR: MY_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
-- dfinie quand on dclare 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

78

Record
Ensemble d'lments de types diffrents
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

79

Formation VHDL

Vahid MEGHDADI

80

Chapitre: zone concurrente

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


instructions s'excutent toutes en mme temps (en parallle)
A
B
C

Formation VHDL

I <= A or B;

S <= I and C

S <= I and C

I <= A or B;
Zone concurrente

Vahid MEGHDADI

81

Instruction with

with HEX select


LED<= "1111001"
"0100100"
"0110000"
"0011001"
"0010010"
"0000010"
"1111000"
"0000000"
"0010000"
"0001000"
"0000011"
"1000110"
"0100001"
"0000110"
"0001110"
"1000000"
Formation VHDL

when
when
when
when
when
when
when
when
when
when
when
when
when
when
when
when

"0001",
"0010",
"0011",
"0100",
"0101",
"0110",
"0111",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
"1110",
"1111",
others;

--1
--2
--3
--4
--5
--6
--7
--8
--9
--A
--b
--C
--d
--E
--F
--0

Zone concurrente

Circuit
combinatoire
4

Vahid MEGHDADI

82

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

REG1

8
ENA2

REG2
Formation VHDL

Zone concurrente

Vahid MEGHDADI

83

Exemple

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

architecture COMPORT1 of CIR is


Begin
S <= (A and B) nor (C nand D);
end COMPORT1;

Formation VHDL

architecture COMPORT2 of CIR is


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

Zone concurrente

Vahid MEGHDADI

84

Exemple ALU

entity ADDER
port (A,B
SEL
S :
end ADDER;

is
:in std_logic_vector(7 downto 0);
: in std_logic;
out std_logic_vector(7 downto 0));

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

85

Formation VHDL

Vahid MEGHDADI

86

Formation VHDL

Vahid MEGHDADI

87

Formation VHDL

Vahid MEGHDADI

88

Chapitre: zone squentielle

En VHDL, une zone squentielle existe dans laquelle


une suite d'instructions sexcutent les unes aprs
les autres.

Cette zone se trouve dans les process, fonctions et


procdures.

Formation VHDL

Zone squentielle

Vahid MEGHDADI

89

Process

Process est une instruction concurrente complexe


crire dans une architecture

Process dfinit une zone squentielle

Les diffrents process d'une architecture s'excutent


tous en parallle
Formation VHDL

Process

Vahid MEGHDADI

90

Syntaxe de process

Syntaxe de process :
label : -- optionnel
process (liste de sensibilit)
{partie dclarative}
begin
suite dinstructions squentielles
end process;

Un process s'excute quand un des signaux de la liste


de sensibilit change de valeur.

Formation VHDL

Process

Vahid MEGHDADI

91

Instructions squentielles

Elles s'crivent uniquement dans une zone squentielle


instruction d'attente (wait)
instruction d'affectation (temporise)
instruction conditionnelle (if)
instruction case
instruction de boucle

Formation VHDL

Process

Vahid MEGHDADI

92

Instructions wait

Elle sutilise pour suspendre un process jusquun vnement


wait until condition;
wait until A= 1 ;
wait until CLKevent and CLK=1;
wait for time expression;
wait for 5 ns;
wait on signal;
wait on A , B

Formation VHDL

Process

Vahid MEGHDADI

93

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

94

Instruction case

Permet de slectionner une suite dinstructions excuter


en fonction de la valeur dune expression.
case EXPRESSION is
when VAL1
=>
when VAL2|VAL3|VAL4 =>
when VAL5 to VAL7 =>
when others
=>
end case;

suite dinstructions squentielles


suite dinstr squentielles
suite dinstr squentielles
suite dinstr squentielles

Lordre des branches na pas dimportance (sauf others)


La branche others est obligatoire si toutes les valeurs
de lexpression ne sont pas numres.
Formation VHDL

Process

Vahid MEGHDADI

95

Instruction for

for I in 0 to 3 loop

Synthse

logique

-- logique

logique

end loop;

Formation VHDL

Logique

Process

logique

Vahid MEGHDADI

96

Exemple

Multiplexeur 4 voies
S1

S0

A
B
C
D

Formation VHDL

M
U
X
4

Process

Vahid MEGHDADI

97

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

98

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

99

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

100

Affectation des signaux

Dans une architecture (zone concurrente), laffectation


est immdiate.
Dans un process (zone squentielle) laffectation est
immdiate pour des variables
retarde jusqu la fin du process pour des signaux

Formation VHDL

Process

Vahid MEGHDADI

101

Affectation dans une architecture


Architecture CONCUR of EXEMPLE is
signal Z, A, B, C, D : std_logic;
begin
Z <= A and B;
Z <= C and D;

Erreur multi sources

end CONCUR;
A
B

D
Formation VHDL

Process

Vahid MEGHDADI

102

Affectation dans un process

Architecture SEQ of EXEMPLE is


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

begin

Z <= A and B;
Z <= C and D;

end process; -- la valeur retenue est affecte maintenant


end CONCUR;
Formation VHDL

Process

Vahid MEGHDADI

103

Attention !

Le process ci-dessous ne
produira pas le signal cicontre
SIG
Process (x)
begin
SIG <= '0';
SIG <= '1';
SIG <= '0';
end process;

Formation VHDL

SIG

Process

Vahid MEGHDADI

104

Exemple dappel multiple

EXEMPLE : process (A,B,M)


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

A:0
B:0
M:0
Z :0

Un vnement se produit : B -> 1


Le process se rveille, alors :

Formation VHDL

Process

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

Y:0
M:1
Z :0

Vahid MEGHDADI

105

Exemple dappel multiple

EXEMPLE : process (A,B,M)


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

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

Un nouveau vnement sur M, process se rveille encore


A:0
B:1
M:1
Z :0
Formation VHDL

Y:0
M:1
Z :1

Process

Vahid MEGHDADI

106

Les variables

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


Les variables ne sont dclares que dans un process
La valeur des variables est mise jour ds lexcution de
linstruction daffectation
Les variables ne sont pas visibles lextrieur du process
Les variables gardent leur valeur pour le rveil suivant

Formation VHDL

Process

Vahid MEGHDADI

107

Formation VHDL

Vahid MEGHDADI

108

Chapitre : Hirarchisation

Conception dun bloc et son utilisation dans un autre


circuit: instantiation ou instantiation multiple
1. Premire tape: crire lentit et larchitecture du
module
2. Deuxime tape: introduire ce module au circuit
appelant (ce module sappellera component )
3. Troisime tape: instantiation du module

Formation VHDL

Hirarchisation

Vahid MEGHDADI

109

Dclaration du component

Se fait dans la partie dclarative de larchitecture.


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

Hirarchisation

Vahid MEGHDADI

110

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;

Deux
faons
de faire

Formation VHDL

Prfrable

DEMI_ADD_INST: DEMI_ADD port map


(A => SIG_A, B => SIG_B, SUM => SOMME, C => RETENUE);
DEMI_ADD_INST: DEMI_ADD port map (SIG_A,SIG_B, SOMME, RETENUE);

Hirarchisation

Vahid MEGHDADI

111

Exemple addition

A
B

SUM
Demiadditionneur C

SUM

B
C

Formation VHDL

Hirarchisation

SUM

Vahid MEGHDADI

112

Description flot de donnes

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

Hirarchisation

Vahid MEGHDADI

113

Exemple darchitecture 2

A
B

N1
DEMI_ADD N2
SUM

SUM

SUM

DEMI_ADD

N3
Cout

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

Formation VHDL

Hirarchisation

Vahid MEGHDADI

114

Instantiation

architecture COMPORT of ADD_COMPLET is


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

Dclaration de
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

Hirarchisation

Vahid MEGHDADI

115

Chapitre : Droulement dun programme VHDL

Larchitecture est le lieu dchange de linformation entre


les instructions concurrentes (les process en particulier).
Lchange se fait uniquement par lintermdiaire des
signaux
Signal a

process

process

Signal x,y

process
Formation VHDL

Droulement dun programme VHDL

Signal t,u
Vahid MEGHDADI

116

Droulement de simulation

La notion de temps ne s'utilise que pour spcifier l'ordre des


vnements.
Les seuls moyens d'avancer dans le temps sont :
par un changement d'un signal en entre
par la commande wait for temps
par la commande after temps
sinon, les signaux sont tous stables et les process dorment
tous.
Formation VHDL

Droulement dun programme VHDL

Vahid MEGHDADI

117

Deux files d'attente

1- A chaque vnement est associ une liste des process


rveiller
2- Aprs excution de tous les process de la liste, une
nouvelle liste d'vnement sur les signaux est tablie
3- Une nouvelle liste des process rveiller s'tablit
4- Tant que cette liste n'est pas vide, on ritre l'tape 2
5- Le circuit est stable et attend un nouvel vnement
Formation VHDL

Droulement dun programme VHDL

Vahid MEGHDADI

118

Traitement des files

Dsigner les
signaux changs

File
signal

Formation VHDL

Dsigner les
process rveiller

File
process

Droulement dun programme VHDL

Vahid MEGHDADI

119

Avancement dans le temps

File
signal

File
process

File
signal

File
process

temps
En simulation, les vnements sont galement sur une liste.
Wait for 5 ns, ou A <= Z after 7 ns crent des vnements
dans l'ordre sur cette liste.
Formation VHDL

Droulement dun programme VHDL

Vahid MEGHDADI

120

Formation VHDL

Vahid MEGHDADI

121

Formation VHDL

Vahid MEGHDADI

122

Formation VHDL

Vahid MEGHDADI

123

Chapitre : Circuits combinatoires

Un circuit combinatoire donne toujours les mmes sorties


quand lentre est la mme.
Un process est combinatoire si les conditions suivantes sont
toutes respectes :
le process comporte une liste de sensibilit
la liste de sensibilit comprend tous les signaux lus
tous les signaux doivent tre affects quelle que soit les
entres (Attention dans un "if" ou dans un "case")
toutes les variables doivent tre affectes avant d'tre lues
Formation VHDL

Circuits combinatoires

Vahid MEGHDADI

124

Circuits combinatoires : quation logique

Architecture COMB1 of NONET is


begin
--quation logique
S <= A nand B;
end COMB1;

Architecture COMB2 of NONET is


begin
--Traduction de la table
--de vrit dans un process
S <= '0' when A='1' and B='1'
else '1';
end COMB2;

Formation VHDL

Architecture COMB3 of NONET is


begin
--Traduction de la table
--de vrit dans un process
process(A,B)
begin
if A='1' and B='1' then
S <= '0';
else
S <= '1';
end if;
end process;
end COMB3;

Circuits combinatoires

Vahid MEGHDADI

125

Exemple

Transcription dune table de vrit


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

Formation VHDL

A(1)
0
0
1
1
0
0
1
1

A(0)
0
1
0
1
0
1
0
1

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

S(1)
0
0
1
1
1
1
0
0

Circuits combinatoires

S(0)
0
1
1
0
0
1
1
0

Vahid MEGHDADI

126

Affectation avec if

Dans une zone squentielle (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

127

Affectation avec case


Dans une zone squentielle (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

128

Affectation slective
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

129

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

130

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

131

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

132

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

133

Exemple : Multiplieur
Le but est de raliser un multiplieur 4 bits fois 4 bits
A
1001
B
*1101
--------0000 1001
+0000 0000
+0010 0100
+0100 1000
---------0111 0101

0
0

B(0)
4

4
B(1)
0
4
B(2)

0
4

res(0)

(4 downto 1)
res(1)

B(3)

5
(4 downto 1)
res(2)

5
(4 downto 1)
res(7 downto 3)

Formation VHDL

Vahid MEGHDADI

134

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

135

Exemple : Multiplieur, rsultat de synthse

Formation VHDL

Vahid MEGHDADI

136

Formation VHDL

Vahid MEGHDADI

137

Chapitre : Circuits squentiels

Un process comporte un point de mmorisation si au


moins une des conditions suivantes est vrifie :
la liste de sensibilit ne comprend pas tous les signaux
lus
les signaux ne sont pas affects quelle que soit la
branche
une variable est lue avant d'tre affecte

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

138

Latch
Bascule verrouillage
entity L is
port (D,G : in std_logic;
Q : out std_logic);
end L;
architecture A of L is
begin
process
begin
wait on D,G;
if G='1' then Q <= D;
end if;
end process;
end A;
Formation VHDL

architecture A of L is
begin
process (D,G)
begin
if G='1' then Q <= D;
end if;
end process;
end A;

Circuits squentiels

Vahid MEGHDADI

139

Registre simple (latch synchrone)


Un circuit synchrone sur le front dun signal (CLK)
entity R is
port (D,CLK: in std_logic;
Q: out std_logic);
end R;
architecture A of R is
begin
process
begin
wait on CLK;
if CLK='1' then Q <= D;
end if;
end process;
end A;
Formation VHDL

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

Vahid MEGHDADI

140

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
begin -- set asynchrone
process (SET,CLK)
begin
if SET = '1' then Q <= '1';
elsif CLK'event and CLK='1'
then Q <= D;
end if;
end process;
end A;
Formation VHDL

architecture A of R is
begin -- set synchrone
process (CLK)
begin
if CLK'event and CLK='1' then
if SET = '1' then Q <= '1';
else Q <= D;
end if;
end if;
end process;
end A;

Circuits squentiels

Vahid MEGHDADI

141

Exemple 1

E2

E1
D

E0
D

CLK QB

CLK QB

CLK QB

H
RAZ
S2

Formation VHDL

S1

Circuits squentiels

S0

Vahid MEGHDADI

142

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 Hevent and H = 1 then
S <= E;
end if;
end process;
end A;
Formation VHDL

Circuits squentiels

Vahid MEGHDADI

143

Exercice : registre dcalage srie

Entree

E2

CLK QB

S2

E1

CLK QB

S1

E0

S0

Sortie

CLK QB

H
RAZ

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

144

Exercice: Registre dcalage srie

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

145

Exercice : Registre dcalage srie

Entree

CLK QB

REG2

CLK QB

REG1

REG0
Sortie

CLK QB

H
RAZ

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

146

Exercice : Registre dcalage srie 2 (suite)

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

147

Exercice : Registre chargement parallle et dcalage sriel

E2
Entree

E1
D

E0

REG2
CLK QB

CLK QB

D
REG1

Sortie
REG0

CLK QB

H
RAZ
LOAD

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

148

Exercice : Registre chargement parallle et dcalage sriel

Formation VHDL

Circuits squentiels

Vahid MEGHDADI

149

Attention !

Les instructions suivantes sont


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

Formation VHDL

Circuits
Attention
squentiels
!

+1

Vahid MEGHDADI

150

Correction

On utilise un process
synchronis sur un front
process (CLK)
begin
if rising_edge(CLK) then
A <= not A;
-- CMPT <= CMPT + 1;
-- etc;
end if;
end process;

Formation VHDL

CLK

+1

CLK

Circuits
Attention
squentiels
!

Vahid MEGHDADI

151

Attention sur les process synchrones!


Un seul if dans un process synchrone

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

Formation VHDL

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

Circuits squentiels

Vahid MEGHDADI

152

Chapitre : Machine tats finis


Une partie combinatoire pour calculer ltat
prochain
Une partie combinatoire pour prparer

E1E2= "11"

les sorties

s0

Une bascule pour avancer dans ltat

E1E2= "10"

Machine de Mealy: la sortie dpend de ltat


et aussi des entre
Machine de Moore: la sortie ne dpend que de
ltat.

E1E2= "0x"

s1

s2
E1E2= "1x"

Formation VHDL

Machine tats finis

Vahid MEGHDADI

153

Sparation des logiques


Dans un automate synchrone il existe
une logique combinatoire permettant de dcider sur
l'tat suivant et sur les sorties
une partie synchrone qui se charge du changement
d'tat du systme au moment voulu.
Il y deux types de ralisation
un seul process regroupant les parties combinatoire
et squentielle
un process pour la partie squentielle et un process
pour la partie combinatoire
Formation VHDL

Machine tats finis

Vahid MEGHDADI

154

Implantation un seul process

type T_ETAT is (E1, E2, E3);


signal ETAT : T_ETAT;
...
logique
ENTREE
Process(CLK)
begin
CLK
if CLK'event and CLK='1 then
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

CLK

Vahid MEGHDADI

155

Implantation par des process spars

E1

Fonction
combinatoire

E2

S1

S2

Fonction
combinatoire

ETAT_FUTUR

ETAT_COUR
Registre
d'tats

H
RAZ

Formation VHDL

Machine tats finis

Vahid MEGHDADI

156

Programmation logique spare


Dclaration des signaux :
signal E1,E2,S1,S2,H,RAZ : std_logic

Dclaration des tats :


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

Avancement dans ltat


REG : process (H, RAZ)
begin
if RAZ = 0 then ETAT_COUR <= ETAT1;
elsif Hevent and H = 1 then
ETAT_COUR <= ETAT_FUTUR;
end if;
end process;
Formation VHDL

Machine tats finis

Vahid MEGHDADI

157

Programmation de la partie combinatoire G

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


-- dentre 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

158

Programmation de la partie combinatoire F

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


-- dentre 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

159

Rappels (1)

Les fonctions F et G peuvent tre dcrites dans le


mme process
Si le process est synthtis par un circuit squentiel
synchronis sur front dhorloge, il ne doit comporter
dans la liste de sensibilit que lhorloge et la RAZ
asynchrone des bascules 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

160

Rappels (2)

Si le process est synthtis par un circuit


combinatoire, il doit comporter dans la liste de
sensibilit tous les signaux lus.
Si il y a test dun signal dans un process
combinatoire, il doit tre complet (ne pas oublier le
else), et toutes les sortie doit tre affectes dans
toutes les branches du test.

Formation VHDL

Machine tats finis

Vahid MEGHDADI

161

Exemple de la partie combinatoire F

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


-- dentre 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

162

Formation VHDL

Vahid MEGHDADI

163

Formation VHDL

Vahid MEGHDADI

164

Chapitre : Exemples
Exemple 1
CLK

Down counter
Vcc
D

IRQ*
Q*

D_FF
CLK

RSET*
Formation VHDL

Exemples

Vahid MEGHDADI

165

Exemple 1 : 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

166

Exemple 1 : 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

167

Exemple 1 : Circuit complet (1)


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

Dclaration
des components

architecture Behavioral of test2 is


component D_FF
Port ( CLK : in std_logic;
RESET : in std_logic;
D : in std_logic;
Q_BAR : out std_logic);
end component;
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

168

Exemple 1 : Circuit complet (2)

Instantiation
des components

begin
FLIP_FLOP: D_FF port map (
CLK => OR_OUT,
RESET => ACK,
D => '1',
Q_BAR => IRQ
);
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

169

Exemple 2

-------------

Formation VHDL

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

Exemples

Vahid MEGHDADI

170

Programmation concurrente

with HEX select


LED<= "1111001" when "0001",
"0100100" when "0010",
"0110000" when "0011",
"0011001" when "0100",
"0010010" when "0101",
"0000010" when "0110",
"1111000" when "0111",
"0000000" when "1000",
"0010000" when "1001",
"0001000" when "1010",
"0000011" when "1011",
"1000110" when "1100",
"0100001" when "1101",
"0000110" when "1110",
"0001110" when "1111",
"1000000" when others;
Formation VHDL

Exemples

--1
--2
--3
--4
--5
--6
--7
--8
--9
--A
--b
--C
--d
--E
--F
--0
Vahid MEGHDADI

171

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

172

Exemple 3

Il nous faut la synthse dun feu tricolore. Le feu


rouge 30 secondes, le vert 26 secondes et lorange 4
seconde. Lentre du systme est une horloge de
frquence 1 Hz.
R
CLK
O
RAZ

Formation VHDL

Exemples

Vahid MEGHDADI

173

Entit

Lentit 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

174

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

Formation VHDL

Exemples

Vahid MEGHDADI

175

Architecture (2)
when VERT =>
if CMPT = 26 then
CMPT := 0;
ETAT <= ORANGE;
else ETAT <= VERT;
end if;
when ORANGE =>
if CMPT = 5 then
CMPT := 0;
ETAT <= ROUGE;
else ETAT <= ORANGE;
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

176

Rapport de mapping

Le rsultat de mapping sur un spartan 2E : XC2s200

Selected Device : 2s200epq208-6


Number
Number
Number
Number
Number

Formation VHDL

of
of
of
of
of

Slices:
Slice Flip Flops:
4 input LUTs:
bonded IOBs:
GCLKs:

Exemples

11
8
18
4
1

out
out
out
out
out

of
of
of
of
of

2352
4704
4704
146
4

0%
0%
0%
2%
25%

Vahid MEGHDADI

177

Exemple 4
Gestion dun clavier
Clavier
FPGA
LIN

CODE
COL

Formation VHDL

Exemples

Vahid MEGHDADI

178

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

179

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

180

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

181

Partie dcodage
DECODE: process (COMB)
begin
case COMB is
when "0111011" => CODE <= "0000110";
when "0111101" => CODE <= "1011011";
when "0111110" => CODE <= "1001111";--3
when "1011011" => CODE <= "1100110";
when "1011101" => CODE <= "1101101";
when "1011110" => CODE <= "1111101";--6
when "1101011" => CODE <= "0000111";
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

--1
--2
--4
--5
--7

--#
--*

Vahid MEGHDADI

182

Exemple 5
Exemple dun additionneur 8 bits utilisant des
additionneurs complets

00111100
10011010
+ 10110110
01010000

Optimisation vitesse
y

y0

y1

x0

x
0

x1
a1

b1

Cin

Cout
s

z
Formation VHDL

y7
x7

a1

b1

Cin

Cout
s

z0

a1

b1

Cin

Cout

z1
Exemples

z7
Vahid MEGHDADI

183

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 squentielle,


linstruction FOR ... LOOP nest pas utilisable.
Par contre on peut utiliser linstruction generate.
On peut faire bien sr dune manire plus simple et plus optimale :
Z <= X+Y;
Formation VHDL

Exemples

Vahid MEGHDADI

184

Structure partage de ressources


Optimisation surface
x

LOAD

Reg dcal
Reg dcal
a1

b1

Cin

s
Cout

CLK

Reg dcal

z
CLK
Formation VHDL

Exemples

Vahid MEGHDADI

185

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

186

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

187

Chronogramme

Le rsultat est prt aprs 8 coups dhorloge


Formation VHDL

Vahid MEGHDADI

188

Exemple 6- UART en mission

Le but est de raliser lmetteur de lUART avec les


caractristiques suivantes:
-8 bits de data
-Deux bit de stop 1
-Un bit de start 0
-Parit paire
-Requte dinterruption quand le registre est vid
-Vitesse dmission 19200
Formation VHDL

Vahid MEGHDADI

189

Le systme fonctionnel

8
IRQ*

EN

EN

Registre

ACK*

CLK

CLK_50M

8
SO
/n

1 1 P

Registre dc.

FCLK=50 MHz
Formation VHDL

Vahid MEGHDADI

190

Dissociation des taches

D_BUS
EN

reg
CLK_50M

Clk_19200

busy

charg

/n
CLK_50M

reg_a_dec

reg_a_dec
1
charg

FF

IRQ*

busy

charg
Compte_bit

ACK*

Formation VHDL

SO

Clk_19600

Vahid MEGHDADI

191

Programmation Diviseur

DIV_CLK:process(CLK_50M)
begin
if CLK_50M'event and CLK_50M='1' then
compt <= compt + 1;
if compt = 1301 then -- = (50 000 000 /19200 *2 )-1=1301
clk_19200 <= not clk_19200;
compt <= 0;
end if;

CLK_50M

Clk_19200

/n

end if;
end process;

Formation VHDL

Vahid MEGHDADI

192

Programmation chargement

REGISTRE:process(CLK_50M)
begin
if CLK_50M'event and CLK_50M='1' then
if EN = '1' then
D_BUS

reg <= D_BUS;


reg_plein <= '1';

EN

reg

else
if busy='0' and reg_plein='1' then

busy

charg

reg_a_dec(8 downto 1) <= reg;


charge <= '1';
reg_plein <= '0';

CLK_50M

reg_a_dec

elsif busy='1' then charge <= '0';


end if;

reg_a_dec

end if;
end if;
end process;
Formation VHDL

Vahid MEGHDADI

193

Programmation dcalage
DECALAGE_CIRCUIT:process(CLK_19200)
begin
if CLK_19200'event and CLK_19200='1' then
case etat_decal is
when repos =>
SO <= '1';
busy <= '0';
if charge='1' then
charg
etat_decal <= decalage;
busy <= '1';
compt_bit <= 0;
Clk_19200
end if;
when decalage =>
SO <= reg_a_dec(compt_bit);
compt_bit <= compt_bit + 1;
if compt_bit = 11 then
etat_decal <= repos;
busy <= '0';
end if;
end case;
end if;
end process;
Formation VHDL

busy
Compte_bit

SO

Vahid MEGHDADI

194

Programmation interruption

INTERRUPT:process(charge, ACK)
begin

if ACK ='0' then IRQ <= '1';


elsif charge'event and charge='0' then
IRQ <= '0';

charg

FF

IRQ*

ACK*

end if;
end process;

Formation VHDL

Vahid MEGHDADI

195

Entity

entity uart is
Port ( CLK_50M : in STD_LOGIC;
ACK : in STD_LOGIC;
IRQ : out STD_LOGIC;
SO : out STD_LOGIC;
D_BUS : in STD_LOGIC_VECTOR (7 downto 0);
EN : in STD_LOGIC);
end uart;

Formation VHDL

Vahid MEGHDADI

196

Dclaration des signaux

architecture Behavioral of uart is


signal compt: integer range 0 to 2047:=0;
signal compt_bit: integer range 0 to 15:=0;
signal clk_19600: std_logic:='0';
signal reg: std_logic_vector(7 downto 0):="00000000";
signal charge: std_logic:='0';
signal busy: std_logic:='0';
signal reg_a_dec: std_logic_vector(11 downto 0):="000000000000";
type T_etat is (repos, decalage);
signal etat_decal:T_etat:=repos;
signal reg_plein : std_logic:='0';
Formation VHDL

Vahid MEGHDADI

197

Formation VHDL

Vahid MEGHDADI

198

Formation VHDL

Vahid MEGHDADI

199

Formation VHDL

Vahid MEGHDADI

200

Chapitre : Notions avancs

Notions
avancs
Formation VHDL

Vahid MEGHDADI

201

Gnricit

Cest un moyen de transmettre des infos un bloc pour


le rendre un bloc paramtrable.
Exemples : une porte ET N entres, un registre
dcalage de taille N, un multiplexeur N vers 1,
Syntaxe :
generic

Formation VHDL

(param1 : type de param1 := valeur par dfaut;


param2 : type de param2 := valeur par dfaut;
...);

Gnricit

Vahid MEGHDADI

202

Exemple
Porte ET N entres :
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

Gnricit

Vahid MEGHDADI

203

Appel dun bloc paramtrable

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

Gnricit

Vahid MEGHDADI

204

Paquetage

Il donne la possibilit de regrouper des parties


communes pour le travail d'une quipe
Prsente des types et des sous-types
Prsente des objets (signaux, constants)
Prsente la dclaration des sous-programmes
On peut y dclarer des alias

Formation VHDL

Paquetage

Vahid MEGHDADI

205

Syntaxe de Paquetage
Package <nom_de_paquetage> is
suite de dclarations>
end {<nom_de_paquetage>};

package pak_test is

Exemple:

subtype OCTET is std_logic_vector(7 downto 0);


subtype MOT is std_logic_vector(15 downto 0);
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

206

Paquetage de composants

Le paquetage permet aussi de grouper la dclaration 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

207

Corps de Paquetage

Dcrit l'algorithme des sous-programmes du paquetage.


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

Formation VHDL

Paquetage

Vahid MEGHDADI

208

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

209

Utilisation de paquetage

On cre 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, slectionner 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

210

Configuration
Une entit peut avoir plusieurs architectures
Un rle de configuration : choisir l'architecture
correspondante
Exemple : Pour l'entit additionneur on peut
envisager 3 architectures diffrentes : 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

211

Choix de l'architecture

Deux faons pour relier une architecture prcise une


entit :
Dans une unit de compilation autonome : la
configuration
Dans la partie dclarative d'un bloc ou d'une
architecture (configuration " la vole")
(Par dfaut c'est la dernire compile qui sera prise en
compte)

Formation VHDL

Configuration

Vahid MEGHDADI

212

Exemple de Configuration

Entity SIM is end;

Entity ADD is
port (A,B : in integer;
S : out integer);
end ADD;
architecture FONCTION of ADD is
begin
S <= A+B;
end FONCTION;

Formation VHDL

architecture ESSAI1 of SIM is


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

Vahid MEGHDADI

213

Exemple de Configuration " la vole"

Entity SIM is end;

Entity ADD is
port (A,B : in integer;
S : out integer);
end ADD;
architecture FONCTION of ADD is
begin
S <= A+B;
end FONCTION;

Formation VHDL

architecture ESSAI1 of SIM is


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

Vahid MEGHDADI

214

Formation VHDL

Vahid MEGHDADI

215

Formation VHDL

Vahid MEGHDADI

216

Les sous-programmes

But des sous-programmes


Pour crire des algorithmes rutilisables
Pour augmenter la lisibilit
Deux classes des sous-programmes
Les procdures
Les fonctions

Formation VHDL

Les sous-programmes

Vahid MEGHDADI

217

Procdure

Mot cl procedure
L'appel d'une procdure est une instruction (concurrente
ou squentielle)
Peut retourner plusieurs valeurs
Peut agir sur les signaux globaux
Peut se synchroniser (avec wait dedans)
Corps d'une procdure est une zone squentielle
Formation VHDL

Les sous-programmes

Vahid MEGHDADI

218

Fonction

Mot cl function
L'appel est droite d'une affectation
L'appel peut se faire dans la zone concurrente ou
squentielle
Retourne une seule valeur
Rend immdiatement sa valeur
Corps d'une fonction est une zone squentielle
Formation VHDL

Les sous-programmes

Vahid MEGHDADI

219

Ecriture des sous-programmes

Un sous-programme est constitu


D'une dclaration : interface
D'un corps : algorithme

Syntaxe de la dclaration
procedure <nom> (liste des paramtre);
function <nom> (liste des paramtre) return type_du_rsultat;

Formation VHDL

Les sous-programmes

Vahid MEGHDADI

220

Dclaration des sous-programmes

Liste_des_paramtre :
{classe_d'objet} PARAM1 :{mode} type{:=valeur_par_dfaut}
class_d'objet : signal, variable, constant
mode : in, out, inout
Restriction
pas de paramtres out ou inout dans la dclaration d'une
fonction
pas de variable transmise une fonction
classe d'objet par dfaut est "constant" pour les "in" et
"variable" pour les "out" et "inout"
Formation VHDL

Les sous-programmes

Vahid MEGHDADI

221

Corps de sous-programme
Entte is -- function ou procedure
{zone de dclarations}
begin
{partie instruction squentielle}
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

222

Appel de sous-programme

Diffrentes formes d'appel


Par position (mme ordre que la dclaration)
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

223

Les Attributs

Attribut sur les signaux:


signal_name'attribut
l'attribut synthtisable : event
wait until CLK'event and CLK='1';

attribut sur le type array


type MYARR is array (-2 to 4) of integer;
MYARRleft
returns -2
MYARRright
4
MYARRhigh
4
MYARR'low
-2
MYARRreverse_range
4 downto to -2

Formation VHDL

Les Attributs

Vahid MEGHDADI

224

Alias
Intrt
Donne un nom diffrent 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

225

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

226

Codage one-hot

La mthode prfre 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

227

If Generate

If-generate permet de
synthtiser un circuit
suivant une condition
Exemple :
entity generate_test is
generic ( CLK_DIV : boolean :=TRUE);
Port ( CLK : in std_logic;
sortie : out std_logic);
end generate_test;

architecture A of generate_test is
signal clk_r : std_logic:= '1';
begin
U1: if CLK_DIV generate
process(CLK)
begin
if CLK'event and CLK='1' then
clk_r <= not clk_r;
end if;
end process;
end generate;
U2: if not CLK_DIV generate clk_r <= clk;
end generate;
sortie <= clk_r;
end A;

Formation VHDL

If generate

Vahid MEGHDADI

228

for Generate
for-generate permet de rpter 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

229

Formation VHDL

Vahid MEGHDADI

230

Formation VHDL

Vahid MEGHDADI

231

Formation VHDL

Vahid MEGHDADI

232

Conseils de synthse

Utiliser le nom du fichier le mme 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 caractres.
Ne pas hsiter de donner un nom signifiant des signaux
(constant, variable, type, etc)
Quand vous appelez un component, utilisez les paramtres
de passage par nom :
U1 : HALF_ADD port map(A =>oper1, B=>oper2, SUM =>somme,
C=>retenue);
Formation VHDL

Conseils de synthse

Vahid MEGHDADI

233

Conseils (2)
Ne jamais utiliser des signaux ou des variables pour des
constantes. (cela gaspille les ressources normment)

Xilinx recommande de n'utiliser que les std_logic pour les


types des ports dans les entits.

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


signaux de sortie qui sont lus dans l'architecture. A sa place,
dclarer un signal interne avec la mme valeur et utiliser "out"
pour le signal de sortie
Formation VHDL

Conseils de synthse

Vahid MEGHDADI

234

Conseils (3)
Privilgier l'utilisation des signaux par rapport aux
variables

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


synthtise pas

Les valeurs initiales ne sont normalement pas tenue


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

Formation VHDL

Conseils de synthse

Vahid MEGHDADI

235

Ordre des oprations

Ordre dans une expression arithmtique


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

Donnent le mme rsultat mais pas forcement le mme circuit


A1
A2
A3
A4

ADD

A1
A2
A3

ADD

Un circuit plus rapide

A4
Formation VHDL

Conseils de synthse

Vahid MEGHDADI

236

"if" ou "case", la diffrence


Pour un circuit de dcodage, "if" produit
un circuit priorit tandis que "case", un
circuit quilibr
Utiliser "case" pour un dcodage
complexe
Utiliser "if" pour favoriser les chemins
lents

entity if_ex is
port (SEL: in std_logic_vector(1 downto 0);
A,B,C,D: in std_logic;
MUX_OUT: out std_logic);
end if_ex;

Formation VHDL

architecture A of if_ex is
begin
IF_PRO: process (SEL,A,B,C,D)
begin
if (SEL=00) then MUX_OUT <= A;
elsif (SEL=01) then MUX_OUT <= B;
elsif (SEL=10) then MUX_OUT <= C;
elsif (SEL=11) then MUX_OUT <= D;
else MUX_OUT <= '0';
end if;
end process; --END IF_PRO
end BEHAV;

Conseils de synthse

Vahid MEGHDADI

237

Circuit rsultant

Formation VHDL

Conseils de synthse

Vahid MEGHDADI

238

Utilisant "case"

entity case_ex is
port (SEL: in std_logic_vector
(1 downto 0);
A,B,C,D: in std_logic;
MUX_OUT: out std_logic);
end case_ex;

Formation VHDL

architecture BEHAV of case_ex is


begin
CASE_: process (SEL,A,B,C,D)
begin
case SEL is
when 00 => MUX_OUT <= A;
when 01 => MUX_OUT <= B;
when 10 => MUX_OUT <= C;
when 11 => MUX_OUT <= D;
when others=> MUX_OUT <= '0';
end case;
end process;
end BEHAV;

Conseils de synthse

Vahid MEGHDADI

239

Circuit rsultant

Formation VHDL

Conseils de synthse

Vahid MEGHDADI

240

Gnration des latch

Une instruction "if" incomplet synthtise 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 gnrer un registre et non pas un latch, on
peut sensibilis le process un front (montant par exemple)
d'une horloge.

Formation VHDL

Conseils de synthse

Vahid MEGHDADI

241

Partage des ressources


Process (A,B,C,COND)
begin
Z1 <= A+B;
Z2 <= A+C;
if COND='1' then
Z <= Z1;
else Z <= Z2;
end if;
end process;
Process (A,B,C,COND)
variable TMP :...
begin
if COND='1' then
TMP := B;
else TMP := C;
end if;
C <= TMP + A;
end process;
Formation VHDL

COND
B
A
C

COND
B

C
A
Conseils de synthse

Vahid MEGHDADI

242

Validation d'horloge

Eviter de gnrer l'horloge dans un circuit combinatoire


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

Formation VHDL

Conseils de synthse

Vahid MEGHDADI

243

Validation d'horloge (suite)

ENABLE <= IN1 and IN2 and LOAD;


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

Formation VHDL

Conseils de synthse

Vahid MEGHDADI

244

Occupation sur le FPGA


CLB

CLB

Chane de
retenue

Spartan-II, Virtex
I3
I2
I1
I0

Spartan-III, Virtex-II
SET
CE
D
Q
RST

LUT
I3
I2
I1
I0

Formation VHDL

SET
CE
D
Q
RST

Occupation sur le FPGA

Vahid MEGHDADI

245

Registre dcalage
Utilisation des bascules
4

Z-1

Z-1

Z-1

Z-1

Z-1

Z-1

Ce registre dcalage demande combien de slice ?


12 car 2 bascules par slice sont disponibles.

Formation VHDL

Occupation sur le FPGA

Vahid MEGHDADI

246

Utilisation des LUT


Multiplexeur

A
B

SEL1
SEL2
A
B

I3
I2
I1
I0

SEL1 SEL2

Ce multiplexeur demande combien de slice ?


Un seul slice.
Formation VHDL

Occupation sur le FPGA

Vahid MEGHDADI

247

Additionneur complet

A
B
Cin

Cout

I3
I2
I1
I0

sum

Sum=f(A,B,Cin)

Cout=g(A,B,Cin)

Cin

I3
I2
I1
I0

Cout

Sum

Un slice.
Formation VHDL

Occupation sur le FPGA

Vahid MEGHDADI

248

Additionneur complet Xilinx

LUT
A

Cout

Sum

Cin

Un seul slice pour l'additionneur complet.


Formation VHDL

Occupation sur le FPGA

Vahid MEGHDADI

249

La chane de retenu

Connexion rapide
I3
I2
I1
I0

SET
CE
D
Q
RST

LUT
I3
I2
I1
I0

Formation VHDL

Occupation sur le FPGA

SET
CE
D
Q
RST

Vahid MEGHDADI

250

Addition 8 bits
S8
B7
A7
B6
A6

Il suffit 4 slices pour une


addition sur 8 bits

B5
A5
B4
A4
B3
A3
B2
A2
B1
A1
B0
A0

Formation VHDL

Occupation sur le FPGA

S7
S6

S5
S4
S3
S2

S1
S0
Vahid MEGHDADI

251

Exercice

Ralisation dun UART


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

Bit de start

RX
CLK=16*bit rate
Formation VHDL

8 bits de data

Interface
UART

Bit de stop

Data suivant

DOUT
STRB
Vahid MEGHDADI

252

Vous aimerez peut-être aussi