Lab 5 Firna Frilanisa
Lab 5 Firna Frilanisa
Lab 5 Firna Frilanisa
Desain
----------------------------------------------------------------------
------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SR_latch is
Port ( S : in STD_LOGIC;
R : in STD_LOGIC;
Q : inout STD_LOGIC;
Qbar : inout STD_LOGIC);
end SR_latch;
ENTITY tb IS
END tb;
ARCHITECTURE behavior OF tb IS
COMPONENT SR_latch
PORT(
S : IN std_logic;
R : IN std_logic;
Q : INOUT std_logic;
Qbar : INOUT std_logic
);
END COMPONENT;
--Inputs
signal S : std_logic := '0';
signal R : std_logic := '0';
--BiDirs
signal Q : std_logic;
signal Qbar : std_logic;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: SR_latch PORT MAP (
S => S,
R => R,
Q => Q,
Qbar => Qbar
);
stim_proc: process
begin
S<='0';
R<='0';
wait for 10 ns;
S<='0';
R<='1';
wait for 10 ns;
S<='1';
R<='0';
wait for 10 ns;
S<='1';
R<='1';
wait for 10 ns;
wait;
end process;
END;
Hasil :
----------------------------------------------------------------------
------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity gated_SR_latch is
Port ( S : in STD_LOGIC;
R : in STD_LOGIC;
Q : inout STD_LOGIC;
E : in STD_LOGIC;
Qbar : inout STD_LOGIC);
end gated_SR_latch;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb2 IS
END tb2;
COMPONENT gated_SR_latch
PORT(
S : IN std_logic;
R : IN std_logic;
Q : INOUT std_logic;
E : IN std_logic;
Qbar : INOUT std_logic
);
END COMPONENT;
--Inputs
signal S : std_logic := '0';
signal R : std_logic := '0';
signal E : std_logic := '0';
--BiDirs
signal Q : std_logic;
signal Qbar : std_logic;
BEGIN
stim_proc: process
begin
E <= '1'; S <= '1'; R <= '0';
END;
Hasil :
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity D_Latch is
Port ( D : in STD_LOGIC;
E : in STD_LOGIC;
Q : inout STD_LOGIC;
Qbar : inout STD_LOGIC);
end D_Latch;
architecture Dataflow of D_Latch is
signal D1,D2 : std_logic;
begin
D1 <= E and D;
D2 <= E and (not D);
Q <= Qbar nor D2;
Qbar <= Q nor D1;
end Dataflow;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY Dlatchtb IS
END Dlatchtb;
--Inputs
signal D : std_logic := '0';
signal E : std_logic := '0';
--BiDirs
signal Q : std_logic;
signal Qbar : std_logic;
BEGIN
uut: D_Latch PORT MAP (
D => D,
E => E,
Q => Q,
Qbar => Qbar
);
-- Stimulus process
stim_proc: process
begin
E<='1';
D<='0';
wait for 10 ns;
E<='0';
D<='0';
wait for 10 ns;
E<='0';
D<='1';
wait for 10 ns;
E<='1';
D<='1';
wait for 10 ns;
E<='0';
D<='1';
wait for 10 ns;
wait;
end process;
END;
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity D_ff is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
Q : inout STD_LOGIC;
Qbar : inout STD_LOGIC);
end D_ff;
begin
process (clk)
begin
if rising_edge(clk) then
Q <= D;
Qbar <= not D;
end if;
end process;
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY D_fftb IS
END D_fftb;
--Inputs
signal D : std_logic := '0';
signal clk : std_logic := '0';
--BiDirs
signal Q : std_logic;
signal Qbar : std_logic;
BEGIN
uut: D_ff PORT MAP (
D => D,
clk => clk,
Q => Q,
Qbar => Qbar
);
-- Stimulus process
stim_proc: process
begin
clk<='0'; D<='0';
wait for 10 ns;
clk<='1'; D<='0';
wait for 10 ns;
clk<='0'; D<='0';
wait for 10 ns;
clk<='1'; D<='1';
wait for 10 ns;
clk<='0'; D<='1';
wait for 10 ns;
clk<='1'; D<='1';
wait for 10 ns;
clk<='0'; D<='0';
wait for 10 ns;
clk<='1'; D<='0';
wait for 10 ns;
clk<='0'; D<='0';
wait for 10 ns;
clk<='1'; D<='1';
wait for 10 ns;
clk<='0'; D<='1';
wait for 10 ns;
clk<='1'; D<='1';
wait for 10 ns;
clk<='0'; D<='0';
wait for 10 ns;
clk<='1'; D<='0';
wait for 10 ns;
clk<='0'; D<='0';
wait for 10 ns;
clk<='1'; D<='0';
wait for 10 ns;
clk<='0'; D<='0';
wait for 10 ns;
wait;
end process;
END;
2.2 Desain rangkaian dengan timing diagram seperti dibawah dengan menggunakan model behavioral!
Perbandingan output D latch (Qa), D flip-flop positive triggered (Qb), D flip-flop negative triggered (Qc).
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity D_package is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
Qa : out STD_LOGIC;
Qb : out STD_LOGIC;
Qc : out STD_LOGIC);
end D_package;
architecture Behavioral of D_package is
begin
process (D, clk)
begin
if (clk='1') then
Qa <= D;
end if;
end process;
process (clk)
begin
if rising_edge(clk) then
Qb <= D;
end if;
end process;
process (clk)
begin
if falling_edge(clk) then
Qc <= D;
end if;
end process;
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY D_tb IS
END D_tb;
--Inputs
signal D : std_logic := '0';
signal clk : std_logic := '0';
--Outputs
signal Qa : std_logic;
signal Qb : std_logic;
signal Qc : std_logic;
BEGIN
uut: D_package PORT MAP (
D => D,
clk => clk,
Qa => Qa,
Qb => Qb,
Qc => Qc
);
-- Stimulus process
stim_proc: process
begin
wait for 10 ns; D <= '1'; clk <= '0';
wait for 10 ns; D <= '1'; clk <= '1';
wait for 10 ns; D <= '0'; clk <= '1';
wait for 10 ns; D <= '1'; clk <= '1';
wait for 10 ns; D <= '0'; clk <= '1';
wait for 10 ns; D <= '0'; clk <= '0';
wait for 10 ns; D <= '1'; clk <= '0';
wait for 10 ns; D <= '1'; clk <= '0';
wait for 10 ns; D <= '0'; clk <= '0';
wait for 10 ns; D <= '1'; clk <= '0';
wait for 10 ns; D <= '0'; clk <= '0';
wait for 10 ns; D <= '0'; clk <= '1';
wait for 10 ns; D <= '1'; clk <= '1';
wait for 10 ns; D <= '0'; clk <= '1';
wait for 10 ns; D <= '1'; clk <= '1';
wait for 10 ns; D <= '1'; clk <= '1';
wait for 10 ns; D <= '1'; clk <= '0';
wait for 10 ns; D <= '0'; clk <= '0';
wait;
end process;
END;
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Dff_syncreset is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
reset : in STD_LOGIC;
Q : out STD_LOGIC);
end Dff_syncreset;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY Dff_syncreset_tb IS
END Dff_syncreset_tb;
--Inputs
signal D : std_logic := '0';
signal clk : std_logic := '0';
signal reset : std_logic := '0';
--Outputs
signal Q : std_logic;
BEGIN
uut: Dff_syncreset PORT MAP (
D => D,
clk => clk,
reset => reset,
Q => Q
);
-- Stimulus process
stim_proc: process
begin
wait for 10 ns; clk <= '1'; D <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; reset <= '1';
wait for 5 ns; clk <= '0'; D <= '1'; reset <= '0';
wait for 5 ns; clk <= '1'; D <= '1'; reset <= '1';
wait for 10 ns; clk <= '0'; D <= '1'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; reset <= '0';
wait for 2 ns; clk <= '1'; D <= '0'; reset <= '1';
wait for 5 ns; clk <= '1'; D <= '0'; reset <= '0';
wait for 3 ns; clk <= '0'; D <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '0'; reset <= '0';
wait for 10 ns;
wait;
end process;
END;
2.4 Desain D flip-flop dengan synchronous reset dan clock enable menggunakan model behavioral!
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Dff_syncreset_clken is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
clk_en : in STD_LOGIC;
reset : in STD_LOGIC;
Q : out STD_LOGIC);
end Dff_syncreset_clken;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY Dff_syncreset_clken_tb IS
END Dff_syncreset_clken_tb;
--Inputs
signal D : std_logic := '0';
signal clk : std_logic := '0';
signal clk_en : std_logic := '0';
signal reset : std_logic := '0';
--Outputs
signal Q : std_logic;
BEGIN
uut: Dff_syncreset_clken PORT MAP (
D => D,
clk => clk,
clk_en => clk_en,
reset => reset,
Q => Q
);
-- Stimulus process
stim_proc: process
begin
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '1'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '1'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '0'; clk_en <= '0'; reset <= '1';
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '0'; reset <= '1';
wait for 10 ns; clk <= '0'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '0'; clk_en <= '1'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '1'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '0'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '1'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '1'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '0'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns; clk <= '1'; D <= '1'; clk_en <= '0'; reset <= '0';
wait for 10 ns;
wait;
end process;
END;
2.5 Desain sebuah T flip-flop dengan synchronous negative-logic reset dan clock enable!
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity T_ff is
Port ( T : in STD_LOGIC;
en : in STD_LOGIC;
clk : in STD_LOGIC;
Q : inout STD_LOGIC);
end T_ff;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY Tff_tb IS
END Tff_tb;
--Inputs
signal T : std_logic := '0';
signal en : std_logic := '0';
signal clk : std_logic := '0';
--BiDirs
signal Q : std_logic;
BEGIN
uut: T_ff PORT MAP (
T => T,
en => en,
clk => clk,
Q => Q
);
-- Stimulus process
stim_proc: process
begin
wait for 10 ns; clk <= '1'; en <= '0'; T <= '0';
wait for 10 ns; clk <= '0'; en <= '1'; T <= '0';
wait for 10 ns; clk <= '1'; en <= '1'; T <= '0';
wait for 10 ns; clk <= '0'; en <= '0'; T <= '1';
wait for 10 ns; clk <= '1'; en <= '0'; T <= '1';
wait for 10 ns; clk <= '0'; en <= '1'; T <= '1';
wait for 10 ns; clk <= '1'; en <= '1'; T <= '0';
wait for 10 ns; clk <= '0'; en <= '0'; T <= '0';
wait for 10 ns; clk <= '1'; en <= '0'; T <= '1';
wait for 10 ns; clk <= '0'; en <= '1'; T <= '1';
wait for 10 ns; clk <= '1'; en <= '0'; T <= '0';
wait for 10 ns; clk <= '0'; en <= '1'; T <= '0';
wait for 10 ns;
wait;
end process;
END;