63
George Mason University Finite State Machines State Diagrams vs. Algorithmic State Machine (ASM) Charts ECE 448 Lecture 6

ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

  • Upload
    others

  • View
    28

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

George Mason University

Finite State Machines

State Diagramsvs.

Algorithmic State Machine (ASM) Charts

ECE 448Lecture 6

Page 2: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

2

Required reading

• P. Chu, FPGA Prototyping by VHDL ExamplesChapter 5, FSM

Page 3: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

3

Recommended reading

• S. Brown and Z. Vranesic,Fundamentals of Digital Logic with VHDL Design

Chapter 8, Synchronous Sequential CircuitsSections 8.1-8.5Section 8.10, Algorithmic State Machine (ASM)

Charts

Page 4: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

4

Datapathvs.

Controller

Page 5: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

5

Structure of a Typical Digital System

Datapath(Execution

Unit)

Controller(Control

Unit)

Data Inputs

Data Outputs

Control & Status Inputs

Control & Status Outputs

Control Signals

StatusSignals

Page 6: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

6

Datapath (Execution Unit)• Manipulates and processes data• Performs arithmetic and logic operations,

shifting/rotating, and other data-processing tasks

• Is composed of registers, multiplexers, adders, decoders, comparators, ALUs, gates, etc.

• Provides all necessary resources and interconnects among them to perform specified task

• Interprets control signals from the Controller and generates status signals for the Controller

Page 7: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

7

Controller (Control Unit)

• Controls data movement in the Datapath by switching multiplexers and enabling or disabling resources

Example: enable signals for registersExample: select signals for muxes

• Provides signals to activate various processing tasks in the Datapath

• Determines the sequence of operations performed by the Datapath

• Follows Some ‘Program’ or Schedule

Page 8: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

8

Finite State Machines• Controllers can be described as Finite State

Machines (FSMs)• Finite State Machines can be represented using

• State Diagrams and State Tables - suitable for simple controllers with a relatively few inputs and outputs

• Algorithmic State Machine (ASM) Charts -suitable for complex controllers with a large number of inputs and outputs

• All of these descriptions can be easily translated to the corresponding synthesizable VHDL code

Page 9: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

9

Hardware Design with RTL VHDLText Description

orPseudocode

Datapath Controller

Blockdiagram

ASMchart

VHDL code VHDL code

Interface

Page 10: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

Steps of the Design Process1. Text description2. Interface3. Pseudocode (optional)4. Block diagram of the Datapath5. Interface divided into the Datapath and Controller 6. State diagram or ASM chart of the Controller7. RTL VHDL code of the Datapath, Controller, and

Top-Level Unit8. Testbench for the Datapath, Controller, and Top-Level

Unit9. Functional simulation and debugging10. Synthesis and post-synthesis simulation11. Implementation and timing simulation12. Experimental testing using FPGA board

Page 11: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

1. Text description2. Interface3. Pseudocode (optional)4. Block diagram of the Datapath5. Interface divided into the Datapath and Controller6. State diagram or ASM chart of the Controller7. RTL VHDL code of the Datapath, Controller, and

Top-level Unit8. Testbench for the Datapath, Controller, and Top-Level

Unit9. Functional simulation and debugging10. Synthesis and post-synthesis simulation11. Implementation and timing simulation12. Experimental testing using FPGA board

Steps of the Design ProcessIntroduced in Class Today

Page 12: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

12

Finite State MachinesRefresher

Page 13: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

13

Finite State Machines (FSMs)• An FSM is used to model a system that transits

among a finite number of internal states. The transitions depend on the current state and external input.

• The main application of an FSM is to act as the controller of a medium to large digital system

• Design of FSMs involves• Defining states• Defining the next-state and output functions• Optimization / minimization

• Manual optimization/minimization is practical for small FSMs only

Page 14: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

14

Moore FSM• output is a function of the state only

stateregister

next-statelogic

outputlogic

input

state_next

output

state_reg

clkreset

Page 15: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

15

Mealy FSM• output is a function of the state and input signals

stateregister

next-statelogic

outputlogic

input

state_next

output

clkreset

state_reg

Page 16: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

16

State Diagrams

Page 17: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

17

Moore Machine

state 1 /output 1

state 2 /output 2

transitioncondition 1

transitioncondition 2

Page 18: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

18

Mealy Machine

state 1 state 2

transition condition 1 /output 1

transition condition 2 /output 2

Page 19: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

19

Moore FSM - Example 1

• Moore FSM that Recognizes Sequence “10”

S0 / 0 S1 / 0 S2 / 1

00

0

1

11

reset

Meaning of states:

S0: No elements of the sequenceobserved

S1: “1”observed

S2: “10”observed

Page 20: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

20

Mealy FSM - Example 1

• Mealy FSM that Recognizes Sequence “10”

S0 S1

0 / 0 1 / 0 1 / 0

0 / 1reset

Meaning of states:

S0: No elements of the sequenceobserved

S1: “1”observed

Page 21: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

21

Algorithmic State Machine (ASM)Charts

Page 22: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

22

Algorithmic State Machine

Algorithmic State Machine –representation of a Finite State Machinesuitable for FSMs with a larger number of inputs and outputs compared to FSMs expressed using state diagrams and state tables.

Page 23: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

23

ASM Chart

– Flowchart-like diagram

– Provides the same info as a state diagram

– More descriptive, better for complex digital systems

Page 24: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

24

ASM describing generalized FSM• Algorithmic state machines can model both

Mealy and Moore Finite State Machines• They can also model generalized machines

that are of the mixed type

Page 25: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

25

Elements used in ASM charts (1)

Output signalsor actions

(Moore type)

State name

Condition expression

0 (False) 1 (True)

Conditional outputs or actions (Mealy type)

(a) State box (b) Decision box

(c) Conditional output box

Page 26: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

26

State Box• State box – represents a state.• Equivalent to a node in a state diagram or

a row in a state table.• Contains register transfer actions or

output signals• Moore-type outputs are listed inside of

the box.• It is customary to write only the name of

the signal that has to be asserted in the given state, e.g., z instead of z<=1.

• Also, it might be useful to write an action to be taken, e.g., count <= count + 1, and only later translate it to asserting a control signal that causes a given action to take place (e.g., enable signal of a counter).

Output signalsor actions

(Moore type)

State name

Page 27: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

27

Decision Box

• Decision box –indicates that a given condition is to be tested and the exit path is to be chosen accordingly.The condition expression may include one or more inputs to the FSM.

Condition expression

0 (False) 1 (True)

Page 28: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

28

Conditional Output Box• Conditional output

box• Denotes output

signals that are of the Mealy type.

• The condition that determines whether such outputs are generated is specified in the preceding decision box.

Conditional outputs or actions (Mealy type)

Page 29: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

29

Simple Example• BTND – reset controller• BTNC – start counting from 0 to k-1After the Counter reaches k-1, Done=1, LED LD0 on

• BTNU – resume the operationDone=0, LED LD0 off

The current value of the counter should be displayed in the hexadecimal notation using four seven-segment displays available on the board.

After reset: Counter = 0x0000

Page 30: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

DATAPATH CONTROLLER

BTNS BTNU BTND

clk

7 4

SEG AN

zi

ldi

INPUT_INTERFACE

BTNSp Contp Rstp

hex_out

OUTPUT_INTERFACE

16

clkrst

eni

BTNC

Startp

Done

LED

i

30

Page 31: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

31

Simple Example: Datapath

eniclk

== k-1

zi

16

i

en ldild

16

0

Page 32: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

32

Simple Example: ASM ChartsRstp

Startp0

i==k-1F

T

S_DONE

Contp0

1

DONE

S_WAIT

S_COUNT

1

i++

i=0

Rstp

Startp0

zi0

1

S_DONE

Contp0

1

DONE

S_WAIT

S_COUNT

1

eni

ldi, eni

a) with actions and condition expressions b) with control outputs and status inputs

Page 33: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

33

ASM Block

• One state box• One or more

(optional)decision boxes: with T (1) or F (0) exit paths

• One or more (optional)conditional output boxes:for Mealy outputs

Page 34: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

34

ASM Chart Rules

Based on RTL Hardware Design by P. Chu

• Difference between a regular flowchart and an ASM chart:– Transition governed by clock – Transition occurs between ASM blocks

• Basic rules:– For a given input combination, there is one

unique exit path from the current ASM block– Any closed loop in an ASM chart must

include a state box

Page 35: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

35

Incorrect ASM Charts

Based on RTL Hardware Design by P. Chu

Page 36: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

36

Correct ASM Chart

Page 37: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

37

State Diagram of Moore FSM

• Moore FSM that Recognizes Sequence “10”

S0 / 0 S1 / 0 S2 / 1

00

0

1

11

reset

Meaning of states:

S0: No elements of the sequenceobserved

S1: “1”observed

S2: “10”observed

Page 38: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

38

ASM Chart of Moore FSM S0

reset

input

S1

S2

input

input

0

1

0

1

1 0

output

Page 39: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

39

State Diagram of Mealy FSM

• Mealy FSM that Recognizes Sequence “10”

S0 S1

0 / 0 1 / 0 1 / 0

0 / 1reset

Meaning of states:

S0: No elements of the sequenceobserved

S1: “1”observed

Page 40: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

40

ASM Chart of Mealy Machine

S0

S1

reset

input

input

output

0

1

1 0

Page 41: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

41

Finite State Machinesin VHDL

Page 42: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

42

Recommended FSM Coding Style

Based on RTL Hardware Design by P. Chu

Process(clk, reset)

Process(state_reg, input)

Page 43: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

43

ASM Chart of Moore Machine S0

reset

input

S1

S2

input

input

0

1

0

1

1 0

output

Page 44: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

44

Moore FSM in VHDL (1)

LIBRARY ieee;USE ieee.std_logic_1164.all;

ENTITY FSM_Moore ISPORT ( clk : IN STD_LOGIC ;

reset : IN STD_LOGIC ;input : IN STD_LOGIC ;

output : OUT STD_LOGIC) ;END FSM_Moore ;

Page 45: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

45

Moore FSM in VHDL (1)

ARCHITECTURE behavioral of FSM_Moore ISTYPE state IS (S0, S1, S2);SIGNAL state_reg, state_next: state;

BEGIN

U_Moore: PROCESS (clk, reset)BEGIN

IF(reset = '1') THENstate_reg <= S0;

ELSIF rising_edge(clk) THENstate_reg <= state_next;

END IF;END PROCESS;

Page 46: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

46

Moore FSM in VHDL (2)Next_State_Output: PROCESS (state_reg, input)BEGIN

state_next <= state_reg;output <= '0';CASE state_reg IS

WHEN S0 =>IF input = '1' THEN

state_next <= S1; ELSE

state_next <= S0;END IF;

Page 47: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

47

Moore FSM in VHDL (3)WHEN S1 =>

IF input = '0' THEN state_next <= S2;

ELSEstate_next <= S1;

END IF;WHEN S2 =>

output <= '1' ;IF input = '1' THEN

state_next <= S1; ELSE

state_next <= S0; END IF;

END CASE;END PROCESS;

END behavioral;

Page 48: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

48

ASM Chart of Mealy Machine

S0

S1

reset

input

input

output

0

1

1 0

Page 49: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

49

Mealy FSM in VHDL (1)

LIBRARY ieee;USE ieee.std_logic_1164.all;

ENTITY FSM_Mealy ISPORT ( clk : IN STD_LOGIC ;

reset : IN STD_LOGIC ;input : IN STD_LOGIC ;output : OUT STD_LOGIC) ;

END FSM_Mealy ;

Page 50: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

50

Mealy FSM in VHDL (1)ARCHITECTURE behavioral of FSM_Mealy ISTYPE state IS (S0, S1);SIGNAL state_reg, state_next: state;

BEGINU_Mealy: PROCESS(clk, reset)BEGIN

IF(reset = '1') THENstate_reg <= S0;

ELSIF rising_edge(clk) THENstate_reg <= state_next;

END IF;END PROCESS;

Page 51: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

51

Mealy FSM in VHDL (2)Next_State_Output: PROCESS (state_reg, input)BEGIN

state_next <= state_reg;output <= '0';CASE state_reg IS

WHEN S0 =>IF input = '1' THEN

state_next <= S1; ELSE

state_next <= S0;END IF;

Page 52: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

52

Mealy FSM in VHDL (3)WHEN S1 =>

IF input = '0' THENstate_next <= S0; output <= '1' ;

ELSEstate_next <= S1;

END IF;END CASE;

END PROCESS;

END behavioral;

Page 53: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

53

ASM Chart of Moore Machine S0

reset

input

S1

S2

input

input

0

1

0

1

1 0

output

Page 54: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

54

ASM Chart of Mealy Machine

S0

S1

reset

input

input

output

0

1

1 0

Page 55: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

55

Moore & Mealy FSMs without delays

clk

input

Moore

Mealy

0 1 0 0 0

S0 S0 S1 S2 S0 S0

S0 S0 S1 S0 S0 S0

state

output

state

output

reset

Page 56: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

56

Moore & Mealy FSMs with delays

clk

input0 1 0 0 0

reset

S0 S0 S1 S2 S0 S0

S0 S0 S1 S0 S0 S0

Moore

Mealy

state

output

state

output

Page 57: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

57

Moore vs. Mealy FSM (1)

• Moore and Mealy FSMs Can Be Functionally Equivalent• Equivalent Mealy FSM can be derived from

Moore FSM and vice versa• Mealy FSM Has Richer Description and

Usually Requires Smaller Number of States• Smaller circuit area

Page 58: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

58

Moore vs. Mealy FSM (2)

• Mealy FSM Computes Outputs as soon as Inputs Change• Mealy FSM responds one clock cycle sooner

than equivalent Moore FSM• Moore FSM Has No Combinational Path

Between Inputs and Outputs• Moore FSM is less likely to affect the critical

path of the entire circuit

Page 59: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

59

Moore FSM• output is a function of the state only

stateregister

next-statelogic

outputlogic

input

state_next

output

state_reg

clkreset

Page 60: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

60

Mealy FSM• output is a function of the state and input signals

stateregister

next-statelogic

outputlogic

input

state_next

output

clkreset

state_reg

Page 61: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

61

Which Way to Go?

Safer.Less likely to affect

the critical path.

Mealy FSM Moore FSM

Lower Area

Responds one clockcycle earlier

Fewer states

Page 62: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

62

ASMs representing simple FSMs

• Algorithmic state machines can model both Mealy and Moore Finite State Machines

• They can also model machines that are of the mixed type

Page 63: ECE 448 Lecture 6 · 3 Recommended reading •S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design Chapter 8, Synchronous Sequential Circuits Sections 8.1-8.5

63

Generalized FSM

Based on RTL Hardware Design by P. Chu