-- fsm_moore_detecta_padrao.vhd -- -- exemplo de máquina de estados -- reconhece o primeiro ZERO após a ocorrência de três ou mais UNS consecutivos -- usando modelo de Moore -- -- PCS3225 - ETM - 2018 library IEEE; use IEEE.std_logic_1164.all; entity fsm_moore_detecta_padrao is port ( CLOCK, ENT: in STD_LOGIC; Z: out STD_LOGIC ); end fsm_moore_detecta_padrao; architecture fsm_moore_detecta_padrao_arch of fsm_moore_detecta_padrao is type Tipo_estado is (A, B,C, D, E); signal Eatual, Eprox: Tipo_estado; begin process (CLOCK) -- memoria de estado begin if CLOCK'event and CLOCK = '1' then Eatual <= Eprox; end if; end process; process (ENT, Eatual) -- logica de proximo estado begin case Eatual is when A => if ENT='0' then Eprox <= A; else Eprox <= B; end if; when B => if ENT='0' then Eprox <= A; else Eprox <= C; end if; when C => if ENT='0' then Eprox <= A; else Eprox <= D; end if; when D => if ENT='0' then Eprox <= E; else Eprox <= D; end if; when E => if ENT='0' then Eprox <= A; else Eprox <= B; end if; when others => Eprox <= A; end case; end process; with Eatual select -- logica de saida (Moore) Z <= '0' when A | B | C | D, '1' when E, '0' when others; end fsm_moore_detecta_padrao_arch;