---------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 12/05/2016 11:01:39 AM -- Design Name: -- Module Name: statemachine - Behavioral -- Project Name: -- Target Devices: -- Tool Versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity statemachine is Port ( Clk : in STD_LOGIC; reset : in STD_LOGIC; start : in STD_LOGIC; guess : in STD_LOGIC; equal : in STD_LOGIC; timeout : in STD_LOGIC; state : out STD_LOGIC_VECTOR (2 downto 0)); end statemachine; architecture Behavioral of statemachine is type state_type is (A, B, C, D, E); attribute ENUM_ENCODING: STRING; attribute ENUM_ENCODING of state_type: type is "000 001 011 101 100"; signal PS, NS : state_type; begin sync : process (Clk, NS, reset) is begin if (reset = '1') then PS <= A; -- if reset then go to start state elsif (rising_edge(Clk)) then PS <= NS; end if; end process sync; states : process (PS, start, guess, equal, timeout) is --variable countscore : unsigned (7 downto 0) := X"00"; begin case PS is when A => -- Start state state <= "000"; if (start = '1') then NS <= B; -- if start is pressed then move to game state else NS <= A; end if; when B => -- game state state <= "001"; if (guess = '1' and timeout = '0') then NS <= C; -- if guess pressed go to the check state elsif (timeout = '1') then NS <= E; -- if time is out move to the end state else NS <= B; end if; when C => -- check state state <= "011"; if (equal = '1') then NS <= D; -- if it is equal then go to the score state else NS <= B; -- not equal than go back to the score state end if; when D => -- score state state <= "101"; NS <= B; -- next state is always the game state when E => -- end state state <= "100"; NS <= E; -- stay in the end state until reset is pressed end case; end process states; end Behavioral;