Vous êtes sur la page 1sur 17

Corrigé Série TD n°2 (systéme séquentiel VHDL)

Rappel

1
Exercice 1

Entré
A2 A1 A0 S1 S0
0 1 1 0 0
1 1 0 0 1
1 0 0 1 1

1) Ecrire une description VHDL qui contient :

 Assignation conditionnelle (if ) ?


 Assignation Selective (case is) ?

-- Assignation conditionnelle (if)


library ieee;
use ieee.std_logic_1164.all;

entity Test1 is
Port (
A0, A1, A2 : in std_logic;
S0, S1 : out std_logic
);
end Test1;

architecture Behavioral of Test1 is


begin
process (A0, A1, A2)
begin

if A0 = '0' and A1 = '1' and A2 = '1' then


S0 <= '0';
S1 <= '0';
elsif A0 = '1' and A1 = '1' and A2 = '0' then
S0 <= '1';
S1 <= '1';
elsif A0 = '1' and A1 = '0' and A2 = '0' then
S0 <= '1';
S1 <= '1';
else
S0 <= '0';
S1 <= '0';
end if;
end process;
end Behavioral;

2
--Ou bien
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity Test1 is
Port (
A : in std_logic_vector(2 downto 0);
S : out std_logic_vector(1 downto 0)
);
end Test1;

architecture Behavioral of Test1 is


begin
process (A)
begin
-- Assignation conditionnelle (if)
if A = "011" then
S <= "00";
elsif A = "110" then
S <= "11";
elsif A = "100" then
S <= "11";
else
S <= "00";
end if;
end process;
end Behavioral;

-- Assignation sélective (case is)


library ieee;
use ieee.std_logic_1164.all;
entity Test1 is
Port (
A : in std_logic_vector(2 downto 0);
S : out std_logic_vector(1 downto 0)
);
end Test1;

architecture Behavioral of Test1 is


begin
process (A)
begin
case A is
when "011" =>

3
S <= "00";
when "110" =>
S <= "11";
when "100" =>
S <= "11";
when others =>
S <= "00";
end case;
end process;
end Behavioral;

Exercice 2
Soit la description VHDL suivante :
Library ieee ;
Use ieee.std_logic_1164.all;

Entity test1 is
Port (A, B: in std_logic;
S1, S2, S3, S4: out std_logic

);
end test1 ;

Architecture Archi_fct1 of test1 is

begin
S1<= '1' when (a= '0' and b= '0') else '0';
S2<= '1' when (a= '1' and b= '0') else '0';
S3<= '1' when (a= '0' and b= '1') else '0';
S4<= '1' when (a= '1' and b= '1') else '0';
end Archi_fct1;

1) Déduire de ce programme le schéma bloc du circuit ?

2) De quel circuit s’agit-il ?


Le circuit décrit dans ce code VHDL est un décodeur binaire 2 vers 4.
1. Entrées :
 Le décodeur a deux entrées, A et B, qui sont chacune d'une seule ligne (un seul
bit).

4
 Ces deux entrées représentent une combinaison binaire de 2 bits, permettant
de sélectionner l'une des 4 sorties possibles.
2. Sorties :
 Le décodeur a quatre sorties, S1, S2, S3, et S4, chacune d'une seule ligne (un
seul bit).
 Chacune de ces sorties correspond à une combinaison binaire particulière des
entrées A et B.
3. Logique de décodage :
 Les lignes d'assignation des sorties utilisent des conditions "when ... else ..."
pour déterminer quelles sorties doivent être activées (à '1') en fonction des
valeurs des entrées A et B.
 Par exemple, S1 est activée (à '1') lorsque A est '0' et B est '0'. S2 est activée
lorsque A est '1' et B est '0'. S3 est activée lorsque A est '0' et B est '1'. Enfin, S4
est activée lorsque A est '1' et B est '1'.

