Advertisement
lukicdarkoo

Automati: Žmigavac sa prelaskom stanja prilikom puštanje dug

Dec 5th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.00 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    22:06:10 12/03/2014
  6. -- Design Name:
  7. -- Module Name:    MainModule - 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_UNSIGNED.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity MainModule is
  34.     Port ( iCLK : in  STD_LOGIC;
  35.            inRST : in  STD_LOGIC;
  36.            inLEFT : in  STD_LOGIC;
  37.            inRIGHT : in  STD_LOGIC;
  38.            inHAZ : in  STD_LOGIC;
  39.            oLEFT : out  STD_LOGIC_VECTOR (2 downto 0);
  40.            oRIGHT : out  STD_LOGIC_VECTOR (2 downto 0)
  41.     );
  42. end MainModule;
  43.  
  44. architecture Behavioral of MainModule is
  45.     type tSTATES is (IDLE, L1, L2, L3, R1, R2, R3, LR3);
  46.     signal sSTATE: tSTATES;
  47.    
  48.     signal sDEVIDER: STD_LOGIC_VECTOR(23 downto 0);
  49.     signal sENABLE_CS: STD_LOGIC;
  50.     constant cDEVIDER_END: integer := 12;-- * 1000 * 1000 / 2;
  51.    
  52.     signal sFORCE_ENABLE_CS: STD_LOGIC; -- ButtonsFix
  53.    
  54.     signal sLEFT, sRIGHT, sHAZ, sLEFT_RIGHT: STD_LOGIC;
  55. begin
  56.     -- Proces u kome je realizovan automat, sa asihronim resetom
  57.     Automat: process (iCLK, inRST) begin
  58.         if (inRST = '0') then
  59.             sSTATE <= IDLE;
  60.            
  61.         elsif (rising_edge(iCLK)) then
  62.             if (sENABLE_CS = '1' or (sFORCE_ENABLE_CS = '1' and sSTATE = IDLE)) then
  63.                 case (sSTATE) is
  64.                     when IDLE => if (sLEFT = '1') then
  65.                                         sSTATE <= L1;
  66.                                     elsif (sRIGHT = '1') then
  67.                                         sSTATE <= R1;
  68.                                     elsif (sHAZ = '1' or sLEFT_RIGHT = '1') then
  69.                                         sSTATE <= LR3;
  70.                                     else
  71.                                         sSTATE <= IDLE;
  72.                                     end if;
  73.                    
  74.                     when L1 => sSTATE <= L2;
  75.                     when L2 => sSTATE <= L3;
  76.                     when L3 => sSTATE <= IDLE;
  77.                    
  78.                     when R1 => sSTATE <= R2;
  79.                     when R2 => sSTATE <= R3;
  80.                     when R3 => sSTATE <= IDLE;
  81.                    
  82.                     when LR3 => sSTATE <= IDLE;
  83.                    
  84.                     --when others => sSTATE <= IDLE;
  85.                 end case;
  86.             end if;
  87.         end if;
  88.     end process;
  89.  
  90.     -- Binarni djelitelj
  91.     -- 12*10^6 = 2^x; log_2(12*10^6) = x; x = 24
  92.     Divider: process (iCLK, inRST) begin
  93.         if (inRST = '0') then
  94.             sDEVIDER <= (others => '0');
  95.             sENABLE_CS <= '0';
  96.         elsif (rising_edge(iCLK)) then
  97.             if (sDEVIDER = cDEVIDER_END) then
  98.                 sDEVIDER <= (others => '0');
  99.                 sENABLE_CS <= '1';
  100.             elsif (sFORCE_ENABLE_CS = '1') then
  101.                 sDEVIDER <= (others => '0');
  102.             else
  103.                 sENABLE_CS <= '0';
  104.                 sDEVIDER <= sDEVIDER + 1;
  105.             end if;
  106.         end if;
  107.     end process;
  108.    
  109.    
  110.     ButtonsFix: process (inRST, inLEFT, inRIGHT, inHAZ, sSTATE) begin
  111.         if (inRST = '0') then
  112.             sFORCE_ENABLE_CS <= '0';
  113.             sLEFT <= '0';
  114.             sRIGHT <= '0';
  115.             sHAZ <= '0';
  116.             sLEFT_RIGHT <= '0';
  117.            
  118.         elsif (sSTATE = IDLE) then
  119.             if (rising_edge(inHAZ)) then
  120.                 sFORCE_ENABLE_CS <= '1';
  121.                 sHAZ <= '1';
  122.             elsif (rising_edge(inLEFT)) then
  123.                 sFORCE_ENABLE_CS <= '1';
  124.                 sLEFT <= '1';
  125.             elsif (rising_edge(inRIGHT)) then
  126.                 sFORCE_ENABLE_CS <= '1';
  127.                 sRIGHT <= '1';
  128.             end if;
  129.         else
  130.             sFORCE_ENABLE_CS <= '0';
  131.             sLEFT <= '0';
  132.             sRIGHT <= '0';
  133.             sHAZ <= '0';
  134.             sLEFT_RIGHT <= '0';
  135.         end if;
  136.     end process;
  137.  
  138.  
  139.     -- Dodjela ukljucivanje dioda zavisno od stanja
  140.     oLEFT <= "000" when sSTATE = IDLE else
  141.         "001" when sSTATE = L1 else
  142.         "011" when sSTATE = L2 else
  143.         "111" when sSTATE = L3 else
  144.         "111" when sSTATE = LR3 else
  145.         "000";  -- R1, R2, R3
  146.  
  147.  
  148.     oRIGHT <= "000" when sSTATE = IDLE else
  149.         "100" when sSTATE = R1 else
  150.         "110" when sSTATE = R2 else
  151.         "111" when sSTATE = R3 else
  152.         "111" when sSTATE = LR3 else
  153.         "000";  -- L1, L2, L3
  154.        
  155. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement