Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 11/20/2019 03:48:28 PM
  6. -- Design Name:
  7. -- Module Name: ex1 - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20.  
  21.  
  22. library IEEE;
  23. use IEEE.STD_LOGIC_1164.ALL;
  24.  
  25.  
  26. entity ex1 is
  27. Port (i: IN std_logic;
  28. reset, clock:IN std_logic;
  29. O: OUT std_logic );
  30. end ex1;
  31.  
  32. architecture Behavioral of ex1 is
  33. type stare is (s0, s1, s2, s3, s4, s5, s6);
  34. signal pr_state, nx_state: stare;
  35.  
  36. begin
  37.  
  38. PROCESS (reset, clock)
  39. BEGIN
  40. IF (reset='1') THEN
  41. pr_state <= s0;
  42. ELSIF (rising_edge(clock)) THEN
  43. pr_state <= nx_state;
  44. END IF;
  45. END PROCESS;
  46.  
  47. PROCESS (i, pr_state)
  48. BEGIN
  49. CASE pr_state IS
  50. WHEN s0 =>
  51. IF (i = '0') then
  52. nx_state <= s1;
  53. O <= '1';
  54. elsif (i = '1') then
  55. nx_state <= s2;
  56. O <= '0';
  57. end if;
  58. WHEN s1 =>
  59. IF (i = '0') then
  60. nx_state <= s3;
  61. O <= '1';
  62. elsif (i = '1') then
  63. nx_state <= s4;
  64. O <= '0';
  65. end if;
  66. WHEN s2 =>
  67. IF (i = '0') then
  68. nx_state <= s4;
  69. O <= '0';
  70. elsif (i = '1') then
  71. nx_state <= s4;
  72. O <= '1';
  73. end if;
  74.  
  75. WHEN s3 =>
  76. IF (i = '0') then
  77. nx_state <= s5;
  78. O <= '0';
  79. elsif (i = '1') then
  80. nx_state <= s5;
  81. O <= '1';
  82. end if;
  83. WHEN s4 =>
  84. IF (i = '0') then
  85. nx_state <= s5;
  86. O <= '1';
  87. elsif (i = '1') then
  88. nx_state <= s6;
  89. O <= '0';
  90. end if;
  91. WHEN s5 =>
  92. IF (i = '0') then
  93. nx_state <= s0;
  94. O <= '0';
  95. elsif (i = '1') then
  96. nx_state <= s0;
  97. O <= '1';
  98. end if;
  99.  
  100. WHEN s6 =>
  101. IF (i = '0') then
  102. nx_state <= s0;
  103. O <= '1';
  104. end if;
  105. end case;
  106. end process;
  107. end Behavioral;
  108.  
  109. library IEEE;
  110. use IEEE.STD_LOGIC_1164.ALL;
  111.  
  112. entity tb_ex1 is
  113. end tb_ex1;
  114. architecture arc of tb_ex1 is
  115. component ex1 is
  116. port (i: IN std_logic;
  117. reset, clock:IN std_logic;
  118. O: OUT std_logic );
  119. end component;
  120. signal tb_input: std_logic;
  121. signal tb_rst: std_logic;
  122. signal tb_clk: std_logic;
  123. signal tb_0: std_logic;
  124.  
  125. begin
  126. ex1_i: ex1 port map (tb_input,tb_rst,tb_clk,tb_0);
  127.  
  128.  
  129. tb_rst<='0','1' after 17 ns;
  130. tb_clk<='0','1' after 5 ns, '0' after 10 ns;
  131. tb_input <='1', '0' after 20 ns;
  132.  
  133. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement