Advertisement
Guest User

dsvkjjkfv

a guest
Apr 6th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.02 KB | None | 0 0
  1. -- Karolina Sroczyk 243280
  2.  
  3. library IEEE;
  4. use IEEE.STD_LOGIC_1164.ALL;
  5. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  6.  
  7. entity top is
  8.     Port ( reset : in STD_LOGIC;
  9.            clock : in STD_LOGIC;
  10.            switch : in STD_LOGIC;
  11.            led : out STD_LOGIC);
  12. end top;
  13.  
  14. architecture Behavioral of top is
  15.  
  16. TYPE states IS (start, detection, glare);
  17. signal timer : std_logic_vector (7 downto 0);
  18. signal timer_glare : std_logic_vector (7 downto 0);
  19. signal state, next_state: states;
  20. signal led_g : std_logic;
  21.  
  22. begin
  23.  
  24. reg: process (clock, reset)
  25. begin
  26.         if(reset = '1') then
  27.             state <= start;
  28.         elsif (clock'event and clock = '1') then
  29.             state <= next_state;
  30.         end if;
  31. end process reg;
  32.  
  33. komb: process (state, switch)
  34. begin
  35.     next_state <= state;
  36.     case state is
  37.         when start =>
  38.            
  39.             led_g <= '0';
  40.             next_state <= detection;
  41.         when detection =>
  42.             if (switch = '1' and timer > "01110100") then
  43.                 next_state <= glare;
  44.             else
  45.                 next_state <= start;
  46.             end if;
  47.         when glare =>
  48.            
  49.            
  50.                 led_g <= '1';
  51.             if (timer_glare > "00001011") then
  52.                 led_g <= '0';
  53.                 next_state <= start;
  54.             end if;
  55.      end case;
  56. end process komb;
  57.  
  58. counter:process(clock)
  59. begin
  60.     if (reset ='1') then
  61.         timer <= "00000000";
  62.     elsif (switch = '1') then
  63.         if (clock'event and clock = '1') then
  64.             timer <= timer + "01";
  65.          end if;
  66.     else
  67.         timer <= "00000000";
  68.        
  69.    
  70.            
  71.     end if;
  72. end process counter;
  73.  
  74. cou:process(clock)
  75. begin
  76.     if (reset = '1') then
  77.         timer_glare <= "00000000";
  78.     elsif (led_g ='1') then
  79.         if (clock'event and clock = '1') then
  80.             timer_glare <= timer_glare + "01";
  81.         end if;
  82.     else
  83.         timer_glare <= "00000000";
  84.      end if;
  85.    
  86. end process cou;
  87.  
  88. led <= led_g;
  89.  
  90. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement