Docsity

Notes for Finite State Machines | Computer Engineering | ECE 2030, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Notes for Finite State Machines | Computer Engineering | ECE 2030 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

INTRO. TO COMP. ENG.

CHAPTER VIII-

FINITE STATE MACHINES

•CHAPTER VIII

CHAPTER VIII

FINITE STATE MACHINES (FSM)

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE MACHINES

INTRODUCTION

FINITE STATE MACHINES

- STATE MACHINES

-INTRODUCTION

From the previous chapter we can make simple memory elements.•

Latches as well as latches with control signals

Flip-flops

Registers

The goal now is to use the memory elements to hold the running state ofthe machine.•

The state of the machine can be used to perform sequential operations.

This chapter will discuss how to represent the state of the machine fordesign and communication purposes.

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE MACHINES

SYNC. & ASYNC. SYSTEMS

FINITE STATE MACHINES

- STATE MACHINES

-INTRODUCTION-MEALY & MOORE MACH.

Synchronous sequential system •

Behaviour depends on the inputs and outputs at discrete instants of time.

Flip-flops, registers, and latches that are enabled/controlled with a signalderived from clock form a synchronous sequential system.

Asynchronous sequential system •

Behaviour depends on inputs at any instant of time.

Latches without control signals behave in an asynchronous manner.

The state machines discussed in this chapter will be synchronoussequential systems (i.e. controlled by a clock) •

This allows us to form timed Boolean functions such as

where

is the next state of a D flip-flop

N

t ( )

D

A

t

N

D

A

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE DIAGRAMS

ELEMENTS OF DIAGRAMS

FINITE STATE MACHINES

- STATE MACHINES

-INTRODUCTION-MEALY & MOORE MACH.-SYNC. & ASYNC SYSTEMS

A state diagram represents a finite state machine (FSM) and contains •

Circles

: represent the machine states

Labelled with a binary encoded number or

reflecting state.

Directed arcs

: represent the transitions between states

Labelled with input/output for that state transition.

S

k

S

k

S

j

State

Input/Output

a/

p

b/

q

x t

a b

Input:

z t

p q

Output:

s t

S

k

S

j

State:

s 0

S

k

Initial state:

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE DIAGRAMS

STATE DIAGRAM EXAMPLES

FINITE STATE MACHINES

- STATE MACHINES - STATE DIAGRAMS

-ELEMENTS OF DIAGRAMS-PROPERTIES

The following is a simple example. What does this state machine do?

Here is a simplified way of forming the above state machine. •

S An input of 0 or 1 causes the transition with output 1 and 0, respectively.

0

S

1

x t

Input:

z t

Output:

s t

S

0

S

1

State:

s 0

S

0

Initial state:

S

0

S

1

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE DIAGRAMS

BIT FLIPPER EXAMPLE

FINITE STATE MACHINES

- STATE DIAGRAMS

-ELEMENTS OF DIAGRAMS-PROPERTIES-STATE DIAGRAM EX.

Consider the simple bit flipper looked at the in previous chapter. Howwould a state diagram be formed? •

Below is one possible way of drawing the state diagram for the bit flipper.

Since the bit flipper is a Moore machine, the state diagram can also be

S

0

S

1

S

0

S

1

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE DIAGRAMS

PATTERN DETECT EXAMPLE

FINITE STATE MACHINES

- STATE DIAGRAMS

-STATE DIAGRAM EX.-BIT FLIPPER EX.-PATTERN DETECT EX.

The following state diagram gives the behaviour of the desired 1101 patterndetector. •

Consider

to be the initial state,

when first symbol detected (

when subpattern

detected, and

when subpattern

detected.

S

0

S

1

S

2

S

3

S

0

S

1

S

2

S

3

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE TABLES

INTRODUCTION

FINITE STATE MACHINES

- STATE DIAGRAMS

-STATE DIAGRAM EX.-BIT FLIPPER EX.-PATTERN DETECT EX.

State tables also express a systems behaviour and consists of •

Present state

The present state of the system, typically given in binary encodedform or with

. So, a state of

in our state diagram with 10

states would be represented as 0101 since we require 4 bits.

Inputs

Whatever external inputs used to cause the state transitions.

Next state

The next state, generally in binary encoded form.

Outputs

Whatever outputs, other then the state, for the system. Note thatthere would be no outputs in a Moore machine.

S

k

S

5

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE TABLES

TRANSLATE FROM DIAGRAM

FINITE STATE MACHINES

- STATE DIAGRAMS - STATE TABLES

-INTRODUCTION-BIT FLIPPER EX.

From a state diagram, a state table is fairly easy to obtain. •

Determine the number of states in the state diagram.

If there are

states and

1-bit inputs, then there will be

rows in

the state table.

Example: If there are 3 states and 2 1-bit inputs, each state willhave

possible inputs, for a total of 3*4=12 rows.

Write out for each state, the

possible input rows.

For each state/input pair, follow the directed arc in the state diagram todetermine the next state and the output.

m

n

m

n

(^2)

n

INTRO. TO COMP. ENG.

CHAPTER VIII-

STATE TABLES

PATTERN DETECT EXAMPLE

FINITE STATE MACHINES

- STATE TABLES

-INTRODUCTION-BIT FLIPPER EX.-TRANSLATE DIAGRAM

If we consider the pattern detection example previously discussed, thefollowing would be the state table.

Present State

Next State

Input

Output

S

0

or

P

1

P

0

X

Z

S

0

or

S

1

or

S

1

or

S

2

or

S

2

or

S

3

or

S

3

or

S

0

or

S

1

or

S

0

or

S

2

or

S

3

or

S

2

or

S

0

or

S

1

or

N

1

N

0

INTRO. TO COMP. ENG.

CHAPTER VIII-

SEQ. CIRCUITS

INTRODUCTION

FINITE STATE MACHINES

- STATE TABLES

-TRANSLATE DIAGRAM-PATTERN DETECT EX.-TRANSLATE TO DIAGRAM

With the descriptions of a FSM as a state diagram and a state table, thenext question is how to develop a sequential circuit, or logic diagram fromthe FSM.

Effectively, we wish to form a circuit as follows.

Inputs

Combinational

Network

State

Outputs

(Mealy machine)

Outputs

(Moore machine)

φ

1

φ

2

FF

φ

1

φ

2

FF

Present State

Next State

INTRO. TO COMP. ENG.

CHAPTER VIII-

SEQ. CIRCUITS^ FROM STATE TABLE

FINITE STATE MACHINES

- STATE TABLES - SEQUENTIAL CIRCUITS

-INTRODUCTION

The procedure for developing a logic circuit from a state table is the sameas with a regular truth table. •

Generate Boolean functions for

each external outputs using external inputs and present state bits

each next state bit using external inputs and present state bits

Use Boolean algebra, Karnaugh maps, etc. as normal to simplify.

Draw a register for each state bit.

Draw logic diagram components connecting external outputs to externalinputs and outputs of state bit registers (which have the present state).

Draw logic diagram components connecting inputs of state bits (for nextstate) to the external inputs and outputs of state bit registers (which havethe present state).

INTRO. TO COMP. ENG.

CHAPTER VIII-

SEQ. CIRCUITS

PATTERN DETECT EXAMPLE

FINITE STATE MACHINES

- SEQUENTIAL CIRCUITS

-INTRODUCTION-DEVEL. LOGIC CIRCUITS-PATTERN DETECT EX.

Notice that the previous Boolean functions can also be expressed with timeas follows.

An important thing to note in these equations is the relation between thepresent states P and the next states N.

N

1

t ( )

P

1

t

X

t ( )

P

1

t ( )

X

t ( )

P

1

t ( )

P

0

t ( )

N

0

t ( )

P

0

t

X

t ( )

P

1

t ( )

P

0

t ( )

X

t ( )

P

1

t ( )

P

0

t ( )

X

t ( )

P

1

t ( )

P

0

t ( )

Z

t ( )

X

P

1

t ( )

P

0

t ( )

X

t ( )

P

1

t ( )

P

0

t ( )

X

t ( )

P

1

t ( )

P

0

t ( )

INTRO. TO COMP. ENG.

CHAPTER VIII-

SEQ. CIRCUITS

PATTERN DETECT EXAMPLE

FINITE STATE MACHINES

- SEQUENTIAL CIRCUITS

-INTRODUCTION-DEVEL. LOGIC CIRCUITS-PATTERN DETECT EX.

The following logic circuit implements the pattern detect example.

Z

P

1

φ

1

φ

P 2

0

φ

1

φ

2

X

N

1

N

0