Sie sind auf Seite 1von 21

Contemporary Logic Design

Finite State Machine Design

Chapter #8: Finite State Machine Design

8.1 - 8.2 Finite State Machine Design

© R.H. Katz Transparency No. 14-1


Contemporary Logic Design
Chapter Overview Finite State Machine Design

Concept of the State Machine

• Partitioning into Datapath and Control

• When Inputs are Sampled and Outputs Asserted

Basic Design Approach

• Six Step Design Process

Alternative State Machine Representations

• State Diagram, ASM Notation, VHDL, ABEL Description Language

Moore and Mealy Machines

• Definitions, Implementation Examples

Word Problems

• Case Studies
© R.H. Katz Transparency No. 14-2
Contemporary Logic Design
Concept of the State Machine Finite State Machine Design

Computer Hardware = Datapath + Control

Qualifiers
Registers FSM generating sequences
Combinational Functional of control signals
Units (e.g., ALU) Instructs datapath what to
Busses do next
Control

Control "Puppeteer who pulls the


strings"
State

Qualifiers Control
and Signal
Inputs Outputs

"Puppet" Datapath

© R.H. Katz Transparency No. 14-3


Contemporary Logic Design
Concept of the State Machine Finite State Machine Design
Example: Odd Parity Checker
Assert output whenever input bit stream has odd # of 1's

Res et Present State Input Next State Output


Even 0 Even 0
0 Even 1 Odd 0
Even
[0]
Odd 0 Odd 1
Odd 1 Even 1
1 1 Symbolic State Transition Table
Odd
[1] Present State Input Next State Output
0
0 0 0 0
0 1 1 0
1 0 1 1
State 1 1 0 1
Diagram
Encoded State Transition Table
===> One FF required because one bit is
needed to represent the two states

© R.H. Katz Transparency No. 14-4


Contemporary Logic Design
Concept of the State Machine Finite State Machine Design
Example: Odd Parity Checker
Using a D-FF Let Q = PS, Q+ = NS, X = Input

Q X Q+ Output D Q+ = D
0 0 0 0 0
0 1 1 0 1
1 0 1 1 1
1 1 0 1 0

D = Q’X + QX’ = Q  X Since we have two states, we can


implement the circuit with one
flip-flop.

NS
X D Q Output
CLK
Q
R
\Reset

D FF Implementation

© R.H. Katz Transparency No. 14-5


Contemporary Logic Design
Concept of the State Machine Finite State Machine Design
Example: Odd Parity Checker
Using a T-FF Let Q = PS, Q+ = NS, X = Input

Q X Q+ Output T Q+ = T  Q
0 0 0 0 0 ==> T = Q+  Q
0 1 1 0 1
1 0 1 1 0
1 1 0 1 1

T=X Since we have two states, we can


implement the circuit with one
flip-flop.

X Output
T Q
CLK
Q
R
\Reset
T FF Implementation
© R.H. Katz Transparency No. 14-6
Contemporary Logic Design
Concept of the State Machine Finite State Machine Design

Input 1 0 0 1 1 0 1 0 1 1 1 0

Clk

Output 1 1 1 0 1 1 0 0 1 0 1 1

Timing Behavior: Input 1 0 0 1 1 0 1 0 1 1 1 0

© R.H. Katz Transparency No. 14-7


Contemporary Logic Design
Concept of State Machine Finite State Machine Design
Timing:
When are inputs sampled, next state computed, outputs asserted?

State Time: Time between clocking events

• Clocking event causes state/outputs to transition, based on inputs

• For set-up/hold time considerations:

Inputs should be stable before clocking event

• After propagation delay, Next State entered, Outputs are stable

NOTE: Asynchronous signals take effect immediately


Synchronous signals take effect at the next clocking event

E.g., tri-state enable: effective immediately


sync. counter clear: effective at next clock event

© R.H. Katz Transparency No. 14-8


Contemporary Logic Design
Concept of State Machine Finite State Machine Design

