In: Electrical Engineering
1. Design a blinking LED with two speeds - slow and fast.
Specification
To change from slow to fast press Button 1 and fast to slow press Button 2.
Reset puts the machine to slow blinking.
entity blink is port (b1, b2, ck, reset: in std_logic;
z: out std_logic);
end blink;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity blink is
port (b1, b2, ck, reset: in std_logic;
z: out std_logic);
end blink;
architecture behavioural of blink is
signal counter : std_logic_vector(3 downto 0);
begin
process (clk)
begin
if (clk'even and clk = '1') then
if (rst = '1') then
counter <= "0000";
else
if(b1 = '1') then
if (counter = "0111") then
counter <= "0000";
end if;
elsif (b2 = '1') then
if (counter = "1111") then
counter <= "0000";
end if;
end if;
counter <= counter + 1;
end if;
end if;
end process;
process (b1, b2, rst, counter)
begin
if (rst = '1') then
blink <= '0';
else
if(b1 = '1') then
if (counter = "0111") then
blink <= not blink;
end if;
else -- with reset or with b2
if (counter = "1111") then
blink <= not blink;
end if;
end if;
end if;
end process;
end behavioural;