TD Digital Synthesis of Basic Component Using VHDL-Enoncé+Solution
TD Digital Synthesis of Basic Component Using VHDL-Enoncé+Solution
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity NON is
Port ( INA1 : in STD_LOGIC; -- NOT gate input
OA : out STD_LOGIC; -- NOT gate output
end NON;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ET_2 is
Port ( A1 : in STD_LOGIC; -- AND gate input
A2 : in STD_LOGIC; -- AND gate input
X1 : out STD_LOGIC; -- AND gate output
end ET_2;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ou_2 is
Port ( B1 : in STD_LOGIC; -- OR gate input
B2 : in STD_LOGIC; -- OR gate input
Y1 : out STD_LOGIC; -- OR gate output
end OU_2;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity NON_ET_2 is
Port ( A1 : in STD_LOGIC; -- NAND gate input
A2 : in STD_LOGIC; -- NAND gate input
X1 : out STD_LOGIC; -- NAND gate output
end NON_ET_2;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity EXLUS_2 is
Port ( INA1 : in STD_LOGIC; -- XOR gate input
INA2 : in STD_LOGIC; -- XOR gate input
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half_adder is
port ( a,b : in std_logic;
sum,cout: out std_logic
);
end half_adder;
architecture adder_arch of half_adder is
begin
sum <= a xor b;
cout <= a and b;
end adder_arch;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half_adder is
port ( a,b : in std_logic;
sum,cout: out std_logic
);
end half_adder;
architecture adder_arch of half_adder is
begin
sum <= a xor b;
cout <= a and b;
end adder_arch;
b-
library IEEE;
Use IEEE. STD_LOGIC_1164.all;
entity fulladder IS
port (a,b,cin :in STD_LOGIC;
sum,carry : out STD_LOGIC);
end fulladder;
3
——————————architecture of full adder——————-
architecture structural1 of fulladder is
———————OR gate component————————-
component OU-3 is
port (a,b,c : in STD_LOGIC; z: out STD_LOGIC); -- à décrire en utilisant z <= a or b or c;
end component;
———————Xor gate component————————-
component EX-2 is
port (a,b : in STD_LOGIC; z: out STD_LOGIC); -- décrit et compile déjà exercice 1
end component;
———————AND gate component————————-
component ET-2 is
port (a,b : in STD_LOGIC; z: out STD_LOGIC); -- décrit et compile déjà exercice 1
end component;
——————————-
signal x1,x2,x3,x4 : STD_LOGIC;
begin
w1: Ex_2 port map (a,b,x1);
w2: Ex_2 port map (cin,x1,sum);
w3: ET_2 port map (a,b,x2);
w3: ET_2 port map (a,cin,x3);
w4: ET_2 port map (b,cin,x4);
w5: OU_3 port map (x2,x3,x4, cout);
end structural1;
c-
library IEEE;
Use IEEE. STD_LOGIC_1164.all;
entity fulladder IS
port (a,b,cin :in STD_LOGIC;
sum,carry : out STD_LOGIC);
end fulladder;
component half_adder is
port (a,b :in STD_LOGIC; -- décrit déjà exercice-1
sum,cout: out STD_LOGIC);
end component;
component OU_2 is
port (b1,b2 :in STD_LOGIC; -- décrit déjà exercice-1
y1: out STD_LOGIC);
end component;
end structural2;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Adder_4bits is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
Cin : in STD_LOGIC;
S : out STD_LOGIC_VECTOR (4 downto 0));
end Adder_4bits;
5
begin
end structural;
⦁
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Mux2x1 is
port( A,B,S: in std_logic; F: out std_logic);
end Mux2x1;
⦁
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux_2to1 is
Port ( SEL : in STD_LOGIC;
6
A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
X : out STD_LOGIC_VECTOR (3 downto 0));
end mux_2to1;
⦁
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux_2to1 is
Port ( SEL : in STD_LOGIC_VECTOR; -- select input
A , B : in STD_LOGIC; -- inputs
X : out STD_LOGIC); -- output
end mux_2to1;
Create a 4-to-1 multiplexer using VHDL. The multiplexer should have four data inputs, two
select lines, and one output.
⦁ using when...else
entity Mux4x1 is
port( A,B,C,D: in std_logic;
S: in std_logic_vector(1 downto 0);
F: out std_logic);
end Mux4x1;
Begin
F<= A WHEN S = "00"
else B WHEN S = "01"
else C WHEN S = "10"
else D when S = "10"
else ‘z’ when others;
end when_else;
7
⦁ Using with.....select
entity Mux4x1 is
port( A,B,C,D: in std_logic;
S: in std_logic_vector(1 downto 0);
F: out std_logic);
end Mux4x1;
Begin
with S select
F <= A when ”00”,
B when ”01”,
C when ”10”,
D when ”11”,
'z' when others;
end when_else;
f-
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Mux4x1 is
port( A,B,C,D: in std_logic;
S: in std_logic_vector(1 downto 0);
F: out std_logic);
end Mux4x1;
8
Signal F1, F2: std_logic;
Begin
M1: mux_2to1 port map(S(0),A,B,F1);
M2: mux_2to1 port map(S(0),C,D,F2);
M3: mux_2to1 port map(S(1),F1,F2,F);
end Structural;
Exercise 6: Decoder Implementation
Implement a 2-to-4 decoder in VHDL. The decoder should have two input bits and four
output lines, where each output line corresponds to one of the possible input combinations.
Library ieee;
Use ieee.std_logic_1164.all;
ENTITY Decode2to4 is
PORT ( S : OUT STD_LOGIC_VECTOR (3 downto 0);
E : IN STD_LOGIC_VECTOR (1 downto 0));
END Decode2to;
ARCHITECTURE combinatoire OF Decode2to4 IS
BEGIN
S <= "0001" WHEN E = "00"
else "0010" WHEN E = "01"
else "0100" WHEN E = "10"
else "1000" when others;
END combinatoire;
entity mux_2to1 is
Port ( SEL : in STD_LOGIC; -- select input
A , B : in STD_LOGIC; -- inputs
X : out STD_LOGIC); -- output
end mux_2to1;
9
b when '1' ;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Mux2x1 is
port( A,B,S: in std_logic; F: out std_logic);
end Mux2x1;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux_2to1_vecteur is
Port ( SEL : in STD_LOGIC;
A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
X : out STD_LOGIC_VECTOR (3 downto 0));
end mux_2to1_vecteur;
10