TD2 Correction
TD2 Correction
Correction TD 2
VHDL : conception circuits numériques combinatoires
Avril 2025
1 Correction exercice 1 :
1.1 Buffer Unidirectionnel
1.1.1 Entité
Listing 1 – Entité
4 -- Definition Entite
5 entity Three_State_Unidir is
6 port ( E,Cde : in std_logic;
7 S : out std_logic);
8 end entity Three_State_Unidir;
1.1.2 Architecture 1
Listing 2 – Architecture 1
1 -- definition Architecture 1
2 architecture a1 of TriState_Unidir is
3 begin
4 S <= E when cde = '1' else 'Z';
5 end architecture a1;
1.1.3 Architecture 2
Listing 3 – Architecture 2
1 -- definition Architecture 2
2 architecture a2 of Thrree_State_Unidir is
3 begin
4 process (E,Cde)
5 begin
6 if (Cde = '1') then
7 S <= E ;
8 else
9 S<= 'Z';
10 end if ;
11 end process;
12 end architecture a2;
4 --Entite Definition
5 entity Three_State_bidir is
6 port ( E,Cde : in std_logic;
7 S : out std_logic;
8 IO : inout std_logic);
9 end entity Three_State_bidir;
1.2.2 Architecture
2 Correction exercice 2 :
2.1 Équation
Q = A · B · I0 + A · B · I1 + A · B · I2 + A · B · I3
2.2 Entité
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 entity Mux4 is
4 port ( I0,I1,I2,I3,A,B : in std_logic;
5 Q : out std_logic);
6 end entity Mux4;
2.3 Architectures
8 I1 when "01",
9 I2 when "10",
10 I3 when "11",
11 'X' when others;
12 end architecture arch_flotData2;
AND3
La figure suivante représente le composant logique AN D3
Figure 2 – AND3
1 library IEEE;
2 use IEEE.std_logic_1164.all;
3 entity AND3 is
4 Port (e0,e1,e2 : in std_logic ;
5 s : out std_logic);
6 end AND3;
OR4
La figure suivante représente le composant logique OR4
Listing 12 – Conception OR4
1 library IEEE;
2 use IEEE.std_logic_1164.all;
3 entity OR4 is
4 Port (e0,e1,e2,e3 : in std_logic ;
Figure 3 – OR4
5 s : out std_logic);
6 end OR4;
2 component AND3 is
3 Port (e0,e1,e2 : in std_logic ;
4 s : out std_logic);
5 end component AND3;
6 component OR4 is
7 Port (e0,e1,e2,e3 : in std_logic ;
8 s : out std_logic);
9 end component OR4;
10 --signaux internes
11 signal x0,x1,x2,x3 : std_logic ;
12 signal notA, notB : std_logic ;
13 begin
14 --Preparation des signaux inversees
15 notA <= not(A);
16 notB <= not(B);
17
1 library IEEE;
2 use IEEE.std_logic_1164.all;
14 begin
15 --instatiation et port mapping
16 UT: Mux4 port map (t_I0,t_I1,t_I2,t_I3,t_A,t_B,t_Q);
17
30
31 t_I0 <= '0';
32 t_I1 <= 'Z';
33 t_I2 <= '0';
34 t_I3 <= '1';
35 wait for 50 ns;
36 t_A <= '0';
37 t_B <= '1';
38 wait for 100 ns;
3 Correction exercice 3 :
Figure 7 – Demux 1 à 8
1 library IEEE;
2 use IEEE.std_logic_1164.all;
3 use IEEE.numeric_std.all;
4 entity Demux_1_To_8 is
5 port (G : in std_logic;
6 A : in std_logic_vector(2 downto 0);
7 Y : out std_logic_vector(7 downto 0) );
8 end Demux_1_To_8;
50 --Update Output
51 y<= temp;
52 END PROCESS;
53 end architecture arch2;
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use IEEE.numeric_std.all;
4 entity Test_Demux is
5 end entity Test_Demux;
7 component Demux_1_To_8 is
8 port (G : in std_logic;
9 A : in std_logic_vector(2 downto 0);
10 Y : out std_logic_vector(7 downto 0) );
11 end component Demux_1_To_8;
16 begin
17 UU : Demux_1_To_8 port map (t_G,t_A,t_Y);
18
19 process
20 begin
21 t_G<= '0';
4 Correction exercice 4 :
1 library ieee;
2 use ieee.std_logic_1164.all; -- std_logic
3 use ieee.numeric_std.all; -- Conversion
4 entity Priority_Encoder_8_To_3 is
11 begin
12 process(E)
13 begin
14 --Calcul GS
15 if (E= zeros) then -- E = "0000 0000"
16 GS <= '1';
17 else
18 GS <= '0';
19 end if;
20 -- Determination de S
21 for I in E'range loop -- E'range :7,6,5,4,3,2,1,0
22 if E(I) = '1' then
23 S <= std_logic_vector(To_Unsigned(I,3));
24 exit ;
25 end if;
26 end loop;
27
28 end process;
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use IEEE.numeric_std.all;
4 entity test_Priority_Encoder is
5 end entity test_Priority_Encoder;
7 --Importation du composant
8 component Priority_Encode_8_to_3 is
9 port (E: in std_logic_vector (7 downto 0);
10 S : out std_logic_vector (2 downto 0);
11 GS : out std_logic);
12 end component Priority_Encode_8_to_3;
18 begin
19 --instantiation et port mapping
20 UT : Priority_Encode_8_to_3 port map(t_E,t_S,t_GS);
21
22 process
23 begin
24 en <= (others => '0');
25 wait for 100 ns;
26
27 b0 : for i in 0 to 2**8 loop
28 t_E <= std_logic_vector (en);
29 en <= en +1;
30 wait for 100 ns;
31 end loop b0;
32
33 end process;
34 end architecture testbench;
1 library IEEE;
2 use IEEE.std_logic_1164.all;
3 use ieee.numeric_std.all; -- Conversion
4 entity Priority_Encode is
5 generic (n : positive);
6 port (E: in std_logic_vector ((2**n)-1 downto 0);
7 S : out std_logic_vector (n-1 downto 0);
8 GS : out std_logic);
9 end entity Priority_Encode;
19 GS <= '0';
20 end if ;
21
22 S <= (Others => '0'); -- Faire sortir 0
23 cherche : for I in E'Range loop
24 if ( E(I) = '1' ) then
25 S <= std_logic_vector(To_Unsigned(I,n));
26 exit cherche; -- sortir de la boucle cherche
27 end if;
28 end loop cherche;
29 end process;
30 end architecture arch;
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use IEEE.numeric_std.all;
4 entity test_Priority_Encoder_Gen is
5 generic (m : positive := 8 );
6 end entity test_Priority_Encoder_Gen;
8 component Priority_Encode is
9 generic (n : positive);
10 port (E: in std_logic_vector ((2**n)-1 downto 0);
11 S : out std_logic_vector (n-1 downto 0);
12 GS : out std_logic);
13 end component Priority_Encode;
18 begin
19 UT : Priority_Encode generic map (m) port map(t_E,t_S,t_GS);
20
21 process
22 begin
23 en <= (others => '0');
24 wait for 100 ns;
25
26 b0 : for i in 0 to 2**m loop
27 t_E <= std_logic_vector (en);
28 en <= en +1;