2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
11 leds : out std_logic_vector(7 downto 0));
16 architecture behav of demo is
18 function GetShiftDelay return time is
27 signal knightlight, knightlight_next : std_logic_vector (7 downto 0);
29 type LEDSTATE_T is (LEFT_S, RIGHT_S);
30 signal ledstate, ledstate_next : LEDSTATE_T;
32 subtype counter_t is integer range 0 to (GetShiftDelay / PERIOD);
33 signal counter : counter_t;
35 signal syncreset : std_logic;
41 if rising_edge(clk) then
47 sync: process(clk, reset)
49 if rising_edge(clk) then
50 if syncreset = RESETVALUE then
51 knightlight <= (others => LED_OFF);
52 knightlight(2 downto 0) <= (others => LED_ON);
55 knightlight <= knightlight_next;
56 ledstate <= ledstate_next;
61 next_state_logic: process(ledstate, knightlight, counter)
62 variable knightlight_tmp : bit_vector (7 downto 0);
64 -- default assignments
65 ledstate_next <= ledstate;
66 knightlight_tmp := TO_BITVECTOR(knightlight);
70 if counter = counter_t'high - 1 then
71 knightlight_tmp := knightlight_tmp sll 1;
73 if knightlight_tmp = "11100000" then
74 ledstate_next <= RIGHT_S;
77 if counter = counter_t'high - 1 then
78 knightlight_tmp := knightlight_tmp srl 1;
80 if knightlight_tmp = "00000111" then
81 ledstate_next <= LEFT_S;
86 knightlight_next <= TO_STDLOGICVECTOR(knightlight_tmp);
89 counterProcess: process(clk, reset)
91 if rising_edge(clk) then
92 if syncreset = RESETVALUE then
94 elsif counter < counter_t'high then
95 counter <= counter + 1;
102 leds <= not knightlight;