Correction_TD3
Correction_TD3
Correction TD 3
Circuits séquentiels VHDL
Avril 2024
1 Correction exercice 1 :
Figure 1 – Mux2_Syn
Listing 1 – Mux2_sync
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 --Definition d'entite
4 entity Mux2_Syn is
5 Port (D0,D1,CLK,Sel : in std_logic;
6 Q : out std_logic);
7 end Mux2_Syn;
1 Library IEEE;
2 use IEEE.std_logic_1164.All;
3 Entity test_Mux2_Syn is
4 end test_Mux2_Syn; --Empty entitu
6 --Importation composant
7 Component Mux2_Syn is
8 Port (D0,D1,CLK,Sel : in std_logic;
9 Q : out std_logic);
10 end Component;
11 --Signaux de test
12 signal t_D0,t_D1, t_sel,t_Q : std_logic ;
13 signal t_clk : std_logic := '0';
14 begin
15 --Instantiation et port mapping
16 U1 : Mux2_Syn port map (t_D0,t_D1,t_clk,t_sel,t_Q);
17 t_clk <= not (t_clk) after 50 ns; --Generatation Horloge
18 stimulus : process
2 Correction exercice 2 :
2.1 Conception Reg_8
Figure 2 – Reg8
Listing 3 – Reg_8
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 entity Reg8 is
4 port (D : in std_logic_vector (7 downto 0);
5 CLK,reset : in std_logic;
6 Q : out std_logic_vector (7 downto 0));
7 end Reg8;
8 architecture arch of Reg8 is
9 --signal memorisation
10 signal x : std_logic_vector(7 downto 0);
11 begin
12 process (CLK,reset)
13 begin
14 if ( reset = '0') then --Reset Asynchrone
15 x <= (others => '0') ; -- "0000 0000"
16 elsif (clk'event and clk='1') then
17 x <= D;
18 end if;
19 end process;
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 entity TB_Reg8 is
4 end TB_Reg8;
6 Component Reg8 is
7 port (D : in std_logic_vector (7 downto 0);
8 CLK,reset : in std_logic;
9 Q : out std_logic_vector (7 downto 0));
10 end Component;
14 begin
15 UT : Reg8 port map (t_D,t_clk,t_reset,t_Q);
16 t_clk <= not (t_clk ) after 25 ns;
17 process
18 begin
19 t_D <= (others => '1');
20 t_reset <= '0';
21 wait for 200 ns;
22 t_reset <= '1';
23 wait for 100 ns;
24 end process;
25 end testBench;
Listing 5 – Reg_n
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
Figure 3 – Regn
3 --Entite
4 Entity Reg_n is
5 generic (n : positive);
6 port (D : in std_logic_vector ((n-1) downto 0);
7 clk, reset : in std_logic;
8 Q : out std_logic_vector ((n-1) downto 0) );
9 end Reg_n;
10 --Architecture
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 entity TB_Reg_n is
5 generic (h : positive := 16);
6 end TB_Reg_n;
15 -- signaux interne
16 signal t_clk : std_logic := '0';
17 signal t_D,t_Q : std_logic_vector ( (h-1) downto 0);
18 signal t_reset : std_logic;
19 signal x : integer;
20 begin
21 --Instantiation , generic map and port mapping
22 UT : Reg_n generic map(h) port map (t_D,t_clk,t_reset,t_Q);
23 --Genration du signal carre
24 t_clk <= not (t_clk) after 25 ns;
25 process
26 begin
27 t_reset <= '0';
28 x <= 15;
29 t_D <= conv_std_logic_vector (x,h);
30 wait for 100 ns;
3 Correction exercice 3 :
Listing 7 – Shifter 4
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 use IEEE.std_logic_arith.all;
4 --Conv_Std_logic_vetor(X,n)
5 -- X : entier
6 -- n taille std_logic_vector
7 --Convertie un entier X vers un std_logic_vector coded
8 -- sur n bits
9 entity shifter4 is
10 port (R : in std_logic_vector(3 downto 0);
11 clk, load,left,right : in std_logic;
12 Q : out std_logic_vector(3 downto 0));
13 end shifter4;
56 for I in 0 to 2 loop
57 X(I) <= X(I+1);
58 end loop;
59 X(3) <= '0';
60 end if;
61 end if;
62 end if;
63 end process;
64 end Arch2;
65 -- Arch3
66 Architecture Arch3 of shifter4 is
72 process (clk,load)
73 begin
74 if (load ='0') then
75 x <= R;
76 elsif (load ='1') then
77 if (clk'event and clk = '1') then
78 if (left = '1' and right ='0')then
79 -- decalage gauche
80 --X convertie en unsigned puis affecter a V
81 v <= unsigned (x);
82 --Decalage
83 --v <= v * unsigned (3 downto 0) (2);
84 -- v <= v * unsigned(d);
85 v <= v * deux;
86 x <= Conv_Std_logic_vetor (V,4);
87 elsif (left ='0' and right ='1') then
88 -- Decalage Droite
89 v <= unsigned(x);
90 v <= v/deux;
91 x <= Conv_Std_logic_vetor (V,4);
92 end if;
93 end if;
94 end if;
95 end process;
96 Q <= x; -- Update output
97 end Arch3;
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 entity test_Shifter4 is
4 end test_Shifter4;
6 component shifter4 is
7 port (Load ,left,right,clk : in std_logic;
8 R : in std_logic_vector (3 downto 0);
9 Q : out std_logic_vector (3 downto 0) );
10 end component;
14 begin
15 clock <= not (clock) after 25 ns;
17 process
18 begin
19 Rin <= "0000";
20 Ld <= '1';
21 Lt <= '1';
22 Rt <= '1';
30 --Decalge Left
31 Rin <= "0001";
32 Ld <= '1';
33 Lt <= '1';
34 Rt <= '0';
36 --Decalge Droite
37 Rin <= "0010";
38 Ld <= '1';
39 Lt <= '0';
40 Rt <= '1';
4 Correction exercice 4 :
Figure 5 – ROM_128_8
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 entity ROM_128_8 is
5 port ( ADD : in std_logic_vector (6 downto 0);
5 Correction exercice 5 :
1 Library IEEE;
2 use IEEE.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 entity RAM_SP_32_8 is
5 port ( H,RW, Enable : in std_logic;
6 ADD : in std_logic_vector ( 4 downto 0);
7 DATA_IN : in std_logic_vector ( 7 downto 0);
8 DATA_OUT : out std_logic_vector ( 7 downto 0));
9 end RAM_SP_32_8;
16 begin
17 process (H,Enable,ADD,RW)
18 begin
19 if (Enable = '0')then
20 DATA_OUT <= (others => 'Z');
21 elsif (Enable ='1') then
22 if ( H = '1' and H'event ) then
23 if (RW = '0') then --Write
24 memoire(TO_INTEGER (unsigned (ADD))) <= DATA_IN;
25 elsif (RW = '1') then --Read
26 DATA_OUT <= memoire(TO_INTEGER (unsigned (ADD)));
27 end if ;
28 end if;
29 end if;
30 end process;
31 end compr_SP_RAM;
1 library IEEE;
2 use IEEE.STD_LOGIC_1164.ALL;
3 use IEEE.NUMERIC_STD.ALL;
4 entity tB_SP_RAM is
5 end tB_SP_RAM;
7 component RAM_SP_32_8 is
8 port ( H,RW, Enable : in std_logic;
9 ADD : in std_logic_vector ( 4 downto 0);
10 DATA_IN : in std_logic_vector ( 7 downto 0);
11 DATA_OUT : out std_logic_vector ( 7 downto 0));
12 end component;
13 --Sigaux Internes
14 Signal clock : std_logic := '0';
15 signal t_RW, t_Enable : std_logic;
16 signal t_ADD : std_logic_vector ( 4 downto 0);
17 signal t_DATA_IN, t_DATA_OUT : std_logic_vector ( 7 downto 0);
19 begin
22 process
23 begin
24 t_Enable <= '0';
25 t_RW <= '0';
26 t_ADD <= (t_ADD'range => '0');
27 t_DATA_IN <= ( t_DATA_IN'range => '0');
29 -- Test Write
30 t_enable <= '1';
31 for i in 0 to 31 loop
32 t_DATA_IN <= t_DATA_IN + "10";
35 end loop;
40 -- Test Read
41 t_enable <= '1';
42 t_RW <= '1';
43 for i in 0 to 31 loop
47 end loop;
48 end process;
49 end testbench;
6 Correction exercice 6 :
1 Library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 entity RAM_DP_32_8 is
5 port (H,Write_Enable : in std_logic;
6 WRITE_ADD,READ_ADD : in std_logic_vector (4 downto 0);
7 DATA_IN : in std_logic_vector (7 downto 0);
8 DATA_OUT : out std_logic_vector(7 downto 0));
9 end RAM_DP_32_8;
17 begin
18 process (H,Write_Enable)
19 begin
20 if (Write_Enable = '1') then --Ecriture dans RAM
21 if (H'event and H='1')then
22 memoire(TO_INTEGER(unsigned(WRITE_ADD))) <= DATA_IN;
23 end if;
24 else --Lecture du RAM
25 if (H'event and H='0') then
26 DATA_OUT <= memoire(TO_INTEGER(unsigned (READ_ADD)));
27 end if;
28 end if;
29 end process;
30 end Arch;
1 Library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.all;
4 entity RAM_DP_32_8_tb is
5 end RAM_DP_32_8_tb;
7 Component RAM_DP_32_8 is
8 port (H,Write_Enable : in std_logic;
9 WRITE_ADD,READ_ADD : in std_logic_vector (4 downto 0);
10 DATA_IN : in std_logic_vector (7 downto 0);
11 DATA_OUT : out std_logic_vector(7 downto 0));
12 end Component;
13 --Sigaux Internes
14 Signal clock : std_logic := '0';
15 signal t_Write_Enable : std_logic;
16 signal t_WRITE_ADD, t_READ_ADD : std_logic_vector (4 downto 0);
17 signal t_DATA_IN, t_DATA_OUT : std_logic_vector (7 downto 0);
18 constant PERIOD : time := 25 ns;
19 begin
20 U1 : RAM_DP_32_8 port map (clock,t_Write_Enable,t_WRITE_ADD,
21 t_READ_ADD,t_DATA_IN, t_DATA_OUT);
22 clock <= not(clock) after PERIOD;
23 process
24 begin
25 --initialisation
26 t_Write_Enable <= '0';
27 t_WRITE_ADD <= (others => '0');
28 t_READ_ADD <= (others => '0');
29 t_DATA_IN <= (others => '0');
41 end loop;
42 end process;
43 end TESTBENCH;