Académique Documents
Professionnel Documents
Culture Documents
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
2
Circuit à fonctionnement programmable
3
Circuit à architecture programmable
4
Les ASIC
5
ASIC ou FPGA ?
ASICs FPGAs
High performance
6
Evolution : Méthodes de CAO
Conception logique
Synthèse comportemental
Formation VHDL Introduction Vahid MEGHDADI
7
Démonstrateurs
8
Exemple
Extension
JTAG
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
10
Intérêt de la logique par rapport à µP
11
Fonction combinatoires
PLA1
PLA2
PLA3
O0 O1 O2 O3
12
PLA
13
CPLD
I/O I/O
PLD PLD
I/O I/O
PLD Global PLD
Interconnection
14
Architecture des FPGA
Feild Programmable Gate Array
15
FPGA architecture interne
Clock
Programmable Programmable
IO Logic (CLB)
BLE
#1
N
N
I Outputs
I
Inputs BLE
#N
Clock
Programmable
Routing
16
Architecture de CLB
Inputs Look-Up
Out
Table
(LUT)
Out = f (in0, in1, in2, in3)
State
Clock
Enable
17
FPGA Xilinx
18
Spartan
19
Spartan II
Ajout de la RAM
20
La famille Spartan II
21
Spartan 3
22
La famille Virtex
•Plus de I/O
•DSP slices
23
La famille Virtex
24
La famille Virtex-II pro
25
Virtex 5 et le LUT
26
Virtex 5 et les blocs DSP
27
Série 7
28
Conception circuit
29
Design flow
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
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
32
Placement & Routage
HDL
(VHDL /
Verilog)
Synthesize
Netlist
Map
Place
Route
Bitstream
33
Insertion d’un microprocesseur (SoC)
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
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
Images by H.Walder
Formation VHDL Introduction Vahid MEGHDADI
36
System on Chip Configurable (CSoC)
Audio
Codec EPROM
Power Supply
L
C
37
Avantages
38
CPUs Embarqués
39
Architecture de MicroBlaze
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)
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
43
Formation VHDL Vahid MEGHDADI
44
Chapitre : Introduction A VHDL
Introduction au langage
VHDL
45
VHDL
V VHSIC
(Very High Speed Integradted Circuit)
H Hardware
D Description
L Language
46
Un peu d’histoire
47
Qu’est ce que on attend de VHDL
48
Qu’est ce que on attend des outils de synthèse
49
Démarche de synthèse
Partitionnement logicielle/matérielles
ASIC
Discret
50
Niveau d’abstraction
Synthèse Comportemental
comportemental
RTL VHDL
Synthèse
logique
Logique
Placement
routage
Layout
51
Formation VHDL Introduction A VHDL Vahid MEGHDADI
52
Chapitre : Structure du VHDL
53
Domaine concurrent et séquentiel
54
Classes d’objets
55
Types d’objets
56
Les opérateurs
57
Programmer en VHDL
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)
•Syntaxe:
entity nom_de_l_entite is
{generic(liste_des_parametres)}
{port(liste_des_port_avec_leutr_mode)}
end {nom_de_l_entite}
61
Entité
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;
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 ;
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
64
Chapitre : Architecture
Syntaxe:
architecture nom_de_l_architecture of nom_de_l_entite is
{partie déclarative}
begin
65
Affectation aux signaux
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;
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
68
Exemple 1, programme
entity DEMI_ADD is
port (A,B: in std_logic;
SUM,C: out std_logic);
end DEMI_ADD;
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;
70
Formation VHDL Vahid MEGHDADI
71
Formation VHDL Vahid MEGHDADI
72
Chapitre : Types en VHDL
73
Types, schéma global
Types
Enregistre
énumérés Entier Réel Physique Tableau ment
(record)
74
Déclaration de type
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
76
Type énuméré
77
Type entier (scalaire)
78
Logique à valeurs multiples (scalaire)
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’
80
Type composite
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);
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');
• 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;
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
84
Exemples
85
Enregistrement (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
89
Instruction with
90
Instruction when
ENA1
8 8
REG1
ENA2
8
REG2
91
Exemple
entity CIR is
port (A,B,C,D : in std_logic;
s : out std_logic);
end CIR;
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;
93
Formation VHDL Vahid MEGHDADI
94
Formation VHDL Vahid MEGHDADI
95
Formation VHDL Vahid MEGHDADI
96
Chapitre: zone séquentielle
97
Process
98
Syntaxe de process
•Syntaxe de process :
label : -- optionnel
process (liste de sensibilité)
{partie déclarative}
begin
suite d’instructions séquentielles
end process;
99
Instructions séquentielles
100
Instructions wait
• wait on signal;
•wait on A , B
101
Instructions if
if condition then
sequential statements
[elsif condition then
sequential statements ]
[elsif condition then
sequential statements ]
[else
sequential statements ]
end if;
102
Instruction case
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;
103
Instruction for
104
Exemple
Multiplexeur 4 voies
S1 S0
A
M
B Z
U
C X
4
D
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;
end behav_MUX_4;
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;
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;
end behav_MUX_4;
Formation VHDL Process Vahid MEGHDADI
108
Affectation des signaux
109
Affectation dans une architecture
A
B
Z
?
C
D
Formation VHDL Process Vahid MEGHDADI
110
Affectation dans un process
Z <= C and D;
end process; -- la valeur retenue est affectée maintenant
end CONCUR;
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;
112
Exemple d’appel multiple
113
Exemple d’appel multiple
A:0
Y:0
B:1
M:1
M:1
Z :1
Z :0
114
Les variables
115
Formation VHDL Vahid MEGHDADI
116
Chapitre : Hiérarchisation
117
Déclaration du component
component DEMI_ADD
port(A,B : in std_logic;
SUM,C: out std_logic);
end component;
118
Instantiation du component
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);
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
120
Description flot de données
entity DEMI_ADD is
port (A,B: in std_logic;
SUM,C: out std_logic);
end DEMI_ADD;
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;
122
Instantiation
123
Chapitre : Déroulement d’un programme VHDL
process
process
Signal x,y
Signal t,u
process
Formation VHDL Déroulement d’un programme VHDL Vahid MEGHDADI
124
Déroulement de simulation
125
Deux files d'attente
126
Traitement des files
Repérer les
signaux changés
Repérer les
File process à réveiller File
signal process
127
Avancement dans le temps
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
129
Circuits combinatoires : équation logique
130
Exemple
131
Affectation avec if
end if;
end process;
end AVEC_IF;
132
Affectation avec case
133
Affectation sélective
134
Affectation non conditionnelle
135
Affectation avec when
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;
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;
138
Exemple : Multiplieur
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)
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;
140
Exemple : Multiplieur, résultat de synthèse
141
Formation VHDL Vahid MEGHDADI
142
Formation VHDL Vahid MEGHDADI
143
Formation VHDL Vahid MEGHDADI
144
Chapitre : Circuits séquentiels
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)
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
RAZ
S2 S1 S0
E 2 2 S
D Q
H
CLK QB
RAZ
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
RAZ
Entree
S
H
RAZ
151
Exercice: Registre à décalage série
152
Exercice : Registre à décalage série
RAZ
Entree
Sortie
H
RAZ
153
Exercice : Registre à décalage série 2 (suite)
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
155
Exercice : Registre à chargement parallèle et décalage sériel
156
Attention !
157
Correction
On utilise un process D Q
158
Attention sur les process synchrones!
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;
159
Formation VHDL Vahid MEGHDADI
160
Chapitre : Machine à états finis
•L’état interne est préservé dans des registres (bascules). Une machine à 5
états comporte au moins 3 bascules.
161
Présentation graphique
E1E2= "1-"
Formation VHDL Vahid MEGHDADI
162
Séparation des logiques
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;
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
165
Programmation logique séparée
166
Programmation de la partie combinatoire G
167
Programmation de la partie combinatoire F
168
Rappels (1)
169
Rappels (2)
170
Exemple de la partie combinatoire F
171
Exemple de la partie combinatoire F
CLK HS
fclk=25MHz
172
Conception RTL
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;
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
176
Exemple 1: Timer
Exemple 1
CLK
Down counter
Vcc
D IRQ*
Q*
D_FF
CLK
RSET*
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;
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;
179
Exemple 1 suite : Circuit complet (1)
entity test2 is
Port ( CLK_IN,ACK, RESET : in std_logic;
IRQ : out std_logic);
end test2;
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 );
end Behavioral;
181
Exemple 2
R
CLK
O
RAZ V
182
Entité
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;
183
Architecture (1)
184
Architecture (2)
185
Rapport de mapping
186
Utilisation des process séparés
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
Clavier
FPGA
CODE LIN
COL
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;
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;
191
Partie machine à état
192
Partie décodage
193
Exemple 4, affichage multiplexé
194
Préparation de l’horloge
195
Machine à états
196
Circuit complet
197
Exemple 5
z z0 z1 z7
198
En VHDL
component FULL_ADD
port(A,B,CIN : in std_logic;
S,COUT : out std_logic);
end component;
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
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;
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
203
Exemple 6- UART en émission
204
Exemple 6- UART en émission
205
Exemple 7- CNA AD5541A
206
Exemple 7- AD5541A Timing Diagram
Génération de LDAC
207
Exemple 7- AD5541A contraintes de Timing
Fclk=25MHz
On fixe à 1/25MHz=40ns
208
Exemple 7- Interface CNA
209
Exemple 7- Conception
210
Exemple 7- Programmation un seul process
211
Exemple 7- Conception robuste
212
Exemple 7- Résultat de simulation
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
215
Chapitre : Notions avancés
Notions
avancés
Formation VHDL Vahid MEGHDADI
216
Généricité
Syntaxe :
generic (param1 : type de param1 := valeur par défaut;
param2 : type de param2 := valeur par défaut;
...);
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;
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
219
Paquetage
220
Syntaxe de Paquetage
Package <nom_de_paquetage> is
suite de déclarations>
end {<nom_de_paquetage>};
package pak_test is
221
Paquetage de composants
222
Corps de Paquetage
223
Exemple de Corps de Paquetage
end pak_test;
Formation VHDL Paquetage Vahid MEGHDADI
224
Utilisation de paquetage
225
Configuration
226
Choix de l'architecture
227
Exemple de Configuration
228
Exemple de Configuration "à la volée"
229
Les sous-programmes
230
Procédure
231
Fonction
232
Ecriture des sous-programmes
Syntaxe de la déclaration
•procedure <nom> (liste des paramètre);
•function <nom> (liste des paramètre) return type_du_résultat;
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
Exemple
function MIN (signal A,B : integer) return integer is
begin
if A < B then return A
else return B
end if;
end MIN;
235
Appel de sous-programme
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
237
Programmation concurrente
238
Utilisation de fonction
239
Les Attributs
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
Formation VHDL Encodage d'état dans une machine à état Vahid MEGHDADI
242
Codage one-hot
Formation VHDL Encodage d'état dans une machine à état Vahid MEGHDADI
243
If Generate
end A;
Formation VHDL If generate Vahid MEGHDADI
244
for Generate
245
Formation VHDL Vahid MEGHDADI
246
Formation VHDL Vahid MEGHDADI
247
Conseils de synthèse
248
Conseils (2)
249
Conseils (3)
250
Ordre des opérations
A1
A2 ADD
A3 Un circuit plus rapide
A4
Formation VHDL Conseils de synthèse Vahid MEGHDADI
251
"if" ou "case", la différence
252
Circuit résultant
253
Utilisant "case"
254
Circuit résultant
255
Génération des latch
256
Partage des ressources
257
Validation d'horloge
258
Validation d'horloge (suite)
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
260
Registre à décalage
4
Z-1 Z-1 Z-1 Z-1 Z-1 Z-1
261
Utilisation des LUT
Multiplexeur
A SEL1 I3
B SEL2 I2 O
A I1
B I0
SEL1 SEL2
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
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
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
266
Exercice
8
RX Interface DOUT
267