Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.11 KB | None | 0 0
  1.  
  2. library ieee;
  3. use ieee.std_logic_1164.all;
  4. use ieee.numeric_std.all;
  5.  
  6. ENTITY fsm IS
  7. port (  reset: in std_logic;
  8.     clk: in std_logic;
  9.     w, c, r: in std_logic;
  10.     enable: out std_logic_vector(0 to 1);
  11.     licz, drive, creset: out std_logic);
  12. END ENTITY fsm;
  13.  
  14. --
  15. ARCHITECTURE z12 OF fsm IS
  16.  
  17. type stany is (idle, read, write1, write2, compare);
  18. signal state, next_state : stany;
  19. signal req: std_logic_vector(2 downto 0);
  20.  
  21. BEGIN
  22.  
  23. synchrP: process (clk, reset)
  24. begin
  25.     if reset='0' then
  26.         state <= idle;
  27.     elsif (rising_edge(clk)) then
  28.         state<= next_state;
  29.     end if;
  30. end process;
  31.  
  32. req <= w&c&r;
  33.  
  34. kombP: process(state, req)
  35. begin
  36.    
  37. case state is
  38. when idle =>    
  39.     if (req="100") then
  40.         next_state <= write1; enable <= "10"; licz<='0'; drive <= '0'; creset <='0';
  41.     elsif (req="010") then
  42.         next_state <= compare; enable<="00"; licz<='1'; drive <= '0'; creset <='0';
  43.     elsif (req="001") then
  44.         next_state <= read; enable<="00"; licz<='0'; drive <= '0'; creset <='0';
  45.     else
  46.         next_state <= idle; enable<="00"; licz<='0'; drive <= '0'; creset <='0';
  47.     end if;        
  48.    
  49.  
  50. when read =>            
  51.            if (req="100") then
  52.         next_state <= write1; enable <= "00"; licz<='0'; drive <= '1'; creset <='0';
  53.     elsif (req="010") then
  54.         next_state <= compare; enable<="00"; licz<='1'; drive <= '1'; creset <='0';
  55.     elsif (req="001") then
  56.         next_state <= read; enable<="00"; licz<='0'; drive <= '1'; creset <='0';
  57.     else
  58.         next_state <= idle; enable<="00"; licz<='0'; drive <= '1'; creset <='0';
  59.     end if;    
  60.  
  61. when write1 =>
  62.            if (req="100") then
  63.         next_state <= write2; enable <= "01"; licz<='0'; drive <= '0'; creset <='1';
  64.     elsif (req="010") then
  65.         next_state <= write2; enable<="01"; licz<='0'; drive <= '0'; creset <='1';
  66.     elsif (req="001") then
  67.         next_state <= write2; enable<="01"; licz<='0'; drive <= '0'; creset <='1';
  68.     else
  69.         next_state <= write2; enable<="01"; licz<='0'; drive <= '0'; creset <='1';
  70.     end if;    
  71.  
  72. when write2 =>
  73.            if (req="100") then
  74.         next_state <= idle; enable <= "00"; licz<='0'; drive <= '0'; creset <='0';
  75.     elsif (req="010") then
  76.         next_state <= compare; enable<="00"; licz<='1'; drive <= '0'; creset <='0';
  77.     elsif (req="001") then
  78.         next_state <= read; enable<="00"; licz<='0'; drive <= '0'; creset <='0';
  79.     else
  80.         next_state <= idle; enable<="00"; licz<='0'; drive <= '0'; creset <='0';
  81.     end if;    
  82.  
  83. when compare =>    
  84.          if (req="100") then
  85.         next_state <= write1; enable <= "00"; licz<='0'; drive <= '0'; creset <='0';
  86.     elsif (req="010") then
  87.         next_state <= compare; enable<="00"; licz<='1'; drive <= '0'; creset <='0';
  88.     elsif (req="001") then
  89.         next_state <= read; enable<="00"; licz<='0'; drive <= '0'; creset <='0';
  90.     else
  91.         next_state <= idle; enable<="00"; licz<='0'; drive <= '0'; creset <='0';
  92.     end if;    
  93.  
  94. end case;
  95. end process;
  96.  
  97.        
  98. END ARCHITECTURE z12;
  99. --Kocham CiÄ™, ale nie pokazuj tego na labkach <3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement