Advertisement
olelek

JK_LATCH

May 18th, 2019
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.38 KB | None | 0 0
  1. -------------------------------------------
  2. -- AND Gate
  3. library IEEE;
  4. library IEEE;
  5. use IEEE.STD_LOGIC_1164.ALL;
  6.  
  7. entity vhdl_and_gate is
  8.     Port ( INO1 : in  STD_LOGIC;    -- OR gate input
  9.            INO2 : in  STD_LOGIC;    -- OR gate input
  10.            OO : out  STD_LOGIC);    -- OR gate output
  11. end vhdl_and_gate;
  12.  
  13. architecture vhdl_and_gate of vhdl_and_gate is
  14. begin
  15. OO <= not INO1 and not INO2;    -- 2 input OR gate
  16. end vhdl_and_gate;
  17. -------------------------------------------
  18. -- up counter with async reset
  19. -- uses signal
  20.  
  21. library IEEE;
  22. use IEEE.STD_LOGIC_1164.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. entity licznik is
  26. generic (N:integer := 32);
  27.     Port(
  28.     C : in std_logic; -- clock signal input
  29.     RST : in std_logic; --asynchronous reset, on low level
  30.     data : out std_logic_vector(N-1 downto 0)
  31.     );
  32. end licznik;
  33.  
  34.  
  35. architecture l1 of licznik is
  36. signal a: std_logic_vector(N-1 downto 0);
  37. begin
  38.  
  39.     process(RST,C)
  40.         begin
  41.             if (RST = '0') then
  42.                 a<= (others => '0');
  43.             elsif (C'event and C='0') then -- on falling edge
  44.                 a <= a+1; -- increment
  45.             end if;
  46.         end process;
  47.     data <= a;
  48. end l1;
  49. -------------------------------------------
  50. library IEEE;
  51. use IEEE.STD_LOGIC_1164.ALL;
  52.  
  53. entity latch_d is
  54.     Port(
  55.         D,C : in bit;
  56.         Q : out bit
  57.     );
  58. end latch_d;
  59.  
  60. architecture a1 of latch_d is
  61. begin
  62.     process(C)
  63.     begin
  64.         if C'event and C='0' then Q <= not D;
  65.         end if;
  66.     end process;
  67. end a1;
  68.  
  69. -------------------------------------------
  70. library IEEE;
  71. use IEEE.STD_LOGIC_1164.ALL;
  72.  
  73. -- jk latch with synchronous reset
  74. entity jk_sr is
  75.     port(J,K,C,R  :in bit; Q : out bit);
  76. end jk_sr;
  77.  
  78. architecture jk3 of jk_sr is -- przerzutnik jk z synchronicznym resetem
  79. begin
  80.     process(C)
  81.         variable ta: bit;
  82.     begin
  83.         if (C'event and C='1') then -- on clock input
  84.             if R = '1' then ta := '0';
  85.             else
  86.            
  87.                 if J='1' and K='1' then -- toggle
  88.                     ta := not ta;
  89.                 elsif J='0' and K='1' then -- reset
  90.                     ta := '0';
  91.                 elsif J='1' and K='0' then -- set
  92.                     ta := '1';
  93.                 else -- no change
  94.                     ta := ta;
  95.                 end if;
  96.                
  97.             end if;
  98.         end if;
  99.         Q <= ta;
  100.     end process;
  101. end jk3;
  102.  
  103. -------------------------------------------
  104. library IEEE;
  105. use IEEE.STD_LOGIC_1164.ALL;
  106.  
  107. -- jk latch with asynchronous reset
  108. entity jk_ar is
  109.     port(J,K,C,R  :in bit; Q : out bit);
  110. end jk_ar;
  111.  
  112. architecture jk2 of jk_ar is -- przerzutnik jk z asynchronicznym resetem
  113. begin
  114.     process(R,C)
  115.         variable ta: bit;
  116.     begin
  117.         if R = '1' then ta := '0';
  118.         else
  119.             if (C'event and C='1') then -- on clock input
  120.                 if J='1' and K='1' then -- toggle
  121.                     ta := not ta;
  122.                 elsif J='0' and K='1' then -- reset
  123.                     ta := '0';
  124.                 elsif J='1' and K='0' then -- set
  125.                     ta := '1';
  126.                 else -- no change
  127.                     ta := ta;
  128.                 end if;
  129.             end if;
  130.         end if;
  131.         Q <= ta;
  132.     end process;
  133. end jk2;
  134.  
  135.  
  136. -------------------------------------------
  137. library IEEE;
  138. use IEEE.STD_LOGIC_1164.ALL;
  139.  
  140. -- jk latch
  141. entity jk is
  142.     port(J,K,C  :in bit; Q : out bit);
  143. end jk;
  144.  
  145. architecture jk1 of jk is -- przerzutnik jk bez wejscia reset
  146. begin
  147.     process(C)
  148.         variable ta: bit;
  149.     begin
  150.         if (C'event and C='1') then -- on clock input
  151.             if J='1' and K='1' then -- toggle
  152.                 ta := not ta;
  153.             elsif J='0' and K='1' then -- reset
  154.                 ta := '0';
  155.             elsif J='1' and K='0' then -- set
  156.                 ta := '1';
  157.             else -- no change
  158.                 ta := ta;
  159.             end if;
  160.         end if;
  161.         Q <= ta;
  162.     end process;
  163. end jk1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement