Altera_Forum
Honored Contributor
12 years agoHelp with latches but can't figure out why after several checks
Hi all can someone figure out why this code gives the following error in Quartus II (vs 13):
It's about finite state machines with keys, ledG, ledR and 5 states (opened, closed, locked, unlocked, error): Here comes the code: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity VHDL_uppgift_4c is port ( clk : in std_logic; -- sync clock signal reset_n: in std_logic; -- async reset signal key_0 : in std_logic; -- door open input button key_1 : in std_logic; -- door closing button key_2 : in std_logic; -- button pressed and door locks key_3 : in std_logic; -- button pressed and lock opens LED_out: out std_logic_vector(1 downto 0); LED_R: out std_logic_vector(2 downto 0) ); end VHDL_uppgift_4c; architecture final_syn of VHDL_uppgift_4c is type state_type is (closed, opened, locked, unlocked, error); -- register to hold current state signal current_state, next_state : state_type; -- defination of register of inner states -- state register begin process (clk, reset_n) begin if reset_n = '1' then -- async reset of machine current_state <= closed; -- default state after reset elsif (rising_edge(clk))then -- sync part of machine current_state <= next_state; end if; end process; process(current_state, key_0, key_1, key_2, key_3) begin case current_state is when closed => if key_0 = '1'then next_state <= opened; LED_out <= "00"; else next_state <= closed; LED_out <= "01"; end if; when opened => if key_1 = '1' then next_state <= locked; LED_out <= "10"; else next_state <= opened; LED_out <= "11"; end if; when locked => if key_2 = '1' then next_state <= unlocked; LED_R <= "000"; else next_state <= locked; LED_R <= "001"; end if; when unlocked => if key_3 = '1' then next_state <= unlocked; LED_R <= "010"; else next_state <= error; LED_R <= "110"; end if; when error => if key_3 = '1' and key_0 = '1' then next_state <= error; LED_R <= "101"; else next_state <= opened; LED_R <= "111"; end if; --when others => --next_state <= error; end case; end process; end final_syn; -------------------------------------------------------------------------- Error message reads: Warning (10631): inferring latch(es) for signal or variable "LED_out", which holds its previous value in one or more paths through the process Warning (10631): inferring latch(es) for signal or variable "LED_R", which holds its previous value in one or more paths through the process ____--------------------------- Thanks for helping out