LIBRARY IEEE;
USE IEEE. STD_LOGIC_1164. ALL;
ENTITY twoprocess_fsm IS
PORT ( ip,reset,clk : IN BIT; --DECLARES THE INPUTS
op : OUT BIT ); --DECLARES THE OUTPUT
END twoprocess_fsm;
ARCHITECTURE operation_twoprocess_fsm OF twoprocess_fsm IS
TYPE statetype IS (S0, S1 ,S2 ,S3 ,S4 ,S5);--ENUMERATED DATA TYPE
SIGNAL currentstate, nextstate: statetype;
BEGIN
PROCESS(reset,clk) --BEGINING OF PROCESS ONE WITH SENSITIVITY LIST
BEGIN
IF(reset='1') THEN --ON RESET STATE BECOMES S0
currentstate<= S0;
ELSIF(clk'event and clk='1') THEN --ON CLK EVENT STATE IS LOADED
currentstate <= nextstate;
END IF;
END PROCESS;
PROCESS(ip,currentstate,nextstate) --BEGINING OF PROCESS TWO WITH SENSITIVITY LIST
BEGIN
CASE currentstate IS --CASE CHECKS FOR VARIOUS CONDITIONS DEPENDING ON THE STATES
WHEN S0 =>
IF(ip='1') THEN
nextstate <= S1;
ELSE
nextstate <= S0;
END IF;
WHEN S1 =>
IF(ip='0') THEN
nextstate <= S2;
ELSE
nextstate <= S1;
END IF;
WHEN S2 =>
IF(ip='0') THEN
nextstate <= S3;
ELSE
nextstate <= S1;
END IF;
WHEN S3 =>
IF(ip='1') THEN
nextstate <= S4;
ELSE
nextstate <= S0;
END IF;
WHEN S4 =>
IF(ip='1') THEN
nextstate <= S5;
ELSE
nextstate <= S2;
END IF;
WHEN S5 =>
IF(ip='1') THEN
nextstate <= S1;
ELSE
nextstate <= S2;
END IF;
END CASE; --END CASE
END PROCESS;
--USE OF WITH SELECT TO GIVE OUPUT BASED ON STATE CONDITION
WITH nextstate SELECT
op <= '0' WHEN S0,
'0' WHEN S1,
'0' WHEN S2,
'0' WHEN S3,
'0' WHEN S4,
'1' WHEN S5,
'0' WHEN OTHERS;
END operation_twoprocess_fsm;