1 chapter 2 introduction to finite state machines presented by: cecilia parng class: c.s. 147 prof:...

30
1 Chapter 2 Chapter 2 Introduction To Finite Introduction To Finite State Machines State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

Upload: quentin-glenn

Post on 05-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

1

Chapter 2Chapter 2Introduction To Finite State Introduction To Finite State

MachinesMachines

Chapter 2Chapter 2Introduction To Finite State Introduction To Finite State

MachinesMachines

Presented By: Cecilia Parng

Class: C.S. 147

Prof: Sin-Min Lee

Page 2: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

2

Topics To CoverTopics To Cover

2.1 State Diagrams And State Tables

2.2 Mealy And Moore Machines

2.3 Designing State Diagrams

Page 3: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

3

State TableState TableState TableState Table

Present state

Inputs Next State Outputs

A state table is similar to the truth tablepresent stateall inputsnext state all outputs .

Page 4: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

4

Important Rule for State Table

Complete state table must include each possible combination of present states and input values, and no such combination may match more than one row of the table

Page 5: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

5

State DiagramsState Diagrams

A state diagram:Each state is represented by a circled vertex

Each row of the state table is shown as directed arc

J’

Y

Page 6: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

6

Important Rule for State Diagram

State diagram has same situation as state table. Their conditions should be mutually exclusive, no input values should meet the condition of more than one arc.

Page 7: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

7

The Alarm Clock The Alarm Clock

Present state Alarm Weekday Next state Turn off alarm

On X Awake in bed YesAsleep

Awake in bed Off Yes Awake and up No

Awake in bed Off No Asleep No

Page 8: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

8

State Diagram for The Alarm Clock State Diagram for The Alarm Clock (a)(a)

Awake in bedAsleepAlarm’ Alarm

Awake and up

1 (Always)

Alarm

Alarm’ /\ Weekday’ Alarm’ /\ Weekday

Turn off Alarm = Yes

( a )

Page 9: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

9

The alarm clock problem with The alarm clock problem with inactioninaction statesstates

Present state Alarm Weekday Next state Turn off alarm

Asleep Off X Asleep No

Asleep On Awake in bed Yes

Awake in bed On X Awake in bed yes

Awake in bed Off Yes Awake and up No

Awake in bed Off No Asleep No

Awake and up X X Awake and up No

X

Page 10: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

10

State Diagram for The Alarm ClockState Diagram for The Alarm Clock (b)

( b )

Asleep Awake in bed

Awake and up

Alarm’ / 0

Alarm / 1

Alarm’ /\ Weekday’ / 0

1 (Always) / 0

Alarm’ /\ Weekday / 0

Alarm / 1

1 = yes turn off alarm (output)

0 – no turn off alarm (output)

Page 11: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

11

State Tables for The JK Flip-FlopState Tables for The JK Flip-Flop

( a )

Present State

Y

Z

Z

Z

Z

Y

Y

Y

J K

0

0

1

1

0

0

1

1

0

1

0

1

0

1

0

1

Next State Q

Y

Y

Z

Z

Z

Y

Z

Y

0

0

1

1

1

0

1

0

Page 12: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

12

Condition in Terms of J and KCondition in Terms of J and K

Z

J

K

J’ K’

Q=0 Q=1

Y

Page 13: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

13

Mealy and Moore MachinesMealy and Moore Machines

A finite state machine can represent outputs in one of two ways

Moore Machines

Mealy Machines

Page 14: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

14

Moore MachinesMoore Machines

Moore Machines• Associates its outputs with the states.

• Output values depend only on the state and not on the transitions.

• It requires less hardware to produce the output values

• It is well suited for representing the control units of microprocessors and cpu.

Page 15: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

15

State Diagram for The Alarm Clock State Diagram for The Alarm Clock (a)(a)

Awake in bedAsleepAlarm’ Alarm

Awake and up

1 (Always)

Alarm

Alarm’ /\ Weekday’ Alarm’ /\ Weekday

Turn off Alarm = Yes

Moore Machine

Page 16: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

16

Mealy MachinesMealy Machines

Mealy Machines• Associates outputs with the transitions.

• It depends on both its state and its input values

Page 17: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

17

State Diagram for The Alarm ClockState Diagram for The Alarm Clock (b)

Mealy Machine

Asleep Awake in bed

Awake and up

Alarm’ / 0

Alarm / 1

Alarm’ /\ Weekday’ / 0

1 (Always) / 0

Alarm’ /\ Weekday / 0

Alarm / 1

Page 18: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

18

Designing State DiagramsDesigning State Diagrams

Counter

String Checker

Toll Booth

Page 19: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

19

Modulo 6 CounterModulo 6 Counter

A modulo 6 counter is a 3-bit counter that counts through the sequence.

000 001 010 011 100 101 000…

0 1 2 3 4 5 0 …

Unlike a regular 3-bit counter

110(6) and 111(7) do not count

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Page 20: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

20

State Table for The Modulo 6 CounterState Table for The Modulo 6 CounterPresent State Next State C V2 V1 V0U

S0

S0

S1

S1

S2

S2

S3

S3

S4

S4

S5

S5

1

0

0

1

0

1

0

1

0

1

0

1

S0

S1

S1

S2

S2

S3

S3

S4

S4

S5

S5

S0

1

0

0

0

0

0

0

0

0

0

0

1

0 0 0

0 0 1

0 0 1

0 1 0

0 1 0

0 1 1

0 1 1

1 0 0

1 0 1

1 0 1

0 0 0

1 0 0

Page 21: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

21

State Diagram for The Modulo 6 State Diagram for The Modulo 6 Counter (Mealy)Counter (Mealy)

S0

S5

S1

S4

S2

S3

0 / 1000 0 / 0001 0 / 0010

1 / 0001 1 / 0010

1 / 0011

0 / 0011

1 / 0100

0 / 0100

1 / 0101

0 / 0101

1 / 1000

( a ) Mealy

Page 22: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

22

State Diagram for The Modulo 6 State Diagram for The Modulo 6 Counter (Moore)Counter (Moore)

S5

S0 S1

S4

S2

S3

U’

U’

U’

U’

U’

U’

C=1

V =000

U

C=0

V=0010

U

C=0

V=010

U

C=0

V=011

U

C=0

V=100

U

C=0

V=101

( b ) Moore

Page 23: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

23

String CheckerString Checker

A String Checker inputs a string of

bits, one bits per clock cycle.

It checks bits 1,2, and 2, then 2,3,and 4 and so forever

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Page 24: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

24

State Table For String CheckerState Table For String CheckerPresent State

S0

S0

S1S1

S2

S2

S3

S3

S4

S4

S5

S5

S6

S6

S7

S7

0

1

0

1

0

1

0

1

0

1

0

1

0

1

0

1

L Next State

S0

S1

S2

S3

S4

S5

S6

S7

S0

S1

S2

S3

S4

S5

S6

S7

M

0

0

0

0

0

0

1

0

0

0

0

0

0

0

1

0

Page 25: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

25

State Diagrams for the String Checker State Diagrams for the String Checker ( Mealy)( Mealy)

S3

S7 S0

S1

S4S6S5

S2

0/0

0/0

0/01/0

1/00/0

0/0

0/01/0

1/0

0/10/1

0/1

1/01/0

1/0

Mealy

Page 26: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

26

State Diagrams for the String State Diagrams for the String Checker (Moore)Checker (Moore)

S7 S0

S6 S5 S4

S3 S2 S1

M=1

I’M=0

I’

I’

M=0I

M=0

IM=0

I

M=0

I

I’

I’

I

I I I’I’ I

I’M=0

M=0

Moore

Page 27: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

27

Toll Booth ControllerToll Booth Controller

A toll booth controller has two external sensors.

Indicates a car is at the toll booth

Indicates a coin has been deposited in the toll booth’s collection basket and its value

Page 28: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

28

States for the toll booth controllerStates for the toll booth controller

State Condition

SNOCAR

S0

S5

S10

S15

S20

S25

S30

Spaid

Scheat

No car in toll booth

Car in toll booth, 0 cents paid

Car in toll booth, 5 cents paid

Car in toll booth, 10 cents paid

Car in toll booth, 15 cents paid

Car in toll booth, 20 cents paid

Car in toll booth, 25 cents paid

Car in toll booth, 30 cents paid

Car in toll booth, full toll paid

Car left toll booth without paying full toll

1 0 0

1 0 0

1 0 0

1 0 0

1 0 0

1 0 0

1 0 0

1 0 0

0 1 0

1 0 1

R G A

R Red light

G Green light

A Alarm

C = 1 Car enters the toll booth

C = 0 No car arrives

I1I0 = 00 no coin has been deposited

I1I0 = 01 nickel has been deposited

I1I0 = 10 dime has been deposited

I1I0 = 11 quarter has been deposited

Page 29: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

29

**********

The EndThe End

Page 30: 1 Chapter 2 Introduction To Finite State Machines Presented By: Cecilia Parng Class: C.S. 147 Prof: Sin-Min Lee

30

Happy Holidays