Advertisement
B-Matt

VHDL - T Flip Flop

Mar 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.50 KB | None | 0 0
  1. --- Author: Matej Arlović, 2018.
  2. library IEEE;
  3. use IEEE.STD_LOGIC_1164.ALL;
  4.  
  5. entity flipflop_t is
  6.     port(
  7.         T, cp: in STD_LOGIC;
  8.         Q, Qn: out STD_LOGIC
  9.     );
  10. end flipflop_t;
  11.  
  12. architecture Behavioral of flipflop_t is
  13.     signal temp: STD_LOGIC;
  14. begin
  15.     process (T,cp)
  16.     begin
  17.         if(T = '1') then
  18.             temp <= '0';
  19.         elsif(cp'EVENT and cp = '1') then
  20.             temp <= not(temp);
  21.         end if;
  22.     end process;
  23.     Q <= temp;
  24.     Qn <= not(temp);
  25. end Behavioral;
  26.  
  27. --- Testbench:
  28. LIBRARY ieee;
  29. USE ieee.std_logic_1164.ALL;
  30.  
  31. ENTITY flipflop_t_w IS
  32. END flipflop_t_w;
  33.  
  34. ARCHITECTURE behavior OF flipflop_t_w IS
  35.  
  36.     -- Component Declaration for the Unit Under Test (UUT)
  37.  
  38.     COMPONENT flipflop_t
  39.     PORT(
  40.          T : IN  std_logic;
  41.          cp : IN  std_logic;
  42.          Q : OUT  std_logic;
  43.             Qn: OUT std_logic
  44.         );
  45.     END COMPONENT;
  46.    
  47.  
  48.    --Inputs
  49.    signal T : std_logic := '0';
  50.    signal cp : std_logic := '0';
  51.  
  52.     --Outputs
  53.    signal Q : std_logic;
  54.     signal Qn: std_logic;
  55.    constant cp_period : time := 200 ns;
  56.  
  57. BEGIN
  58.  
  59.     -- Instantiate the Unit Under Test (UUT)
  60.    uut: flipflop_t PORT MAP (
  61.           T => T,
  62.           cp => cp,
  63.           Q => Q,
  64.              Qn => Qn
  65.         );
  66.  
  67.    -- Clock process definitions
  68.    cp_process :process
  69.    begin
  70.         cp <= '0';
  71.         wait for cp_period/2;
  72.         cp <= '1';
  73.         wait for cp_period/2;
  74.    end process;
  75.  
  76.  
  77.    -- Stimulus process
  78.    stim_proc: process
  79.    begin
  80.         T <= '1';
  81.         wait for 100ns;
  82.         T <= '0';
  83.         wait for 100ns;
  84.    end process;
  85. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement