Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 20:29:18 03/27/2017
  6. -- Design Name:
  7. -- Module Name: ProgrammingBlock - 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. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. ---- Uncomment the following library declaration if instantiating
  26. ---- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29.  
  30. entity Machine3 is
  31. PORT (
  32. clk : IN std_logic;
  33. input: IN std_logic;
  34. output : OUT std_logic ;
  35. state : out std_logic_vector (1 downto 0));
  36. end Machine3;
  37.  
  38. architecture Behavioral of Machine3 is
  39.  
  40. constant A : std_logic_vector(1 downto 0) := "000";
  41. constant B : std_logic_vector(1 downto 0) := "001";
  42. constant C : std_logic_vector(1 downto 0) := "010";
  43. constant D : std_logic_vector(1 downto 0) := "011";
  44. constant E : std_logic_vector(1 downto 0) := "100";
  45.  
  46. Signal currentState : std_logic_vector := A;
  47. Signal outputS : std_logic := '0';
  48. begin
  49.  
  50. process (clk)
  51.  
  52. if (clk'event AND clk = '1') then
  53. if (currentState = A) then
  54. if(input=0) then
  55. currentState <= C;
  56. outputS<='1';
  57. else
  58. currentState <= B;
  59. outputS<='0';
  60. end if;
  61. elsif(currentState = B) then
  62. if(input=0) then
  63. currentState <= D;
  64. outputS<='0';
  65. else
  66. currentState <= A;
  67. outputS<='1';
  68. end if;
  69. elsif (currentState = C) then
  70. if(input=0) then
  71. currentState <= E;
  72. outputS<='0';
  73. else
  74. currentState <= C;
  75. outputS<='0';
  76. end if;
  77.  
  78. elsif (currentState = D) then
  79. if(input=0) then
  80. currentState <= C;
  81. outputS<='1';
  82. else
  83. currentState <= E;
  84. outputS<='0';
  85. end if;
  86.  
  87. else
  88. if(input=0) then
  89. currentState <= B;
  90. outputS<='1';
  91. else
  92. currentState <= D;
  93. outputS<='1';
  94. end if;
  95. end if;
  96. end if;
  97. end process;
  98. state <= currentState;
  99. output <= outputS;
  100. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement