Skip to content

Instantly share code, notes, and snippets.

@makestuff
Last active June 2, 2017 12:53
Show Gist options
  • Save makestuff/7470133 to your computer and use it in GitHub Desktop.
Save makestuff/7470133 to your computer and use it in GitHub Desktop.
Blinky LEDs, Knight-Rider style.
--
-- Copyright (C) 2013 Chris McClelland
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity knight_rider is
port(
clk_in : in std_logic;
leds_out : out std_logic_vector(4 downto 0)
);
end entity;
architecture rtl of knight_rider is
signal count : unsigned(2 downto 0) := (others => '0');
signal count_next : unsigned(2 downto 0);
begin
-- Infer registers
process(clk_in)
begin
if ( rising_edge(clk_in) ) then
count <= count_next;
end if;
end process;
-- Next state logic
count_next <= count + 1;
with to_integer(count) select leds_out <=
"10000" when 0,
"01000" when 1,
"00100" when 2,
"00010" when 3,
"00001" when 4,
"00010" when 5,
"00100" when 6,
"01000" when others;
end architecture;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment