Altera_Forum
Honored Contributor
12 years agocan someone help on this
Hi all,
I am working on a finite state machine assignment. I have the following code below which i want key_0, key_1, key_2 and key_3 to influence the out LEDR[1..0] and LEDG[1..0]. key_0 and key_1 work very well when pressed the LEDG lights come on but i donot understand why key_2 and key_3 does not affect the LEDR lights when i run the code on the DE2-115 altera circuit board. I have tried to modify the code several times but still nothing happens. Thank you vhdl gurus for helping: ----------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity uppgift_dorr is port( clk : in std_logic; --clock signal reset : in std_logic; --reset signal key_0, key_1, key_2, key_3 : in std_logic; LEDR : out std_logic_vector (1 downto 0); -- Output LEDG : out std_logic_vector (1 downto 0) -- Output ); end uppgift_dorr; architecture Behavioral of uppgift_dorr is --Defines the type for states in the state machine type state_type is (closed,opened,locked,unlocked); --Declare the signal with the corresponding state type. signal Current_State, Next_State : state_type; begin -- Synchronous Process process(clk, reset) begin if( reset = '1' ) then --Synchronous Reset Current_State <= closed; elsif (rising_edge(clk)) then --Rising edge of Clock Current_State <= Next_State; end if; end process; -- Combinational Process Process(Current_State, key_0, key_1, key_2, key_3) begin LEDG <= "00"; LEDR <= "00"; case Current_State is when closed => if ( key_0 = '1' ) then Next_State <= closed; LEDG <= "01"; else Next_State <= opened; LEDG <= "10"; end if; when opened => if ( key_1 = '1' ) then Next_State <= opened; LEDG <= "10"; else Next_State <= closed; LEDG <= "01"; end if; when locked => if ( key_2 = '1' ) then Next_State <= locked ; LEDR <= "10"; else Next_State <= unlocked; LEDR <= "01"; end if; when unlocked => if (key_3 = '1' ) then Next_State <= unlocked; LEDR <= "01"; else Next_State <= locked; LEDR <= "10"; end if; when others => NULL; end case; end process; end Behavioral; ------------------------ :confused: thanks for helping