Advertisement
mdabkow

Untitled

Nov 28th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. ----------------------------------------------
  2. -- Uruchomienie na płytce DE1:
  3. -- Set As Top-Level Entity na plik za_de1.vhd.
  4. -- W komentarzach znajduje się opis przypisania sygnałów do przełączników i diod.
  5. -----------------------------------------------
  6.  
  7.  
  8. library ieee;
  9. use ieee.std_logic_1164.all;
  10.  
  11. --zad. 1, cw2
  12. entity automat is
  13. port(
  14. clk, clrn : in std_logic;
  15. sclr : in std_logic;
  16. x1, x2 : in std_logic;
  17. c : out std_logic;
  18. me : out std_logic_vector(1 downto 0);
  19. mo1, mo0: out std_logic;
  20. ST : out std_logic_vector(2 downto 0)
  21. );
  22. end entity;
  23.  
  24. architecture arch of automat is
  25. type tauto is (S0, S1, S2, S3, S4);
  26. signal auto_r, auto_n : tauto;
  27. attribute syn_encoding: string;
  28. attribute syn_encoding of tauto: type is "one-hot";
  29.  
  30. begin
  31.  
  32. p1:
  33. process(clk, clrn)
  34. begin
  35. if(clrn = '0') then
  36. auto_r <= S0;
  37. elsif(rising_edge(clk)) then
  38. auto_r <= auto_n;
  39. end if;
  40. end process p1;
  41.  
  42. p2:
  43. process(auto_r,sclr, x1, x2)
  44. begin
  45. me <= "00";
  46. case auto_r is
  47. when S0 =>
  48. if(x2 = '0' or x1 = '1') then
  49. auto_n <= S0;
  50. else
  51. auto_n <= S1;
  52. end if;
  53. when S1 =>
  54. if(x2 = '1' and x1 = '1') then
  55. auto_n <= S2;
  56. else
  57. auto_n <= S1;
  58. end if;
  59. when S2 =>
  60. if(x2 = '1' and x1 = '1') then
  61. auto_n <= S3;
  62. elsif(x2 = '1' and x1 = '0') then
  63. auto_n <= S1;
  64. me <= "01";
  65. else
  66. auto_n <= S2;
  67. end if;
  68. when S3 =>
  69. if(x2 = '1' and x1 = '1') then
  70. auto_n <= S0;
  71. elsif(x2 = '1' and x1 = '0') then
  72. auto_n <= S4;
  73. me <= "11";
  74. else
  75. auto_n <= S3;
  76. end if;
  77. when S4 =>
  78. if(x2 = '1' and x1 = '1') then
  79. auto_n <= S0;
  80. me <= "01";
  81. elsif(x2 = '1' and x1 = '0') then
  82. auto_n <= S1;
  83. else
  84. auto_n <= S4;
  85. end if;
  86. end case;
  87. if(sclr = '1') then
  88. auto_n <= S0;
  89. end if;
  90. end process p2;
  91.  
  92. p3:
  93. process(auto_r)
  94. begin
  95. case auto_r is
  96. when S0 =>
  97. mo1 <= '0'; mo0 <= '0';
  98. ST <= "000";
  99. when S1 =>
  100. mo1 <= '0'; mo0 <= '1';
  101. ST <= "001";
  102. when S2 =>
  103. mo1 <= '0'; mo0 <= '1';
  104. ST <= "010";
  105. when S3 =>
  106. mo1 <= '0'; mo0 <= '1';
  107. ST <= "011";
  108. when S4 =>
  109. mo1 <= '1'; mo0 <= '1';
  110. ST <= "100";
  111. end case;
  112. end process p3;
  113.  
  114. c <= '1' when auto_r = S3 and x2 = '1' and x1 = '0' else '0';
  115. end arch;
  116.  
  117.  
  118.  
  119.  
  120. Licznik
  121.  
  122. library ieee;
  123. use ieee.std_logic_1164.all;
  124. use ieee.numeric_std.all;
  125.  
  126. --zad. 1, cw2
  127. entity licz_rej is
  128. port(
  129. clk, clrn : in std_logic;
  130. sclr : in std_logic;
  131. cnt, ld : in std_logic;
  132. L : out std_logic_vector(3 downto 0);
  133. R : out std_logic_vector(3 downto 0)
  134. );
  135. end entity;
  136.  
  137. architecture arch of licz_rej is
  138. signal reg : std_logic_vector(3 downto 0);
  139. signal l_r, l_n : unsigned(3 downto 0);
  140. begin
  141.  
  142. p1:
  143. process(clk, clrn)
  144. begin
  145. if(clrn = '0') then
  146. reg <= (others => '0');
  147. l_r <= (others => '0');
  148. elsif(rising_edge(clk)) then
  149. if(sclr = '1') then
  150. reg <= (others => '0');
  151. elsif(ld = '1') then
  152. reg <= std_logic_vector(l_r);
  153. end if;
  154. l_r <= l_n;
  155. end if;
  156. end process p1;
  157.  
  158. l_n <= (others => '0') when sclr = '1' else
  159. l_r + 1 when cnt = '1' else
  160. l_r;
  161. L <= std_logic_vector(l_r);
  162. R <= reg;
  163. end arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement