--
-- D-Flip FLop
--
library IEEE;
use IEEE.STD_LOGIC_1164.all;
ENTITY dff IS
PORT (
clock : IN std_logic;
reset : IN std_logic;
d : IN std_logic;
q : BUFFER std_logic
);
END ENTITY dff;
ARCHITECTURE rtl OF dff IS
BEGIN
PROCESS ( clock, reset )
BEGIN
IF ( reset = '0' ) THEN
q <= '0';
ELSIF ( clock = '1' AND clock'EVENT) THEN
q <= d;
END IF;
END PROCESS;
END rtl;
--
-- T-Flip Flop
--
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use work.dff;
ENTITY tff IS
PORT (
clock : IN std_logic;
clear : IN std_logic;
t : INOUT std_logic;
q : BUFFER std_logic
);
END ENTITY tff;
ARCHITECTURE rtl_tff OF tff IS
COMPONENT dff
PORT (
clock : IN std_logic;
reset : IN std_logic;
d : IN std_logic;
q : BUFFER std_logic
);
END COMPONENT;
BEGIN
dff_inst : dff PORT MAP
(
clock => clock,
reset => clear,
d => NOT q,
q => q
);
END rtl_tff;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use work.tff;
ENTITY ckt IS
PORT (
enable : IN std_logic;
clock : IN std_logic;
clear : IN std_logic;
q_out : BUFFER std_logic
);
END ENTITY ckt;
ARCHITECTURE rtl_ckt OF ckt IS
COMPONENT tff
PORT (
clock : IN std_logic;
clear : IN std_logic;
t : INOUT std_logic;
q : BUFFER std_logic
);
END COMPONENT;
SIGNAL t_2,t_3,t_4,q,q2,q3 : std_logic;
BEGIN
tff_1 : tff PORT MAP (
clock => clock,
clear => clear,
t => enable,
q => q
);
t_2 <= enable AND q;
tff_2 : tff PORT MAP (
clock => clock,
clear => clear,
t => t_2,
q => q2
);
t_3 <= t_2 AND q2;
tff_3 : tff PORT MAP (
clock => clock,
clear => clear,
t => t_3,
q => q3
);
t_4 <= t_3 AND q3;
tff_4 : tff PORT MAP (
clock => clock,
clear => clear,
t => t_4,
q => q_out
);
END rtl_ckt;