Example: Positive Edge Triggered Synchronous System

State Time On rising edge, inputs sampled


outputs, next state computed

After propagation delay, outputs and


next state are stable
Cloc k
Immediate Outputs:
affect datapath immediately
Inputs could cause inputs from datapath to change

Delayed Outputs:
take effect on next clock edge
Outputs propagation delays must exceed hold times

© R.H. Katz Transparency No. 14-9


Contemporary Logic Design
Concept of the State Machine Finite State Machine Design
Communicating State Machines
One machine's output is another machine's input

X
CLK
FSM 1 FSM 2
Y
FSM 1 A A B

X
Y=0 X=0
Y=0 X=0
A C FSM 2 C D D
[1] [0]

X=1 Y
Y=1
X=1

B D
Y=0,1 [0] X=0 [1]

Machines advance in lock step

Initial inputs/outputs: X = 0, Y = 0
© R.H. Katz Transparency No. 14-10
Contemporary Logic Design
Basic Design Approach Finite State Machine Design
Six Step Process
1. Understand the statement of the Specification

2. Obtain an abstract specification of the FSM


(I.e. state diagram)

3. Perform a state minimization

4. Perform state assignment

5. Choose FF types to implement FSM state register

6. Implement the FSM

1, 2 covered now; 3, 4, 5 covered later;


4, 5 generalized from the counter design procedure

© R.H. Katz Transparency No. 14-11


Contemporary Logic Design
Basic Design Approach Finite State Machine Design
Example: Vending Machine FSM
General Machine Concept:
deliver package of gum after 15 cents deposited

single coin slot for dimes, nickels

no change

Step 1. Understand the problem:


Draw a picture!

Block Diagram N
Coin Vending Gum
Sensor D Open
Machine Release
Reset FSM Mechanism

Clk

© R.H. Katz Transparency No. 14-12


Contemporary Logic Design
Vending Machine Example Finite State Machine Design

Step 2. Map into more suitable abstract representation

Tabulate typical input sequences:


three nickels -- N,N,N
nickel, dime -- N,D
dime, nickel -- D,N Reset
two dimes -- D,D S0
two nickels, dime -- N,N,D
N D
Draw state diagram:
S1 S2
Inputs: N, D, reset

Output: open D
N D N

S3 S4 S5 S6

[open] [open] [open]


N D

S7 S8
[open] [open]

© R.H. Katz Transparency No. 14-13


Contemporary Logic Design
Vending Machine Example Finite State Machine Design
Step 3: State Minimization
Pres ent Inputs Next Output
Reset

State D N State Open
0¢ 0 0 0¢ 0
Moore 0 1 5¢ 0
N
Machine 1 0 10¢ 0

D 1 1 X X
5¢ 0 0 5¢ 0
N 0 1 10¢ 0
10¢ 1 0 15¢ 0
D 1 1 X X
N, D 10¢ 0 0 10¢ 0
15¢
0 1 15¢ 0
1 0 15¢ 0
[o pen ]
1 1 X X
15¢ X X 15¢ 1
reuse states
whenever Symbolic State Table
possible

© R.H. Katz Transparency No. 14-14


Contemporary Logic Design
Vending Machine Example Finite State Machine Design

Step 4: State Encoding


Present State Inputs Next State Output
Q1 Q0 D N Q1+ =D 1 Q0+ =D Open
0
4 states ==> 0 0 0 0 0 0 0
2 bits needed 0 1 0 1 0
to represent 1 0 1 0 0
1 1 X X X
0 1 0 0 0 1 0
0 1 1 0 0
1 0 1 1 0
1 1 X X X
1 0 0 0 1 0 0
0 1 1 1 0
1 0 1 1 0
1 1 X X X
1 1 0 0 1 1 1
0 1 1 1 1
1 0 1 1 1
1 1 X X X

© R.H. Katz Transparency No. 14-15


Contemporary Logic Design
Vending Machine Example Finite State Machine Design

Step 5. Choose FFs for implementation


D FF easiest to use

Q1 Q0 Q1 Q1 Q0 Q1 Q1 Q0 Q1
DN 00 01 11 10 DN 00 01 11 10 DN 00 01 11 10
00 0 0 1 1 00 0 1 1 0 00 0 0 1 0

01 0 1 1 1 01 1 0 1 1 01 0 0 1 0
N N N
11 X X X X 11 X X X X 11 X X X X
D D D
10 1 1 1 1 10 0 1 1 1 10 0 0 1 0

Q0 Q0 Q0
K-map for D1 K-map for D0 K-map for Open

D1 = Q1 + D + Q0 N

D0 = N Q0 + Q0 N + Q1 N + Q1 D

OPEN = Q1 Q0

© R.H. Katz Transparency No. 14-16


Contemporary Logic Design
Vending Machine Example Finite State Machine Design

Q1
D D1 Q1
D Q
CLK \ Q1
Q0 Q
R
N
\reset
N
\ Q0 OPEN

Q0
\N
D0 Q0
D Q
Q1 CLK \ Q0
N Q
R
Q1 \reset
D

D1 = Q1 + D + Q0 N

D0 = N Q0 + Q0 N + Q1 N + Q1 D

OPEN = Q1 Q0

8 Gates, 2 flip flops

© R.H. Katz Transparency No. 14-17


Contemporary Logic Design
Vending Machine Example Finite State Machine Design

Step 5. Choosing FF for Implementation


J-K FF
Flip Flop Values
Present State Inputs Next State J1 K1 J0 K 0
Q1 Q0 D N Q+ Q+
Q Q+ J K 1 0
0 0 0 X 0 0 0 0 0 0 0 X 0 X
0 1 0 1 0 X 1 X
0 1 1 X
1 0 1 0 1 X 0 X
1 0 X 1 1 1 X X X X X X
1 1 X 0 0 1 0 0 0 1 0 X X 0
0 1 1 0 1 X X 1
1 0 1 1 1 X X 0
1 1 X X X X X X
1 0 0 0 1 0 X 0 0 X
0 1 1 1 X 0 1 X
1 0 1 1 X 0 1 X
1 1 X X X X X X
1 1 0 0 1 1 X 0 X 0
0 1 1 1 X 0 X 0
1 0 1 1 X 0 X 0
1 1 X X X X X X

Remapped encoded state transition table


© R.H. Katz Transparency No. 14-18
Contemporary Logic Design
Vending Machine Example Finite State Machine Design
Implementation:
Q1 Q0 Q1 Q1 Q0 Q1

DN 00 01 11 10 DN 00 01 11 10

00 0 0 X X 00 X X X 0

01 0 1 X X 01 X X X 0
N N J1 = D + Q0 N
11 X X X X 11 X X X X
D D K1 = 0
10 1 1 X X 10 X X X 0

Q0 Q0
K-map for J1 K-map for K1 J0 = Q0 N + Q1 D
Q1 Q0 Q1 Q1 Q0 Q1
DN 00 01 11 10 DN 00 01 11 10 K0 = Q1 N
00 0 X X 0 00 X 0 0 X

01 1 X X 1 01 X 1 0 X
N
N
11 X X X X 11 X X X X
D D
Output OPEN does not
10 0 X X 1 10 X 0 0 X change:
Q0 Q0
OPEN = Q1 Q0
K-map for J0 K-map for K0

© R.H. Katz Transparency No. 14-19


Contemporary Logic Design
Vending Machine Example Finite State Machine Design

N
Q0 J Q Q1
D \ Q1
CLK K RQ
\ Q0

N
OPEN
Q1

D Q0
J Q
\ Q1 CLK
\ Q0
KR Q
N

\reset

7 Gates,
2 flip flops

© R.H. Katz Transparency No. 14-20


Contemporary Logic Design
Finite State Machine Design
HW #14 -- Section 8.1 & 8.2

© R.H. Katz Transparency No. 14-21

Das könnte Ihnen auch gefallen