Altera_Forum
Honored Contributor
13 years agoBlinking LED
Hi,
I am trying to make a design that makes the LED blink 4 times when iKEY is pressed. Right now it blinks non stop when iKEY is pressed and stops blinking when iKEY is pressed again. What changes should I make to make that happen ? library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.numeric_std.all; use ieee.std_logic_unsigned.all; entity pract is port ( iCLK_50 : in std_logic; iKEY : in std_logic_vector(0 downto 0); oLEDG: out std_logic_vector(2 downto 0) ); end entity pract; architecture behav of pract is signal sel : std_logic_vector(0 downto 0) := "0"; signal newCLK : std_logic_vector (0 downto 0) := "1"; signal counting: integer := 0; signal cycles : integer :=0 ; type state_type is (idle, s0, s1, s2, s3); signal current_state, next_state : state_type; --signal begin ------------------------------------------------------- -----------clk code------------------------------------ clocking : process(iCLK_50, iKEY) begin if(rising_edge(iCLK_50)) then counting <= counting + 1; if (counting >= 100000000) then counting <= 0; end if; end if; end process; newclocking: process(counting) begin if(counting <= 50000000) then newCLK <= "0"; else newCLK <= "1"; end if; end process; -------------end clk code------------------------------ ------------------------------------------------------- p1 : process(iKEY) begin if(rising_edge(iKEY(0))) then sel <= sel + "1"; end if; end process; p2 : process(sel) begin case sel is when "1"=> -- go to s0 case newCLK is when "0" => oLEDG <= "000"; when "1" => oLEDG <= "111"; end case; when "0"=> oLEDG <= "000"; -- restart the counter or something end case; end process; end behav; Thanks