3) Ecrire cette même fonction avec une assignation conditionnelle (if .. ?

library ieee;
use ieee.std_logic_1164.all;

entity test1 is
Port (
A, B: in std_logic;
S1, S2, S3, S4: out std_logic
);
end test1;

architecture Archi_test1 of test1 is


begin
process (A, B)
begin
if A = '0' and B = '0' then
S1 <= '1';
S2 <= '0';
S3 <= '0';
S4 <= '0';
elsif A = '1' and B = '0' then
S1 <= '0';
S2 <= '1';
S3 <= '0';

5
S4 <= '0';
elsif A = '0' and B = '1' then
S1 <= '0';
S2 <= '0';
S3 <= '1';
S4 <= '0';
else
S1 <= '0';
S2 <= '0';
S3 <= '0';
S4 <= '1';
end if;
end process;
end Archi_test1;

Ou bien en déclarant S sur 4 bits

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity test1 is
Port (
A, B: in std_logic;
S: out std_logic_vector(4 downto 1)
);
end test1;

architecture Archi_test1 of test1 is


begin
process (A, B)
begin
if A = '0' and B = '0' then
S <= "0001";
elsif A = '1' and B = '0' then
S <= "0010";
elsif A = '0' and B = '1' then
S <= "0100";
else
S <= "1000";
end if;
end process;
end Archi_test1;

4) Ecrire cette même fonction avec une assignation sélective (case is

6
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity test1 is
Port (
A, B: in std_logic;
S1, S2, S3, S4: out std_logic;
AB:inout std_logic_vector(1 downto 0)

);
end test1;

architecture Archi_fct1 of test1 is

begin

process (AB)
begin
case AB is
when "00" =>
S1 <= '1';
S2 <= '0';
S3 <= '0';
S4 <= '0';
when "01" =>
S1 <= '0';
S2 <= '1';
S3 <= '0';
S4 <= '0';
when "10" =>
S1 <= '0';
S2 <= '0';
S3 <= '1';
S4 <= '0';
when others =>
S1 <= '0';
S2 <= '0';
S3 <= '0';
S4 <= '1';
end case;
end process;
end Archi_fct1;

ou bien en déclarant S sur 4 bits

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

entity test1 is
Port (
A, B: in std_logic;
AB: inout std_logic_vector(1 downto 0);
S: out std_logic_vector(4 downto 1)
);
end test1;

architecture Archi_fct1 of test1 is


begin
process (A, B, AB)
begin
case AB is
when "00" =>
S <= "0001";
when "01" =>
S <= "0010";
when "10" =>
S <= "0100";
when others =>
S <= "1000";
end case;
end process;
end Archi_fct1;

Exercice 3

Comme indiqué dans la figure suivante, notre objectif est de concevoir une unité de
calcul en VHDL, nommée "test1". Cette entité doit effectuer les opérations logiques
XOR (ou exclusif) et AND (et logique) sur deux entrées A et B, en fonction d'une
sélection "sel" et d'un signal d'horloge "clk". Le résultat des opérations doit être
renvoyé en sortie sous le nom "r" lorsque le signal d'horloge "clk" passe de '0' à '1'.
Pour atteindre cet objectif, nous allons suivre les consignes suivantes :
1. Création de l'entité "test1" avec les ports suivants :
 A et B : deux entrées logiques de 1 bit chacune.
 sel : une entrée logique de 1 bit pour la sélection des opérations.
 clk : une entrée logique de 1 bit pour l'horloge.
 r : une sortie logique de 1 bit pour le résultat des opérations.
2. Utilisation d'une architecture de notre choix pour décrire le comportement du circuit.

8
Le circuit doit effectuer les opérations suivantes en fonction de la valeur de "sel" :
 Si "sel" est égal à '0', le circuit doit effectuer une opération XOR entre A et B.
 Si "sel" est égal à '1', le circuit doit effectuer une opération AND entre A et B.
Enfin, le résultat des opérations doit être mis à jour lorsque le signal d'horloge "clk" passe
de '0' à '1'.

En utilisant instruction if ……..


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_UNSIGNED.all;
entity test1 is
port(
A,B,sel,clk: in std_logic;
r: out std_logic
);
end test1;
architecture fonction of test1 is
signal s1,s2,s3 : std_logic;
begin
process(a,b,sel,clk)
begin
s2<=A xor B;
s1<= A and B;
if sel='0' then s3<= s2;
elsif sel='1' then s3<= s1;
end if ;
if (clk'event and clk='1') then
r<=s3;
end if;
end process ;
end fonction;

9
Avec case ..is
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_UNSIGNED.all;
entity test1 is
port(
A,B,sel,clk: in std_logic;
r: out std_logic);
end test1;
architecture fonction of test1 is
signal s1,s2,s3 : std_logic;
begin
process(a,b,sel,clk)
begin
s2<=A xor B;
s1<= A and B;
case sel is
when '0' => s3<= s2;
when '1' => s3<= s1;
end case;
if (clk'event and clk='1') then
r<=s3;
end if;
end process ;
end fonction;

Exercice 4
Écrire une description en VHDL d'une entité nommée 'test1', qui représente un
circuit composé de deux multiplexeurs (Mux1 et Mux2). Chacun de ces multiplexeurs
possède des entrées de 8 bits : Mux1 a deux entrées, a et c, tandis que Mux2 a deux
entrées, b et d. Le circuit est contrôlé par une seule entrée de sélection nommée
'sel1'.
Les sorties de ce circuit sont les suivantes :
 Pour Mux1, la sortie est nommée 'op1'.
 Pour Mux2, la sortie est nommée 'op2'.
Ces signaux 'op1' et 'op2' sont utilisés comme entrées pour un autre bloc du circuit,
qui effectue les opérations suivantes :
 'op1 + op2' (addition)
 'op1 - op2' (soustraction)
 'op1 and op2' (opération logique ET)
 'op1 or op2' (opération logique OU)
Ce bloc intermédiaire a quatre sorties internes nommées 's1', 's2', 's3', et 's4',
correspondant respectivement à chacune des opérations.

10
Ces quatre signaux 's1', 's2', 's3', et 's4' servent d'entrées à un troisième multiplexeur
nommé 'Mux3', qui est contrôlé par une entrée de sélection nommée 'sel2'. 'Mux3' a
une sortie nommée 'R'.
Enfin, la sortie 'R' est connectée à une bascule D, qui est déclenchée par une horloge
nommée 'clk'.
La sortie de la bascule D est nommée 'output'."

Ecrire une description VHDL en utilisant : if…..

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity test1 is
Port (
a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
c: in std_logic_vector(7 downto 0);
d: in std_logic_vector(7 downto 0);
sel1, CLK: in std_logic;
sel2: in std_logic_vector(1 downto 0);
output: out std_logic_vector(7 downto 0)
);
end test1;

11
architecture behavioral of test1 is
signal op1, op2, s1, s2, s3, s4, R: std_logic_vector(7 downto 0);
begin
process (a, b, c, d, sel1)
begin
if sel1 = '0' then
op1 <= a;
op2 <= b;
else
op1 <= c;
op2 <= d;
end if;
end process;

process (op1, op2, sel2)


begin
if sel2 = "00" then
R <= op1 + op2;
elsif sel2 = "01" then
R <= op1 - op2;
elsif sel2 = "10" then
R <= op1 and op2;
elsif sel2 = "11" then
R <= op1 or op2;
else
R <= "XXXXXXXX";
end if;
end process;

process (CLK)
begin
--if (rising_edge(CLK)) then
--o <= R;
if (CLK'event and CLK='0' ) then output <=R;

end if;
end process;
end behavioral;

Ecrire une description VHDL en utilisant : case …is

library ieee;

12
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity test1 is
Port (
a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
c: in std_logic_vector(7 downto 0);
d: in std_logic_vector(7 downto 0);
sel1, CLK: in std_logic;
sel2: in std_logic_vector(1 downto 0);
output: out std_logic_vector(7 downto 0)
);
end test1;
architecture behavioral of test1 is
signal op1, op2, s1, s2, s3, s4, R: std_logic_vector(7 downto 0);
begin
process (a, b, c, d, sel1)
begin
case sel1 is
when '0' =>
op1 <= a;
op2 <= b;
when others =>
op1 <= c;
op2 <= d;
end case;
end process;

process (op1, op2, sel2)


begin
case sel2 is
when "00" =>
R <= op1 + op2;
when "01" =>
R <= op1 - op2;
when "10" =>
R <= op1 and op2;
when "11" =>
R <= op1 or op2;
when others =>
R <= "XXXXXXXX";
end case;
end process;

13
process (CLK)
begin
--if (rising_edge(CLK)) then
--o <= R;
if (CLK'event and CLK = '0') then
output <= R;
end if;
end process;
end behavioral;

Ecrire une description VHDL en utilisant : if et case is


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity test1 is
Port (
a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
c: in std_logic_vector(7 downto 0);
d: in std_logic_vector(7 downto 0);
sel1, CLK: in std_logic;
sel2: in std_logic_vector(1 downto 0);
o: out std_logic_vector(7 downto 0)
);
end test1;

architecture behavioral of test1 is


signal op1, op2, s1, s2, s3, s4, R: std_logic_vector(7 downto 0);
begin
process (sel1)
begin
if sel1 = '0' then
op1 <= a;
op2 <= b;
else
op1 <= c;
op2 <= d;

14
end if;
end process;

s1 <= op1 + op2;


s2 <= op1 - op2;
s3 <= op1 and op2;
s4 <= op1 or op2;

process (sel2)
begin
case sel2 is
when "00" =>
R <= s1;
when "01" =>
R <= s2;
when "10" =>
R <= s3;
when "11" =>
R <= s4;
when others =>
R <= "XXXXXXXX";
end case;
end process;

process (CLK)
begin
--if (rising_edge(CLK)) then
--o <= R;
if (CLK'event and CLK='0' ) then o <=R;

end if;
end process;
end behavioral;

15
Exercice 5

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;

entity porte is
port (
A, B, C, D, E, Cin, clk: in std_logic;
output, cout: out std_logic;
Sel: in std_logic
);
end porte;

architecture UAL_porte of porte is


signal sum: std_logic_vector (1 downto 0);
signal s1, s2, s3, s4, s5, Result: std_logic;
begin

-- Opération AND
s1 <= A and B;

-- Opération OR
s2 <= C and D;

-- Opération XOR
s3 <= s1 or s2;
s4 <= E and s3;

16
-- Opération de la somme (sum)
sum <= (A & A) + (B & B) + Cin;
s5 <= sum(0);
cout <= sum(1);

-- Multiplexeur (MUX)
process (Sel)
begin
case Sel is
when '0' =>
Result <= s4;
when others =>
Result <= s5;
end case;
end process;
-- Bascule D
process (clk)
begin
if rising_edge(clk) then
output <= Result;
end if;
end process;
end UAL_porte;

17

Vous aimerez peut-être aussi