ВЕРХНИЙ ФАЙЛ
Код
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity led_blink is
port (
clk : in std_logic; -- синхросигнал
btn : in std_logic; --кнопка
led : out std_logic_vector(3 downto 0) --выход на светодиоды
);
end led_blink;
architecture rtl of led_blink is
signal ONN_OFF : std_logic := '1';
signal state : std_logic_vector(3 downto 0) := "0001";
signal divider : unsigned(23 downto 0) := (others => '0'); --делитель частоты
begin
main_p : process(clk)
begin
if (rising_edge(clk)) then
if (divider < 5000000) then ---если меньше 5 млн. тактов, то счётчик наращивает 1
divider <= divider + 1;
else
divider <= (others => '0');--если больше,то счётчик сбрасывается в 0
if (btn = '1') then --если нажата кнопка
ONN_OFF <= not(ONN_OFF);--светодиоды загораются
if (ONN_OFF = '1') then
state <= state(2 downto 0) & state(3);
led <= state;
else --если НЕ нажата
led <= (others => '0');--сигнал на выход светодиодов не идёт
end if;
else
ONN_OFF <= '1';
led <= (others => '0');
end if;
end if;
end if;
end process;
end rtl;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity led_blink is
port (
clk : in std_logic; -- синхросигнал
btn : in std_logic; --кнопка
led : out std_logic_vector(3 downto 0) --выход на светодиоды
);
end led_blink;
architecture rtl of led_blink is
signal ONN_OFF : std_logic := '1';
signal state : std_logic_vector(3 downto 0) := "0001";
signal divider : unsigned(23 downto 0) := (others => '0'); --делитель частоты
begin
main_p : process(clk)
begin
if (rising_edge(clk)) then
if (divider < 5000000) then ---если меньше 5 млн. тактов, то счётчик наращивает 1
divider <= divider + 1;
else
divider <= (others => '0');--если больше,то счётчик сбрасывается в 0
if (btn = '1') then --если нажата кнопка
ONN_OFF <= not(ONN_OFF);--светодиоды загораются
if (ONN_OFF = '1') then
state <= state(2 downto 0) & state(3);
led <= state;
else --если НЕ нажата
led <= (others => '0');--сигнал на выход светодиодов не идёт
end if;
else
ONN_OFF <= '1';
led <= (others => '0');
end if;
end if;
end if;
end process;
end rtl;
АНТИДРЕБЕЗГ (КОРЯВЫЙ)
Код
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Debouncer is
Port ( clk : in std_logic;
btn : in std_logic;
led : out std_logic_vector(3 downto 0));
end Debouncer;
architecture Behavioral of Debouncer is
signal led : std_logic_vector (3 downto 0);
signal btn_cl : std_logic;
begin
process (clk)
begin
if rising_edge(clk) then
if clk /= btn_cl then
btn_cl <= clk;
led <= (others => '0');
elsif led = "1111" then
btn <= btn_cl;
else
led <= led + 1;
end if;
end if;
end process;
end Behavioral;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Debouncer is
Port ( clk : in std_logic;
btn : in std_logic;
led : out std_logic_vector(3 downto 0));
end Debouncer;
architecture Behavioral of Debouncer is
signal led : std_logic_vector (3 downto 0);
signal btn_cl : std_logic;
begin
process (clk)
begin
if rising_edge(clk) then
if clk /= btn_cl then
btn_cl <= clk;
led <= (others => '0');
elsif led = "1111" then
btn <= btn_cl;
else
led <= led + 1;
end if;
end if;
end process;
end Behavioral;
Временная диаграмма работы устройства.
При загрузке в устройсво, кнопка конечно же без антидребега так идеально не работает (((
