Advertisement
cofyye

SR FLIP-FLOP SYNC

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