Forum Discussion
Altera_Forum
Honored Contributor
9 years agoWhy not start the counter running when led1 gets turned on - then turn on LED2 1s later?
The following code will set GRID1 and GRID2 to '1' exactly 1s after LED1, and stay at '1' for exactly 1 clock cycle. I leave it as an exercise for you if you want it to remain on for longer
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity test_mode_tst is
port (
CLK_50MHz: in std_logic;
IF1 : IN STD_LOGIC; --InfraRed 1
IF2 : IN STD_LOGIC; --InfraRed 2
LED1 : in STD_LOGIC; --Dont get into the habit of using buffer - it can cause problems
GRID1: out STD_LOGIC;
GRID2: out STD_LOGIC
);
end test_mode_tst;
architecture rtl of test_mode_tst is
signal cnt : unsigned(24 downto 0) := (others => '0'); -- must be initialised as you have no reset
-- would otherwise be U in simulation
signal led1_i : std_logic;
signal led1_r : std_logic;
begin
LED1 <= IF1 and IF2;
led1_i <= IF1 and IF2;
process(CLK_50MHZ)
begin
if rising_edge(CLK_50MHZ) then
led1_r <= led1_i;
GRID1 <= '0';
GRID2 <= '0';
if led1_i = '1' and led1_r = '0' then --rising edge of led1
cnt <= cnt + 1; -- start counter
elsif cnt /= 0 then
cnt <= cnt + 1; -- keep counting
elsif cnt >= 50000000-1 then -- 1s later
cnt <= (others => '0');
GRID1 <= '1';
GRID2 <= '1';
end if;
end if;
end process;
end arcitecture rtl;