Advertisement
Guest User

Mealy VHDL

a guest
Nov 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.all;
  3.  
  4. ENTITY mealy IS
  5. PORT (
  6. I IN BIT;
  7. reset, clockIN BIT;
  8. O OUT BIT);
  9. END mealy;
  10.  
  11. ARCHITECTURE mealy OF mealy IS
  12. TYPE state IS (s0, s1, s2, s3, s4, s5, s6);
  13. SIGNAL pr_state, nx_state state;
  14. BEGIN
  15. PROCESS (reset, clock)
  16. BEGIN
  17. IF (reset='1') THEN
  18. pr_state = s0;
  19. ELSIF (clock'EVENT AND clock='1') THEN
  20. pr_state = nx_state;
  21. END IF;
  22. END PROCESS;
  23. PROCESS (I, pr_state)
  24. BEGIN
  25. CASE pr_state IS
  26. WHEN s0 =
  27. IF (i = '0') THEN
  28. O = '1';
  29. nx_state = s1;
  30. ELSE
  31. O = '0';
  32. nx_state = s2;
  33. END IF;
  34. WHEN s1 =
  35. IF (i = '0') THEN
  36. O = '1';
  37. nx_state = s3;
  38. ELSE
  39. O = '0';
  40. nx_state = s4;
  41. END IF;
  42. WHEN s2 =
  43. IF (i = '0') THEN
  44. O = '0';
  45. nx_state = s4;
  46. ELSE
  47. O = '1';
  48. nx_state = s4;
  49. END IF;
  50. WHEN s3 =
  51. IF (i = '0') THEN
  52. O = '0';
  53. nx_state = s5;
  54. ELSE
  55. O = '1';
  56. nx_state = s5;
  57. END IF;
  58. WHEN s4 =
  59. IF (i = '0') THEN
  60. O = '1';
  61. nx_state = s5;
  62. ELSE
  63. O = '0';
  64. nx_state = s6;
  65. END IF;
  66. WHEN s5 =
  67. IF (i = '0') THEN
  68. O = '0';
  69. nx_state = s0;
  70. ELSE
  71. O = '1';
  72. nx_state = s0;
  73. END IF;
  74. WHEN s6 =
  75. IF (i = '0') THEN
  76. O = '1';
  77. nx_state = s0;
  78. END IF;
  79. END CASE;
  80. END PROCESS;
  81. END mealy;
  82.  
  83. entity test_bench is
  84. end test_bench;
  85.  
  86. architecture test_bench_arch of test_bench is
  87. component mealy is
  88. port(
  89. I IN BIT;
  90. reset, clockIN BIT;
  91. O OUT BIT);
  92. end component;
  93. signal inp bit;
  94. signal rst, clk bit;
  95. signal outp bit;
  96. begin
  97. UUT mealy port map(inp, rst, clk, outp);
  98. process
  99. begin
  100. clk = '0';
  101. wait for 5ns;
  102. clk = '1';
  103. wait for 5ns;
  104. end process;
  105.  
  106. process
  107. begin
  108. inp = '0';
  109. wait for 10ns;
  110. inp = '1';
  111. wait for 10ns;
  112. inp = '0';
  113. wait for 10ns;
  114. inp = '1';
  115. wait for 10ns;
  116. inp = '1';
  117. wait for 10ns;
  118. inp = '0';
  119. wait for 10ns;
  120. end process;
  121.  
  122.  
  123. end test_bench_arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement