Académique Documents
Professionnel Documents
Culture Documents
-- Entitate
-- Arhitectura
-- Entitate
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end SI;
architecture comportamental of SI is
begin
Y <= A and B;
end architecture;
-- Arhitectura
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-- Poarta SI
-- Poarta SAU
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component;
component INV is
port ( X: in STD_LOGIC;
nX: out STD_LOGIC);
end component;
-- Semnale:
SIGNAL Aneg,
Bneg,
-- Invertor
-- A negat
-- B negat
o1,
o2 :STD_LOGIC;
begin
inv1: INV port map (A, Aneg);
inv2: INV port map (B, Bneg);
si1: SI port map (A, Bneg, o1);
si2: SI port map (Aneg, B, o2);
sau1: SAU port map (o1, o2, Y);
end architecture;
--------------------- Fuctia logica de coincidenta (NXOR) -----------------------Descriere structurala
--Ecuatie: f = (A = B) = not (A xor B) = not ( (A and not(B)) or (not(A) and B) )
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity egal is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end egal;
architecture structural of egal is
-- Componente:
component SI is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component;
-- Entitate
-- Arhitectura
-- Poarta SI
component SAU is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component;
-- Poarta SAU
component INV is
port ( X: in STD_LOGIC;
nX: out STD_LOGIC);
end component;
-- Invertor
-- Semnale:
SIGNAL Aneg,
Bneg,
-- A negat
-- B negat
o1,
o2,
o3
:STD_LOGIC;
begin
inv1: INV port map (A, Aneg);
inv2: INV port map (B, Bneg);
si1: SI port map (A, Bneg, o1);
si2: SI port map (Aneg, B, o2);
------6
---- 9
0
1
2
3
4
5
--
7
8
-----6
---- 9
1
2
3
4
5
------6
---- 9
0
1
2
3
4
5
7
8
end case;
end process;
end architecture;
7
8
process (X)
begin
if X(0) = '1' then BCD <= "0000";
elsif X(1) = '1' then BCD <= "0001";
elsif X(2) = '1' then BCD <= "0010";
elsif X(3) = '1' then BCD <= "0011";
elsif X(4) = '1' then BCD <= "0100";
elsif X(5) = '1' then BCD <= "0101";
elsif X(6) = '1' then BCD <= "0110";
elsif X(7) = '1' then BCD <= "0111";
elsif X(8) = '1' then BCD <= "1000";
elsif X(9) = '1' then BCD <= "1001";
-- 0
-- 1
-- 2
-- 3
-- 4
-- 5
-- 6
-- 7
-- 8
-- 9
else BCD <= "1111"; -- nici o intrare activata
end if;
end process;
end architecture;
-------
0
1
2
3
4
5
---- 9
7
8
-- 6
-- >= 10
end entity;
-- Arhitectura:
architecture comportamental of binar_to_zecimal is
begin
process (binar)
begin
case binar is
when "0000" => Y <= "0000000000000001";
when "0001" => Y <= "0000000000000010";
when "0010" => Y <= "0000000000000100";
when "0011" => Y <= "0000000000001000";
when "0100" => Y <= "0000000000010000";
when "0101" => Y <= "0000000000100000";
when "0110" => Y <= "0000000001000000";
when "0111" => Y <= "0000000010000000";
when "1000" => Y <= "0000000100000000";
when "1001" => Y <= "0000001000000000";
when "1010" => Y <= "0000010000000000";
when "1011" => Y <= "0000100000000000";
when "1100" => Y <= "0001000000000000";
when "1101" => Y <= "0010000000000000";
when "1110" => Y <= "0100000000000000";
when "1111" => Y <= "1000000000000000";
end case;
end process;
end architecture;
-- Entitate
generic (
-- pentru MUX 8:1, nr_sel = 3
);
-- Semanle de intrare si de iesire:
-- S : intrari de selctie
-- X : intrari de date
-- Q : iesirea multiplexorului
port (
S: in STD_LOGIC_VECTOR (nr_sel - 1 downto 0);
X: in STD_LOGIC_VECTOR (2**nr_sel - 1 downto 0);
O: out STD_LOGIC
);
end entity;
architecture comportamental of MUX is
begin
O <= X( conv_integer(S) );
end architecture;
-- Arhitectura
---- 9
7
8
------
11
12
13
14
15
-- 10
Library
IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
nr_sel: INTEGER := 3
0
1
2
3
4
5
-- 6
entity MUX is
-- Parametrii genericii:
-- nr_sel : numarul intrarilor de selectie
-------
Library
IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity DEMUX is
-- Parametrii genericii:
-- nr_sel : numarul intrarilor de selectie
-- Entitate
generic (
nr_sel: INTEGER := 3
);
-- Semanle de intrare si de iesire:
-- S : intrari de selctie
-- X : intrarea de date
-- O : iesiriile demultiplexorului
port (
S: in STD_LOGIC_VECTOR (nr_sel - 1 downto 0);
O: out STD_LOGIC_VECTOR (2**nr_sel - 1 downto 0);
X: in STD_LOGIC
);
end entity;
architecture comportamental of DEMUX is
begin
-- Arhitectura
process (S,X)
variable tempO: STD_LOGIC_VECTOR (2**nr_sel - 1 downto 0);
begin
tempO := (tempO'range => '0'); -- umplam vectorul cu '0' uri
tempO(conv_integer (S)) := X; -- pe pozitia corespunzatoare punem pe X
O <= tempO;
end process;
end architecture;
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-----------------------------------------------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity comp2 is
--Semnale de iesire si de intrare:
-- A, B: cele doua intrari a comparatorul
-- mic: A<B
-- mare: A>B
-- egal: A=B
port (
A, B: in STD_LOGIC_VECTOR (1 downto 0);
mic, mare, egal: out STD_LOGIC
);
end entity;
-- Arhitectura:
-- Nr. 1. Descriere Structurala
architecture structural of comp2 is
-- Componente:
-- 1. Invertor:
component INV is
port ( X: in STD_LOGIC;
nX: out STD_LOGIC);
end component INV;
-- 2. Poarta AND:
component AND3 is
port ( A, B, C: in STD_LOGIC;
Y: out STD_LOGIC);
end component AND3;
-- 3. Poarta OR:
component OR3 is
port ( A, B, C: in STD_LOGIC;
Y: out STD_LOGIC);
end component OR3;
-- 4. Poarta XOR:
component XOR2 is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component XOR2;
-- Semnale:
signal nA0, nA1, nB0, nB1,
p1, p2, p3,
q1, q2, q3,
t1, t2, t3 : STD_LOGIC;
begin
inv_1: INV port map ( A(0), nA0);
inv_2: INV port map ( A(1), nA1);
inv_3: INV port map ( B(0), nB0);
inv_4: INV port map ( B(1), nB1);
-- mic:
and_1: AND3 port map ( B(1), nA1, '1', p1);
and_2: AND3 port map ( B(0), nA0, nA1, p2);
and_3: AND3 port map ( nA0, B(1), B(0), p3);
or1: OR3 port map (p1, p2, p3, mic);
-- mare:
and_4: AND3 port map ( A(1), nB1, '1', q1);
and_5: AND3 port map ( A(0), nB0, nB1, q2);
and_6: AND3 port map ( nB0, A(1), A(0), q3);
or2: OR3 port map (q1, q2, q3, mare);
-- egal:
xor_1: XOR2 port map ( A(1), B(1), t1);
xor_2: XOR2 port map ( A(0), B(0), t2);
or_3: OR3 port map ( t1, t2, '0', t3);
inv_5: INV port map (t3, egal);
end architecture;
-- Nr. 2. Descriere Comportamentala
architecture comportamental of comp2 is
begin
process (A,B)
begin
if (A<B) then
mic <= '1';
else
mic <= '0';
end if;
if (A=B) then
egal <= '1';
else
egal <= '0';
end if;
if (A>B) then
-- Entitate
-- Entitate
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-- Entitate
-- Arhitectura
-----------------------------------------------------------------------library
IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity scazator is
-- Semnale de intrare si de iesire:
port (
A, B, Cin: in STD_LOGIC;
S, Cout: out STD_LOGIC
);
end entity;
-- Arhitectura:
architecture structural of scazator is
-- Componente:
-- 1. Invertor:
component INV_1 is
port ( X: in STD_LOGIC;
nX: out STD_LOGIC);
end component INV_1;
-- 2. Poarta SI:
component SI_2 is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component SI_2;
-- 3. Poarta SAU:
component SAU_3 is
port ( A, B, C: in STD_LOGIC;
Y: out STD_LOGIC);
end component SAU_3;
-- 4. Poarta SAU-EXCLUSIV:
component XOR_2 is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component XOR_2;
-- Semnale:
signal nA, nCin,
x1, x2, x3,
y1, y2, y3: STD_LOGIC;
begin
inv_nr1: INV_1 port map ( Cin, nCin);
inv_nr2: INV_1 port map ( A, nA);
-- S:
xor_nr1: XOR_2 port map ( A, B, x1);
inv_nr3: INV_1 port map (x1, x2);
xor_nr2: XOR_2 port map (x2, Cin, x3);
-- Entitate
-- Entitate
-- Entitate
IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
-- Entitatea:
entity ROM16_4 is
-- Semnale de intrare si de iesire:
port (
ADR: in STD_LOGIC_VECTOR (3 downto 0);
CLK, CS: in STD_LOGIC;
Dout: out STD_LOGIC_VECTOR (3 downto 0)
);
end entity;
-- Architectura:
architecture comportamental of ROM16_4 is
type mem is array (15 downto 0) of STD_LOGIC_VECTOR (3 downto 0);
signal M:mem := (
--Continutul memoriei
"0000", -- 15
"0001",
-- 14
"0010",
"0011",
"0100",
"0101",
"0110",
"0111",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
"1110",
"1111" ); -- 0
begin
process (CLK, CS, ADR)
begin
if CLK = '1' and CLK'EVENT and CS = '1' then
Dout <= M( conv_integer(ADR) );
end if;
end process;
end architecture;
signal M:mem := (
--Continutul memoriei
"0000", -- 15
"0001",
-- 14
"0010",
"0011",
"0100",
"0101",
"0110",
"0111",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
"1110",
"1111" ); -- 0
begin
process (CLK, CS, ADR, WE)
begin
if CLK = '1' and CLK'EVENT and CS = '1' then
if (WE = '1') then
M (conv_integer(ADR)) <= Din;
end if;
Dout <= M( conv_integer(ADR) );
end if;
end process;
end architecture;
-- Inmultire (*)
H := A * B;
O <= H(7 downto 0);
elsif (S = "011") then
-- Inpartire (/)
null;
elsif (S = "100") then
-- AND
O <= A and B;
elsif (S = "101") then
-- NOT
O <= not (A);
elsif (S = "110") then
-- OR
O <= A or B;
elsif (S = "100") then
-- XOR
O <= A xor B;
end if;
end process;
end architecture;
-- 18. Bistabil D sincron, cu intrri asincrone si cu proces pt. tact descriere comportamental
library
IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity bist_D is
port (
D, R, S: in STD_LOGIC;
Q: out STD_LOGIC
);
end entity;
-- Arhitectura:
architecture comportamental of bist_D is
signal clk: STD_LOGIC := '1';
begin
tact: process
begin
clk <= not clk;
wait for 10 ns;
end process;
bist: process (D, R, S, clk)
begin
if (R = '1') then
Q <= '0';
elsif (S = '1') then
Q <= '1';
elsif clk'event and clk = '1' then
Q <= D;
end if;
end process;
end architecture;
-- 19. Bistabil JK sincron, cu intrri asincrone si cu proces pt. tact descriere comportamental
library
IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity bist_JK is
port (
J, K, R, S: in STD_LOGIC;
Q: out STD_LOGIC
);
end entity;
-- Arhitectura:
architecture comportamental of bist_JK is
signal clk: STD_LOGIC := '1';
signal M: STD_LOGIC;
begin
tact: process
begin
clk <= not clk;
wait for 10 ns;
end process;
bist: process (M, J, K, R, S, clk)
begin
if (R = '1') then
M <= '0';
elsif (S = '1') then
M <= '1';
elsif clk'event and clk = '1' then
if (J = '0') then
if (K = '0') then
null;
else
M <= '0';
end if;
else
if (K = '0') then
M <= '1';
else
M <= not(M);
end if;
end if;
end if;
Q <= M;
end process;
end architecture;
-- 19. Bistabil T sincron, cu intrri asincrone si cu proces pt. tact descriere comportamental
library
IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity bist_T is
port (
T, R, S: in STD_LOGIC;
Q: out STD_LOGIC
);
end entity;
-- Arhitectura:
architecture comportamental of bist_T is
signal clk: STD_LOGIC := '1';
signal M: STD_LOGIC;
begin
tact: process
begin
clk <= not clk;
wait for 10 ns;
end process;
bist: process (M, T, R, S, clk)
begin
if (R = '1') then
M <= '0';
elsif (S = '1') then
M <= '1';
elsif clk'event and clk = '1' then
if (T = '1') then
M <= not (M);
end if;
end if;
Q <= M;
end process;
end architecture;
-- Resetare
-- Incarcare paralela
-- Deplasare dreapta
-- Deplasare stanga
-- Entitate:
entity registru is
port (
CLK, L, ST, DR, R, SI: in STD_LOGIC;
Din: in STD_LOGIC_VECTOR (7 downto 0);
Dout: out STD_LOGIC_VECTOR (7 downto 0)
);
end entity;
-- Arhitectura:
architecture comportamental of registru is
signal M: STD_LOGIC_VECTOR (7 downto 0);
begin
process (CLK, L, ST, DR, R, SI, Din)
begin
if (CLK = '1') and (CLK'EVENT) then
if (R = '1') then
M <= "00000000";
elsif (L = '1') then
M <= Din;
elsif (DR = '1') then
M(6 downto 0) <= M(7 downto 1);
M(7) <= SI;
elsif (ST = '1') then
M(7 downto 1) <= M(6 downto 0);
M(0) <= SI;
end if;
end if;
end process;
Dout <= M;
end architecture;
-- Resetare
-- Incarcare paralela
-- Deplasare dreapta
-- Deplasare stanga
-- Entitate
end component;
-- 2. Poarta XOR
component XOR2 is
port ( A, B: in STD_LOGIC;
Y: out STD_LOGIC);
end component;
-- Entitate
-- Signal:
signal X: STD_LOGIC;
signal Y: STD_LOGIC_VECTOR (7 downto 0);
begin
reg: registru port map (CLK => CLK, L=> R, ST => '0', DR => '1', R=> '0', SI => X, Din => "00010000", Dout => Y);
xor1: XOR2 port map (Y(7), Y(4), X);
Dout <= Y (7 downto 4);
end architecture;
end if;
Empty <= tEmpty;
Full <= tFull;
end if;
end process;
end architecture;
use IEEE.STD_LOGIC_UNSIGNED.all;
-- Entitate:
entity Scazator1 is
port (
A, B, Cin: in STD_LOGIC;
S, Cout: out STD_LOGIC
);
end entity;
-- Arhitectura:
architecture comportamental of Scazator1 is
begin
process (A, B, Cin)
variable X, Y, Z, T: STD_LOGIC_VECTOR(1 downto 0);
begin
X(0) := A; X(1) := '1';
Y(0) := B; Y(1) := '0';
Z(0) := Cin; Z(1) := '0';
T := X - Y - Z;
S <= T(0);
Cout <= not T(1);
end process;
end architecture;
-- Modul de simulare
library
IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
-- Entitate:
entity Modul_scazator is
end entity;
-- Arhitectura:
architecture comportamental of Modul_scazator is
component Scazator1 is
port (
A, B, Cin: in STD_LOGIC;
S, Cout: out STD_LOGIC
);
end component;
signal A, B, Cin, S, Cout: STD_LOGIC;
begin
UST: Scazator1 port map (A, B, Cin, S, Cout);
A <= '0', '1' after 80 ns;
B <= '0', '1' after 40 ns, '0' after 80 ns, '1' after 120 ns;
Cin <= '0', '1' after 20 ns, '0' after 40 ns, '1' after 60 ns, '0' after 80 ns, '1' after 100 ns, '0' after 120 ns, '1' after 140 ns;
end architecture;
A, B: in STD_LOGIC;
mic, mare, egal: out STD_LOGIC
);
end entity;
-- Arhitectura
architecture flux of comp1 is
begin
mic <= (not A) and B;
mare <= A and (not B);
egal <= not (A xor B);
end;
-- Modul de simulare:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity modul_comp1 is
end entity;
-- Arhitectura:
architecture comportamental of modul_comp1 is
component comp1 is
port (
A, B: in STD_LOGIC;
mic, mare, egal: out STD_LOGIC
);
end component;
signal A, B, mic, mare, egal: STD_LOGIC;
begin
UST: comp1 port map ( A, B, mic, mare, egal);
A <= '0', '1' after 80 ns;
B <= '0', '1' after 40 ns, '0' after 80 ns, '1' after 120 ns;
end architecture;
-- Arhitectura
end entity;
-- Arhitectura:
architecture comportamental of modul_mux4 is
component MUX4_1 is
port (
S: in STD_LOGIC_VECTOR (1 downto 0);
X: in STD_LOGIC_VECTOR (3 downto 0);
O: out STD_LOGIC
);
end component;
signal S: STD_LOGIC_VECTOR (1 downto 0);
signal X: STD_LOGIC_VECTOR (3 downto 0);
signal O: STD_LOGIC;
begin
UST: MUX4_1 port map (S, X, O);
X <= "0001", "0010" after 20 ns, "0100" after 40 ns, "1000" after 60 ns,
"1110" after 80 ns, "1101" after 100 ns, "1011" after 120 ns, "0111" after 140 ns;
S <= "00", "01" after 20 ns, "10" after 40 ns, "11" after 60 ns,
"00" after 80 ns, "01" after 100 ns, "10" after 120 ns, "11" after 140 ns;
end architecture;
-- Arhitectura:
architecture comportamental of modul_dmux4 is
component DMUX4_1 is
port (
S: in STD_LOGIC_VECTOR (1 downto 0);
O: out STD_LOGIC_VECTOR (3 downto 0);
X: in STD_LOGIC
);
end component;
signal S: STD_LOGIC_VECTOR (1 downto 0);
signal O: STD_LOGIC_VECTOR (3 downto 0);
signal X: STD_LOGIC;
begin
UST: DMUX4_1 port map (S, O, X);
X <= '0', '1' after 80 ns;
S <= "00", "01" after 20 ns, "10" after 40 ns, "11" after 60 ns,
"00" after 80 ns, "01" after 100 ns, "10" after 120 ns, "11" after 140 ns;
end architecture;
34.library IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate:
entity bistJK is
port (
J, K, R, S: in STD_LOGIC;
Q: out STD_LOGIC
);
end entity;
-- Arhitectura:
architecture comportamental of bistJK is
signal clk: STD_LOGIC := '1';
signal M: STD_LOGIC;
begin
tact: process
begin
clk <= not clk;
wait for 10 ns;
end process;
bist: process (M, J, K, R, S, clk)
begin
if (R = '1') then
M <= '0';
elsif (S = '1') then
M <= '1';
elsif clk'event and clk = '1' then
if (J = '0') then
if (K = '0') then
null;
else
M <= '0';
end if;
else
if (K = '0') then
M <= '1';
else
M <= not(M);
end if;
end if;
end if;
Q <= M;
end process;
end architecture;
-- Modul de simulare
library
IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Entitate
entity modul_bistJK is
end entity;
-- Arhitectura
architecture comportamental of modul_bistJK is
component bistJK is
port (
J, K, R, S: in STD_LOGIC;
Q: out STD_LOGIC
);
end component;
signal J, K, R, S, Q: STD_LOGIC;
begin
UST: bistJK port map(J, K, R, S, Q);
S <= '1', '0' after 20 ns;
R <= '0', '1' after 20 ns, '0' after 40 ns;
J <= '0', '1' after 80 ns;
K <= '0', '1' after 60 ns, '0' after 80 ns, '1' after 100 ns;
end architecture;
component bistT is
port (
T, R, S: in STD_LOGIC;
Q: out STD_LOGIC
);
end component;
signal T, R, S, Q: STD_LOGIC;
begin
UST: bistT port map (T, R, S, Q);
R <= '1', '0' after 20 ns;
S <= '0', '1' after 100 ns, '0' after 120 ns;
T <= '0', '1' after 40 ns, '0' after 100 ns, '1' after 140 ns;
end architecture;
-- Resetare
-- Incarcare paralela
-- Deplasare dreapta
-- Deplasare stanga
port (
CLK, L, ST, DR, R, SI: in STD_LOGIC;
Din: in STD_LOGIC_VECTOR (7 downto 0);
Dout: out STD_LOGIC_VECTOR (7
downto 0)
);
end component;
signal CLK, L, ST, DR, R, SI: STD_LOGIC :='0';
signal Din: STD_LOGIC_VECTOR (7 downto 0);
signal Dout: STD_LOGIC_VECTOR (7 downto 0);
begin
UST: reg port map (CLK, L, ST, DR, R, SI, Din, Dout);
clock: process
begin
CLK <= not (CLK);
wait for 5 ns;
end process;
Din <= "01101101", "00001111" after 10 ns;
L <= '1', '0' after 20 ns;
SI <= '0', '1' after 10 ns, '0' after 20 ns, '1' after 30 ns, '0' after 40 ns, '1' after 50 ns, '0' after 60 ns,
'1' after 70 ns, '0' after 80 ns, '1' after 90 ns, '0' after 100 ns, '1' after 110 ns, '0' after 120 ns;
R <= '0', '1' after 20 ns, '0' after 30 ns;
ST <= '0', '1' after 30 ns, '0' after 80 ns;
DR <= '0', '1' after 80 ns;
end architecture;