Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.04 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4. use ieee.numeric_std.all;
  5.  
  6.  
  7. entity JK is port(
  8.     CLK : in std_logic;
  9.     R : in std_logic;
  10.     J,K : in std_logic;
  11.     Q,NQ : out std_logic
  12. );
  13. end JK;
  14.  
  15. architecture JK_arch of JK is
  16.  
  17. signal q1: std_logic:='0';
  18. signal nq1 : std_logic:='1';
  19.  
  20. begin
  21. process(CLK,R)
  22. begin
  23.     if (R = '1') then
  24.         q1 <= '0';
  25.         nq1 <= '1';
  26.     elsif (rising_edge(CLK)) then
  27.         if (J = '1') then
  28.             if (K = '1') then
  29.                 q1 <= not(q1);
  30.                 nq1 <= not(nq1);
  31.             else
  32.                 q1 <= '1';
  33.                 nq1 <= '0';
  34.             end if;
  35.         else
  36.             if (K = '1') then
  37.                 q1 <= '0';
  38.                 nq1 <= '1';
  39.             end if;
  40.         end if;
  41.     end if;
  42.     Q <= q1;
  43.     NQ <= nq1;
  44. end process;
  45. end JK_arch;
  46.  
  47. library ieee;
  48. use ieee.std_logic_1164.all;
  49. use ieee.std_logic_unsigned.all;
  50. use ieee.numeric_std.all;
  51.  
  52. entity licz74193 is port(
  53.     clk:in std_logic;
  54.     r:in std_logic;
  55.     en:in std_logic;
  56.     out4:out std_logic_vector(3 downto 0);
  57.     max:out std_logic
  58. );
  59. end licz74193;
  60.  
  61. architecture licz74193_arch of licz74193 is
  62.  
  63. component JK is port(
  64.      CLK : in std_logic;
  65.     R : in std_logic;
  66.     J,K : in std_logic;
  67.     Q,NQ : out std_logic
  68.  );
  69. end component;
  70.  
  71. signal v4 : std_logic_vector(3 downto 0);
  72. signal nv4 : std_logic_vector(3 downto 0);
  73. signal n_v4 : std_logic_vector(3 downto 0);
  74. signal n_nv4 : std_logic_vector(3 downto 0);
  75. signal rst : std_logic;
  76.  
  77. begin
  78.  
  79. stage0: JK port map (clk,rst,en,en,n_v4(0),n_nv4(0));
  80. stage1: JK port map (nv4(0),rst,en,en,n_v4(1),n_nv4(1));
  81. stage2: JK port map (nv4(1),rst,en,en,n_v4(2),n_nv4(2));
  82. stage3: JK port map (nv4(2),rst,en,en,n_v4(3),n_nv4(3));
  83.  
  84. process(clk)
  85. begin
  86.     if (n_v4 = "0000") then
  87.         max <= '1';
  88.         --rst <= '1';
  89.     else
  90.         rst <= r;
  91. end if;
  92. end process;
  93.  
  94.  
  95. v4 <= n_v4;
  96. nv4 <= n_nv4;
  97. out4 <= v4;
  98.  
  99. end licz74193_arch;
  100.  
  101.  
  102. library ieee;
  103. use ieee.std_logic_1164.all;
  104. use ieee.std_logic_unsigned.all;
  105. use ieee.numeric_std.all;
  106.  
  107. entity licznik is port(
  108.     clk:in std_logic;
  109.     r:in std_logic;
  110.     en:in std_logic;
  111.     res8:out std_logic_vector(7 downto 0);
  112.     m:out std_logic
  113. );
  114. end licznik;
  115.  
  116. architecture licznik_arch of licznik is
  117.  
  118. component licz74193 is port(
  119.     clk:in std_logic;
  120.     r:in std_logic;
  121.     en:in std_logic;
  122.     out4:out std_logic_vector(3 downto 0);
  123.     max:out std_logic
  124. );
  125. end component;
  126.  
  127.  
  128. signal result : std_logic_vector(7 downto 0);
  129. signal n_result : std_logic_vector(7 downto 0);
  130. signal maxi : std_logic := '0';
  131. --signal maxi2 : std_logic := '0';
  132. signal rst : std_logic := '0';
  133.  
  134. begin
  135.  
  136. stage0: licz74193 port map(clk,rst,en,n_result(3 downto 0));
  137. stage1: licz74193 port map(clk,rst,maxi,n_result(7 downto 4));
  138.  
  139. result <= n_result;
  140. res8 <= result;
  141. --maxi2 <= maxi;
  142.  
  143. process(clk)
  144. begin
  145. if (n_result = "00010101") then
  146.     rst <= '1';
  147.     maxi <= '0';
  148. elsif (n_result = "00001111") then
  149.     rst <= '0';
  150.     maxi <= '1';
  151. else
  152.     rst <= '0';
  153.     maxi <= '0';
  154. end if;
  155. end process;
  156.  
  157.  
  158. end licznik_arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement