4-Finite State Machines ED 20 21
4-Finite State Machines ED 20 21
http://www. dte.uc3m.es
http://www. dte.uc3m.es
http://www. dte.uc3m.es
State Register
BEGIN
IF reset = ‘1’ THEN next_state <= si & state (3 DOWNTO 1);
q <= “0000”;
ELSIF clk’EVENT AND clk = ‘1’ THEN
IF enable = ‘1’ THEN
state <= next_state; Or using 2 processes.
END IF; It’s equivalent.
END IF;
END PROCESS;
http://www. dte.uc3m.es
State Next
state
State
(flip-flops)
Clk
State transition graph
PROCESS (reset, clk)
BEGIN
IF reset = ‘1’ THEN
state <= “0000”;
ELSIF clk’EVENT AND clk = ‘1’ THEN Using only 1 process
IF enable = ‘1’ THEN
state <= state + 1;
END IF;
END IF;
END PROCESS;
http://www. dte.uc3m.es
BEGIN
next_state <= state + 1;
IF reset = ‘1’ THEN
state <= “0000”;
ELSIF clk’EVENT AND clk = ‘1’ THEN
IF enable = ‘1’ THEN Or using 2 processes.
state <= next_state;
END IF;
It’s equivalent.
END IF;
END PROCESS;
http://www. dte.uc3m.es
Next
State
state
State
(flip-flops)
Clk
⚫ Mealy: The outputs depend both on the inputs and the state.
http://www. dte.uc3m.es
http://www. dte.uc3m.es
Inputs
Output Functions Outputs
(COMB)
http://www. dte.uc3m.es
http://www. dte.uc3m.es
http://www. dte.uc3m.es
State
State
functions
(SEQ)
(COMB)
http://www. dte.uc3m.es
State 1
State 3
Input 2 /
Output 2
http://www. dte.uc3m.es
X Z
Clk
Reset
http://www. dte.uc3m.es
1/0 S1
0/0 S11
1/1
http://www. dte.uc3m.es
0 1
S0/0 S1/0
0
0 1
0
S3/1 S2/0
1
1
http://www. dte.uc3m.es
http://www. dte.uc3m.es
‘0’ ‘0’
‘1’ ‘1’
s0 / ‘0’ s1 / ‘0’ s11 / ‘1’
‘1’
‘0’
ENTITY fsm is
PORT( clk: in std_logic;
reset: in std_logic;
a: in std_logic;
z: out std_logic);
END fsm;
http://www. dte.uc3m.es
http://www. dte.uc3m.es
‘0’ / ‘0’
‘0’ / ‘0’
‘1’ / ‘0’
S0 S1
‘1’ / ’1’
ENTITY fsm is
PORT( clk: in std_logic;
reset: in std_logic;
a: in std_logic;
z: out std_logic);
END fsm;
http://www. dte.uc3m.es
http://www. dte.uc3m.es