Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.27 KB | None | 0 0
  1. entity source is
  2. port(  
  3.         clk      : in   bit;
  4.         day      : in   bit;
  5.     vdd      : in   bit;
  6.     vss      : in   bit;
  7.     i        : in   bit_vector(3 downto 0);
  8.     reset    : in   bit;
  9.     door     : out  bit;
  10.         alarm    : out  bit
  11.      );
  12. end entity source;
  13. ARCHITECTURE fsm of source IS
  14. TYPE state_type IS (E0, Ea, E1, E2, E3, E4, E5);
  15. SIGNAL current_state, next_state: state_type;
  16.  
  17.  
  18.  
  19. --pragma CURRENT_STATE current_state
  20. --pragma NEXT_STATE    next_state
  21. --pragma CLOCK         clk
  22.  
  23.  
  24. BEGIN
  25. -- Process (1): Transition and Generation functions
  26. CS: PROCESS (current_state, i, reset) IS
  27. BEGIN
  28. -- Next state Transition function = f(inputs)
  29. if (reset = '1') THEN next_state <= E0;
  30. else
  31. case current_state is
  32. WHEN E0 =>
  33.  
  34. IF (i="0010") THEN
  35. next_state <= E1;
  36. ELSIF  (i="1010" AND day='1') THEN
  37.  
  38. next_state <= E5;
  39. Else
  40. next_state <= Ea;
  41. end if;
  42.  
  43.  
  44. WHEN E1 =>
  45.  
  46. IF i="0110" THEN
  47. next_state <= E2;
  48. ELSIF  i="1010" AND day='1' THEN
  49. next_state <= E5;
  50. Else
  51. next_state <= Ea;
  52. end if;
  53.  
  54. WHEN E2 =>
  55.  
  56. IF i="1111" THEN
  57. next_state <= E3;
  58. ELSIF  i="1010" AND day='1' THEN
  59.  
  60. next_state <= E5;
  61. Else
  62. next_state <= Ea;
  63. end if;
  64. WHEN E3 =>
  65.  
  66. IF i="0000" THEN
  67. next_state <= E4;
  68. ELSIF  i="1010" AND day='1' THEN
  69. next_state <= E5;
  70. Else
  71. next_state <= Ea;
  72. END IF;
  73.  
  74. WHEN E4 =>
  75.  
  76. IF i="0101" THEN
  77. next_state <= E5;
  78. ELSIF  i="1010" AND day='1' THEN
  79.  
  80. next_state <= E5;
  81. Else
  82. next_state <= Ea;
  83. end if;
  84. WHEN E5 =>
  85.  
  86. next_state <= E5;
  87.  
  88. WHEN Ea =>
  89.  
  90. next_state <= Ea;
  91.  
  92.  
  93.  
  94. end case;
  95. end if;
  96. -- output generation function =f(states)
  97. case current_state is
  98.  
  99. when E0 =>
  100.         alarm <= '0';
  101.             door  <= '0';
  102.         when E1 =>
  103.        alarm <= '0';
  104.            door  <= '0';
  105.         when E2 =>
  106.         alarm <= '0';
  107.             door  <= '0';
  108.         when E3 =>
  109.         alarm <= '0';
  110.             door  <= '0';
  111.         when E4 =>
  112.             alarm <= '0';
  113.             door  <= '0';
  114.         when E5 =>
  115.             alarm <= '0';
  116.             door  <= '1';
  117.         when Ea =>
  118.             alarm <= '1';
  119.             door  <= '0';
  120. end case;
  121. end process CS;
  122. -- Process (2): State update (sequential)
  123. Operation: PROCESS (clk)
  124. BEGIN
  125.  if (clk='1' and not clk'stable) then
  126.       current_state <= next_state;
  127.     end if;
  128.  
  129. END PROCESS Operation;
  130. END ARCHITECTURE fsm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement