Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

LED lights, SWITCHES and between :)

Hi all,

I would like to greet and thank for beeing here and answering

i'm kind of new to VHDL and trying to perfrom a project with my new DE2-115 and i hope that you guys can help me figure out how to :

i want to use these ports:

port(	          IF1:  IN STD_LOGIC;      --InfraRed 1
		  IF2:  IN STD_LOGIC;		--InfraRed 2
		  LED2: OUT STD_LOGIC);		--LED 2
		  LED1: OUT STD_LOGIC);	   --LED 1

when i'm switching IF1 on, and then IF2 ON - LED1 will turn on.

that was accomplish by -

LED1 <= IF1 AND IF2;

my question is - how to make LED2 turned ON 1 sec after LED1 ?

i know that is need to use the 50MHz clk_out of the DE2, but can't implement it..

i have this code so far:

					
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
	--entity mode_one IS
	--
	--generic (width1s : integer := 1); --pulse width1s of 1 seconds
	--
	--port(	  clk_in: IN STD_LOGIC; --50Mhz DE2 input
	--		  reset : IN std_logic;
	--		  IF1: IN STD_LOGIC;    --InfraRed 1
	--		  IF2: IN STD_LOGIC;		--InfraRed 2
	--		  LED2:OUT STD_LOGIC;		--LED 2
	--		  LED1: OUT STD_LOGIC;	--LED 1
	--		  switch_in: in std_logic); --test switch to delay 1 sec'
	--		  
	--END mode_one;
	--
	--architecture behave OF mode_one IS
	----1st process -divider- internal memories
	--signal counter: integer range 50000000 downto 0; 
	--signal clk_out: std_logic; 
	----2nd process -oneshot- internal memories
	signal cnt: integer range 0 to width1s;
	
		BEGIN
		
	
	divider: process(clk_in)
	BEGIN
		LED1 <= IF1 AND IF2;
		IF clk_in'EVENT AND clk_in = '1' THEN --calculating untill counter =25M
			if counter = 50000000 then
				clk_out <= NOT clk_out; --switching the output pulse. only when counter =25M
				counter <= 0;
			ELSE counter <= counter+1;
			end if;
		end if;
	end process;	
oneshot: process (cnt,clk_out,switch_in,reset)
	BEGIN
		if reset ='0' then
			clk_out <= '0';	
			cnt <= 0;
		else if switch_in  = '1' then
				if clk_out'EVENT and clk_out = '1' then
					if cnt < width1s then
						clk_out <= '1';
						cnt <= cnt+1;
						else 
						cnt <= 0;
						clk_out <= '0';	
					end if;
				end if;
			end if;
		end if;
end process;
end behave;

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Your idea is basically correct, just a few mistakes with your implementation...

    You are updating 'clk_out' in both your 'divider' and 'oneshot' processes. You can't do that. Only update a signal in a single process - (you can always read/test a signal in another process).

    By looking for an event on 'clk_out' you're trying to use it as a clock. Assuming you weren't trying to update it in the same process, this could be possible - this is a derived clock - but it's not very good practice.

    I suggest you simplify the first process - just run the counter to 50M.

    I suggest changing the second process to a clocked process. In there, check the 'counter' (e.g. for zero, which will happened every 1 second) and then act, updating IF1 & IF2.

    Start with that and, if you still have problems, update the post.

    Cheers,

    Alex