Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Karolina Sroczyk 243280
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- entity top is
- Port ( reset : in STD_LOGIC;
- clock : in STD_LOGIC;
- switch : in STD_LOGIC;
- led : out STD_LOGIC);
- end top;
- architecture Behavioral of top is
- TYPE states IS (start, detection, glare);
- signal timer : std_logic_vector (7 downto 0);
- signal timer_glare : std_logic_vector (7 downto 0);
- signal state, next_state: states;
- signal led_g : std_logic;
- begin
- reg: process (clock, reset)
- begin
- if(reset = '1') then
- state <= start;
- elsif (clock'event and clock = '1') then
- state <= next_state;
- end if;
- end process reg;
- komb: process (state, switch)
- begin
- next_state <= state;
- case state is
- when start =>
- led_g <= '0';
- next_state <= detection;
- when detection =>
- if (switch = '1' and timer > "01110100") then
- next_state <= glare;
- else
- next_state <= start;
- end if;
- when glare =>
- led_g <= '1';
- if (timer_glare > "00001011") then
- led_g <= '0';
- next_state <= start;
- end if;
- end case;
- end process komb;
- counter:process(clock)
- begin
- if (reset ='1') then
- timer <= "00000000";
- elsif (switch = '1') then
- if (clock'event and clock = '1') then
- timer <= timer + "01";
- end if;
- else
- timer <= "00000000";
- end if;
- end process counter;
- cou:process(clock)
- begin
- if (reset = '1') then
- timer_glare <= "00000000";
- elsif (led_g ='1') then
- if (clock'event and clock = '1') then
- timer_glare <= timer_glare + "01";
- end if;
- else
- timer_glare <= "00000000";
- end if;
- end process cou;
- led <= led_g;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement