0% found this document useful (0 votes)
22 views22 pages

4-Finite State Machines ED 20 21

The document discusses finite state machines and their implementation in VHDL. It provides examples of shift registers and counters to illustrate finite state machines. It explains the difference between Moore and Mealy state machines, and how they can be represented using state transition graphs.

Uploaded by

Jaime Martinez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views22 pages

4-Finite State Machines ED 20 21

The document discusses finite state machines and their implementation in VHDL. It provides examples of shift registers and counters to illustrate finite state machines. It explains the difference between Moore and Mealy state machines, and how they can be represented using state transition graphs.

Uploaded by

Jaime Martinez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Sequential circuit design

Finite State Machines

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 1


Finite State Machines (FSMs)
⚫ Review of previous examples
• Shift register
• Counter
⚫ General case. FSMs. Definition.
⚫ State transition graphs
• Moore model
• Mealy model
⚫ VHDL description

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 2


Example 1: Shift register
Combinational
Inputs Outputs
circuit.
Order
rearrangement
State Next
state
State
(flip-flops)
Clk

PROCESS (reset, clk)


BEGIN
IF reset = ‘1’ THEN
state <= "0000";
Using only 1 process
ELSIF clk’EVENT AND clk = ‘1’ THEN
state <= si & state (3 DOWNTO 1);
END IF;
END PROCESS;

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 3


Example 1: shift register
Inputs Combinational Outputs
circuit.
Order
rearrangement
State Next
state
State
(flip-flops)
Clk

State Register

PROCESS (reset, clk) Combinational circuit

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

Digital Electronics. Telecommunication Engineering Degrees. 4


Example 2: counter
Inputs Combinational Outputs
circuit.
Adder (+1)

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

Digital Electronics. Telecommunication Engineering Degrees. 5


Example 2: counter
Inputs Outputs
Combinational
circuit.
Adder (+1)
State Next
state
State
(flip-flops)
Clk
State transition graph
State Register

PROCESS (reset, clk) Combinational circuit

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

Digital Electronics. Telecommunication Engineering Degrees. 6


General Case

Synchronous sequential circuits


Inputs Outputs
Combinational
circuit

Next
State
state
State
(flip-flops)
Clk

Finite state Machines


⚫ Moore: The outputs do no depend on the inputs (they are a function of the state)
• Counters and shift registers are examples of Moore FSMs

⚫ Mealy: The outputs depend both on the inputs and the state.

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 7


Finite State Machines
⚫ The behavior of a synchronous circuit can be represented by a
Finite State Machine (FSM)
⚫ A state machine has the following elements:
• X = Inputs
• Y = Outputs
• Z = States (flip-flop values, they change every clock edge)
• δ = State functions (combinational functions, acting as flip-flop inputs)
• λ = Output functions (combinational functions, generating the outputs)

⚫ A state machine can be defined as an event sequence in


discrete time. State (Z) changes with every event. State change
is defined by state functions (δ)

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 8


Moore model
⚫ Outputs are a function of the state (not inputs)
⚫ Moore State Machine:
• Z = δ (X, Z)
• Y = λ (Z)
⚫ Structure of a Moore circuit:

Inputs
Output Functions Outputs
(COMB)

State Functions State


(COMB) (SEQ)

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 9


Moore model
⚫ Clock and Reset do not appear in state machine
representations. Their relation with the state
machine is:
• Every clock edge a state change or transition is produced
• Reset activation makes the state machine to take its initial state

⚫ Moore state machine outputs change only when


there is a state change
• Outputs are synchronized with the clock

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 10


Moore model
⚫ A FSM can be represented using a State Transition
Graph (STG):
• Every state is represented by a node
• Every transition is represented by an arrow
• Input values producing the transition are represented over the
corresponding arrow
• In a Moore model, outputs are represented inside the
corresponding state node

⚫ State Transition Graph (Moore): Input 1 State 2


Output 2
State 1
Output 1
Input 2
State 3
Output 3

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 11


Mealy model
⚫ Outputs are functions of the state and the inputs
⚫ Mealy FSM:
• Z = δ (X, Z)
• Y = λ (X, Z)
⚫ Mealy circuit structure:
Inputs
Output Outputs
functions
(COMB)

State
State
functions
(SEQ)
(COMB)

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 12


Mealy model
⚫ Mealy state transition graph:
• Every state is represented by a node
• Every transition is represented by an arrow
• Input values producing the transition are represented over
the corresponding arrow
• In a Mealy model, outputs are represented over the
corresponding transition arrow
Input 1 /
Output 1
State 2

State 1

State 3
Input 2 /
Output 2

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 13


Mealy model
⚫ Same as Moore model, clock an reset are
not represented in the STG, they are implicit
⚫ In Mealy state machines, outputs can change
anytime. An input change can produce an
output change:
• Outputs are not (necessarily) synchronized with
clock
• Although outputs are not in sync with clock, the
circuit is still synchronous, as every flip-flop is
synchronized with clock
http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 14


Synchronous Sequential Circuits
⚫ Example: design a synchronous sequential circuit to
detect a sequence of three or more consecutive
ones in a serial input.
⚫ Input is read every rising clock edge
⚫ Output activates when the right sequence is detected

X Z

Clk
Reset

⚫ Input-output sample sequence:


⚫ X:001101111100111
⚫ Z:000000011100001

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 15


State Transition Graphs
⚫ Solution: Mealy

1/0 S1

0/0 S0 0/0 1/0

0/0 S11

1/1

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 16


State Transition Graphs
⚫ Solution: Moore

0 1
S0/0 S1/0
0
0 1
0
S3/1 S2/0
1
1

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 17


VHDL: State Machines
⚫ States: declared as enum type
• TYPE estado IS (s0, s1, s11);
• Declare signals for present and next state
⚫ Sequential part:
• Sequential process
• Asynchronous initialization to initial state
• Synchronous state update (present state updated with next
state)
⚫ Combinacional part:
• Generates next state and outputs
• Combinational process depending on state (case).

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 18


VHDL example: Moore machine
⚫ Write VHDL description

‘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

Digital Electronics. Telecommunication Engineering Degrees. 19


VHDL example: Moore machine
ARCHITECTURE moore OF fsm IS PROCESS (state, a)
TYPE state_t IS (s0, s1, s11); BEGIN
SIGNAL state, next_state: state_t; CASE state IS
BEGIN WHEN s0 =>
PROCESS (clk, reset) z <= '0';
BEGIN IF a = '0' THEN
IF reset = '1' THEN next_state <= s0;
state <= s0; ELSE
ELSIF rising_edge(clk) THEN next_state <= s1;
state <= next_state; END IF;
END IF; WHEN s1 =>
END PROCESS; z <= '0';
.... IF a = '0' THEN
next_state <= s1;
ELSE
next_state <= s11;
END IF;
WHEN s11 => ...
z <= ‘1';
....
END CASE;
END PROCESS;
END moore;

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 20


VHDL example: Mealy machine

‘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

Digital Electronics. Telecommunication Engineering Degrees. 21


VHDL example: Mealy machine
ARCHITECTURE mealy OF fsm IS PROCESS (next_state, a)
TYPE state IS (s0, s1); BEGIN
SIGNAL state, next_state: estado; CASE estado_actual IS
BEGIN WHEN s0 =>
PROCESS (clk, reset) z <= '0';
BEGIN IF a = '0' THEN
IF reset = '1' THEN next_state <= s0;
state <= s0; ELSE
ELSIF rising_edge(clk)THEN next_state <= s1;
state <= next_state; END IF;
END IF; WHEN s1 =>
END PROCESS; IF a = '0' THEN
.... z <= '0';
next_state <= s1;
ELSE
z <= '1';
next_state <= s0;
END IF;
END CASE;
END PROCESS;
...

http://www. dte.uc3m.es

Digital Electronics. Telecommunication Engineering Degrees. 22

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy