Advertisement
Guest User

Coffee Fsm

a guest
Oct 5th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.49 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity F is
  5. port(
  6.     clk, input, areset: in std_logic;
  7.     output: out std_logic_vector(2 downto 0)
  8. );
  9. end F;
  10.  
  11. architecture arch of F is
  12.  
  13.     type state_type is (A, B, C, D, E, F, G);
  14.     signal state, prev_state: state_type;
  15.  
  16.     begin
  17.  
  18.     process(clk, areset)
  19.         begin
  20.         if areset='1' then state<=A;
  21.         elsif(clk'event and clk='1') then
  22.         case state is
  23.             when A=>
  24.             if(input='1') then
  25.             state<=B;
  26.             prev_state<=A;
  27.             end if;
  28.             when B=>
  29.             if(input='1') then state<=C;
  30.             else state<=A;
  31.             end if;
  32.             prev_state<=B;
  33.             when C=>
  34.             if(prev_state=B and input='1') then
  35.             state<=D;
  36.             elsif((prev_state=E or prev_state=F) and input='1') then
  37.             state<=F;
  38.             else state<=A;
  39.             end if;
  40.             -- don't calculate prev_state
  41.             when D=>
  42.             if(input='1') then state<=E;
  43.             else state<=C;
  44.             end if;
  45.             -- don't calculate prev_state
  46.             when E=>
  47.             if(input='0') then
  48.             state<=D;
  49.             elsif(input='1' and prev_state=F) then
  50.             state<=G;
  51.             end if;
  52.             prev_state<=E;
  53.             when F=>
  54.             if(input='1') then state<=G;
  55.             else state<=C;
  56.             end if;
  57.             prev_state<=F;
  58.             when G=>
  59.             -- nothing happens
  60.         end case;
  61.         end if;
  62.     end process;
  63.  
  64.     process(state, input)
  65.         begin
  66.         case state is
  67.             when A=>
  68.             output<="000";
  69.             when B=>
  70.             output<="001";
  71.             when C=>
  72.             output<="010";
  73.             when D=>
  74.             output<="011";
  75.             when E=>
  76.             output<="100";
  77.             when F=>
  78.             output<="101";
  79.             when G=>
  80.             output<="110";
  81.         end case;
  82.     end process;
  83.  
  84. end arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement