DSTRN

Untitled

Jan 31st, 2021
984
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  4.  
  5. entity Semafor is
  6.     Port ( iCLK    : in  STD_LOGIC;
  7.            inRST    : in  STD_LOGIC;
  8.            oRED    : out STD_LOGIC;
  9.            oBLUE : out STD_LOGIC;
  10.               oGREEN  : out STD_LOGIC);
  11. end Semafor;
  12.  
  13. architecture Behavioral of Semafor is
  14.  
  15.     type T_STATE is (IDLE, RED, GREEN, BLUE, WRITE_CNT);
  16.    
  17.     signal sWR_EN : std_logic;
  18.     signal sD : std_logic_vector(3 downto 0);
  19.     signal sCNT : std_logic_vector(3 downto 0);
  20.    
  21.     signal sSTATE, sNEXT : T_STATE;
  22.  
  23.  
  24. begin
  25.  
  26.     -- BROJAC
  27.     process (inRST, iCLK) begin
  28.         if(inRST = '0') then
  29.             sCNT <= "0000";
  30.         elsif(iCLK'event and iCLK = '1') then
  31.        
  32.             if(sWR_EN = '1') then
  33.                 sCNT <= sD;
  34.             else
  35.                 if(sCNT = 8) then
  36.                     sCNT <= "0000";
  37.                 else
  38.                     sCNT <= sCNT + 1;
  39.                 end if;
  40.             end if;
  41.        
  42.         end if;
  43.        
  44.     end process;
  45.    
  46.     -- AUTOMAT
  47.     process (inRST, iCLK) begin
  48.         if(inRST = '0') then
  49.             sSTATE <= IDLE;
  50.         elsif(iCLK'event and iCLK = '1') then
  51.             sSTATE <= sNEXT;
  52.         end if;
  53.     end process;
  54.    
  55.     process (sSTATE, sCNT) begin
  56.         case (sSTATE) is
  57.             when IDLE =>
  58.                 if(sCNT = 3) then
  59.                     sNEXT <= RED;
  60.                 else
  61.                     sNEXT <= IDLE;
  62.                 end if;
  63.             when RED =>
  64.                 if(sCNT = 5) then
  65.                     sNEXT <= GREEN;
  66.                 else
  67.                     sNEXT <= RED;
  68.                 end if;
  69.             when GREEN =>
  70.                 if(sCNT = 7) then
  71.                     sNEXT <= WRITE_CNT;
  72.                 else
  73.                     sNEXT <= GREEN;
  74.                 end if;
  75.             when WRITE_CNT =>
  76.                 sNEXT <= BLUE;
  77.             when BLUE =>
  78.                 if(sCNT = 0) then
  79.                     sNEXT <= IDLE;
  80.                 else
  81.                     sNEXT <= BLUE;
  82.                 end if;
  83.             when others => sNEXT <= IDLE;
  84.         end case;
  85.     end process;
  86.  
  87.     process (sSTATE) begin
  88.         case (sSTATE) is
  89.             when WRITE_CNT =>
  90.                 sWR_EN <= '1';
  91.                 sD <= "0110";
  92.             when others =>
  93.                 sWR_EN <= '0';
  94.                 sD <= "0000";
  95.         end case;
  96.     end process;
  97.    
  98.     oRED <= '1' when sSTATE = RED else '0';
  99.     oGREEN <= '1' when sSTATE = GREEN else '0';
  100.     oBLUE <= '1' when sSTATE = BLUE else '0';
  101.    
  102.  
  103. end Behavioral;
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×