VHDL TD - Corrigé
VHDL TD - Corrigé
-1-
Université Sultan Moulay Slimane
Faculté des sciences et Techniques Béni Mellal
Département de Génie Electrique
Exercice 3 :
library ieee;
use ieee.std_logic_1164.all;
entity FullSub is port (
a,b,cin : in std_logic;
d,cout : out std_logic
);
end FullSub;
architecture arch of FullSub is
begin
d <= a xor b xor cin;
cout <= (not(a) and b) or (cin and (not(a) or b));
end arch;
Exercice 4 :
library ieee;
use ieee.std_logic_1164.all;
entity Sub8bits is port (
A : in std_logic_vector(7 downto 0);
B : in std_logic_vector(7 downto 0);
D : out std_logic_vector(7 downto 0);
cout : out std_logic);
end Sub8bits;
architecture arch of Sub8bits is
component FullSub is port (
a,b,cin : in std_logic;
d,cout : out std_logic
);
end component;
signal S1,S2,S3,S4,S5,S6,S7 : std_logic;
begin
FullSub1 : FullSub port map (A(0),B(0),'0',D(0),S1);
FullSub2 : FullSub port map (A(1),B(1),S1,D(1),S2);
FullSub3 : FullSub port map (A(2),B(2),S2,D(2),S3);
FullSub4 : FullSub port map (A(3),B(3),S3,D(3),S4);
FullSub5 : FullSub port map (A(4),B(4),S4,D(4),S5);
FullSub6 : FullSub port map (A(5),B(5),S5,D(5),S6);
FullSub7 : FullSub port map (A(6),B(6),S6,D(6),S7);
FullSub8 : FullSub port map (A(7),B(7),S7,D(7),cout);
end arch;
Exercice 5 :
library ieee;
use ieee.std_logic_1164.all;
entity And8bits is port(
A,B : in std_logic_vector(7 downto 0);
S : out std_logic_vector(7 downto 0)
);
end And8bits;
-2-
Université Sultan Moulay Slimane
Faculté des sciences et Techniques Béni Mellal
Département de Génie Electrique
-3-
Université Sultan Moulay Slimane
Faculté des sciences et Techniques Béni Mellal
Département de Génie Electrique
Exercice 8 :
library ieee;
use ieee.std_logic_1164.all;
entity UAL is port(
A,B : in std_logic_vector (7 downto 0);
SEL : in std_logic_vector (1 downto 0);
R : out std_logic_vector (7 downto 0);
sout,rout : out std_logic
);
end UAL;
architecture arch of UAL is
component Add8bits is port (
A : in std_logic_vector(7 downto 0);
B : in std_logic_vector(7 downto 0);
S : out std_logic_vector(7 downto 0);
cout : out std_logic);
end component;
component Sub8bits is port (
A : in std_logic_vector(7 downto 0);
B : in std_logic_vector(7 downto 0);
D : out std_logic_vector(7 downto 0);
cout : out std_logic);
end component;
component And8bits is port(
A,B : in std_logic_vector(7 downto 0);
S : out std_logic_vector(7 downto 0)
);
end component;
component Or8bits is port(
A,B : in std_logic_vector(7 downto 0);
S : out std_logic_vector(7 downto 0)
);
end component;
component MUX4x8_8 is port(
E1,E2,E3,E4 : in std_logic_vector (7 downto 0);
SEL : in std_logic_vector (1 downto 0);
S : out std_logic_vector (7 downto 0)
);
end component;
Signal S1,S2,S3,S4 : std_logic_vector(7 downto 0);
begin
AddOp : Add8bits port map (A,B,S1,sout);
SubOp : Sub8bits port map (A,B,S2,rout);
AndOp : And8bits port map (A,B,S3);
OrOp : Or8bits port map (A,B,S4);
MuxOp : MUX4x8_8 port map (S1,S2,S3,S4,SEL,R);
end arch;
-4-
Université Sultan Moulay Slimane
Faculté des sciences et Techniques Béni Mellal
Département de Génie Electrique
Exercice 9 :
library ieee;
use ieee.std_logic_1164.all;
entity JKH is port (
J,K,H,CLR,PRE : in std_logic;
Q,Qb : out std_logic
);
end JKH;
architecture arch of JKH is
signal S : std_logic;
begin
process (H,CLR,PRE)
begin
if (CLR = '0') then S <= '0';
elsif (PRE = '0') then S <= '1';
elsif (H'event and H='0') then
if (J='0' and K='0') then S <= S;
elsif (J='0' and K='1') then S <= '0';
elsif (J='1' and K='0') then S <= '1';
elsif (J='1' and K='1') then S <= not(S);
end if;
end if;
end process;
Q <= S;
Qb <= not(S);
end arch;
Exercice 10 :
library ieee;
use ieee.std_logic_1164.all;
entity CNT4bits_asyn is port (
CLK : in std_logic;
Q : out std_logic_vector(3 downto 0)
);
end CNT4bits_asyn;
architecture arch of CNT4bits_asyn is
component JKH is port (
J,K,H,CLR,PRE : in std_logic;
Q,Qb : out std_logic
);
end component;
signal S1,S2,S3,S4,a : std_logic;
begin
JKH1 : JKH port map('1','1',CLK,'1','1',S1);
JKH2 : JKH port map('1','1',S1 ,'1','1',S2);
JKH3 : JKH port map('1','1',S2 ,'1','1',S3);
JKH4 : JKH port map('1','1',S3 ,'1','1',S4);
-5-
Université Sultan Moulay Slimane
Faculté des sciences et Techniques Béni Mellal
Département de Génie Electrique
Exercice 11 :
library ieee;
use ieee.std_logic_1164.all;
entity CNT4bits_syn is port(
CLK : in std_logic;
Q : out std_logic_vector(3 downto 0)
);
end CNT4bits_syn;
architecture arch of CNT4bits_syn is
component JKH is port (
J,K,H,CLR,PRE : in std_logic;
Q,Qb : out std_logic
);
end component;
Signal S1,S2,S3,S4 : std_logic;
Signal J1,J2,J3,J4 : std_logic;
Signal K1,K2,K3,K4 : std_logic;
begin
JKH1 : JKH port map (J1,K1,CLK,'1','1',S1);
JKH2 : JKH port map (J2,K2,CLK,'1','1',S2);
JKH3 : JKH port map (J3,K3,CLK,'1','1',S3);
JKH4 : JKH port map (J4,K4,CLK,'1','1',S4);
J1 <= '1';
K1 <= '1';
J2 <= S1;
K2 <= S1;
J3 <= S1 and S2;
K3 <= J3;
J4 <= J3 and S3;
K4 <= J4;
Q(0) <= S1;
Q(1) <= S2;
Q(2) <= S3;
Q(3) <= S4;
end arch;
-6-