Advertisement
cofyye

D FLIP-FLOP SYNC

Apr 6th, 2023
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.33 KB | Source Code | 0 0
  1. -- design.vhd
  2.  
  3. library IEEE;
  4. use IEEE.std_logic_1164.all;
  5.  
  6. entity d_flipflop_sync is
  7.     port(clock, D : in std_logic;
  8.          Q, Qn : out std_logic);
  9. end entity d_flipflop_sync;
  10.  
  11. architecture d_flipflop_sync_arch of d_flipflop_sync is
  12. begin
  13.     process(clock)
  14.     begin
  15.         if(clock'event and clock = '1') then
  16.             if(D = '0') then
  17.                 Q <= '0';
  18.                 Qn <= '1';
  19.             elsif(D = '1') then
  20.                 Q <= '1';
  21.                 Qn <= '0';
  22.             end if;
  23.         end if;
  24.     end process;
  25. end architecture d_flipflop_sync_arch;
  26.  
  27.  
  28. -- testbench.vhd
  29.  
  30. library IEEE;
  31. use IEEE.std_logic_1164.all;
  32.  
  33. entity d_flipflop_sync_tb is
  34. end entity d_flipflop_sync_tb;
  35.  
  36. architecture d_flipflop_sync_tb_arch of d_flipflop_sync_tb is
  37.     signal clock1, D1, Q1, Qn1 : std_logic;
  38. begin
  39.     DUT1 : entity work.d_flipflop_sync(d_flipflop_sync_arch)
  40.            port map(clock1, D1, Q1, Qn1);
  41.    
  42.     CLOCK : process
  43.     begin
  44.         clock1 <= '0'; wait for 10ns;
  45.         clock1 <= '1'; wait for 10ns;
  46.     end process;
  47.    
  48.     STIMULUS : process
  49.     begin
  50.         D1 <= '0'; wait for 10ns;
  51.         D1 <= '0'; wait for 10ns;
  52.         D1 <= '1'; wait for 10ns;
  53.         D1 <= '1'; wait for 10ns;
  54.         D1 <= 'X'; wait for 10ns;
  55.         D1 <= 'X'; wait for 10ns;
  56.     end process;
  57. end architecture d_flipflop_sync_tb_arch;
Tags: VHDL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement