Lecture 8: Sequential Networks and Finite State Machines CSE 140: - - PowerPoint PPT Presentation

lecture 8 sequential networks and finite state machines
SMART_READER_LITE
LIVE PREVIEW

Lecture 8: Sequential Networks and Finite State Machines CSE 140: - - PowerPoint PPT Presentation

Lecture 8: Sequential Networks and Finite State Machines CSE 140: Components and Design Techniques for Digital Systems Spring 2014 CK Cheng, Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego 1


slide-1
SLIDE 1

Lecture 8: Sequential Networks and Finite State Machines

CSE 140: Components and Design Techniques for Digital Systems Spring 2014

CK Cheng, Diba Mirza

  • Dept. of Computer Science and Engineering

University of California, San Diego

1

slide-2
SLIDE 2

2

Combinational

CLK CLK A B C D

Sequential Networks

  • 1. Components F-Fs
  • 2. Specification
  • 3. Implementation: Excitation Table

S(t) X Y CLK

slide-3
SLIDE 3

3

Specification

  • Combinational Logic

– Truth Table – Boolean Expression – Logic Diagram (No feedback loops)

  • Sequential Networks: State Diagram

(Memory)

– State Table and Excitation Table – Characteristic Expression – Logic Diagram (FFs and feedback loops)

slide-4
SLIDE 4

4

Specification: Finite State Machine

  • Input Output Relation
  • State Diagram (Transition of States)
  • State Table
  • Excitation Table (Truth table of FF inputs)
  • Boolean Expression
  • Logic Diagram
slide-5
SLIDE 5

Specification: Examples

  • Transition from circuit to finite state

machine representation

– Netlist => State Table => State Diagram => Input Output Relation

  • Example 1: a circuit with D Flip Flops
  • Example 2: a circuit with other Flip Flops

5

slide-6
SLIDE 6

6

Building Sequential Circuits and describing their behavior

slide-7
SLIDE 7

What we will learn:

7

  • 1. Given a sequential circuit, describe its behavior over time
  • 2. Given the behavior of a sequential circuit, implement the circuit

Sequential Circuit: Wall-E How does Wall-E behave?

slide-8
SLIDE 8

What does it mean to describe the behavior of a sequential circuit

8

Specify how the output of the circuit changes as a function of inputs and the state of the circuit

slide-9
SLIDE 9

9

PI Q: What is the difference between the state of a circuit and its output?

  • A. The output is independent of the state
  • B. The output and state are the same thing
  • C. The state is special type of output that is fed

back into the circuit

  • D. The state is input information that is

independent of previous outputs

slide-10
SLIDE 10

State: What is it? Why do we need it?

10

Free running 2 bit Counter Symbol/ Circuit Behavior over time time

CLK Q0 Q1

What is the expected output of the counter over time?

slide-11
SLIDE 11

State: What is it ? Why do we need it?

11

Symbol/ Circuit Behavior over time time

CLK

2 bit Counter PI Q: At time t1, what information is needed to produce the output of the counter at the next rising edge of the clock (i.e t2)?

  • A. All the outputs of the counter until t1
  • B. The initial output of the counter at time t=0
  • C. The output of the counter at current time t1
  • D. We cannot determine the output of the counter at t2 prior to t2

t1 t2

slide-12
SLIDE 12

State: What is it ? Why do we need it?

12

  • The state is distilled output information that tells us everything we

need to know to produce the next output. That is why it is fed back into the circuit.

  • In the case of the 2-bit counter the output (i.e. the current count) is

also the state of the counter. But we could have had other outputs that were not part of the state. E.g. A signal that indicated whether the current count is greater than 2.

slide-13
SLIDE 13

Finite State Machines: Describing circuit behavior over time

13

2 bit Counter Symbol/ Circuit Diagram that depicts behavior over time

slide-14
SLIDE 14

State Diagrams: Describing circuit behavior over time

14

State diagram of the 2 bit counter S0 S1 S2 S3 PI Q: What information is not explicitly indicated in the state diagram?

  • A. The input to the circuit
  • B. The output of the circuit
  • C. The time when state transitions
  • ccur
  • D. The current state of the circuit.
  • E. The next state of the circuit.

Finite State Machine

slide-15
SLIDE 15

Implementing the 2 bit counter

15

00 01 10 11

State Diagram State Table

Q1(t) Q0(t) Q1(t+1) Q0(t+1) 1 1 1 1 1 1 1 1

slide-16
SLIDE 16

Implementing the 2 bit counter

16

State Table

Q1(t) Q0(t) Q1(t+1) Q0(t+1) 1 1 1 1 1 1 1 1

PI Q: To obtain the outputs Q0(t+1) and Q1(t+1) from the inputs Q1(t) and Q0(t) we need to use:

  • A. Combinational logic
  • B. Some other logic
slide-17
SLIDE 17

Implementing the 2 bit counter

17

State Table

Q1(t) Q0(t) Q1(t+1) Q0(t+1) 1 1 1 1 1 1 1 1

Q0(t) Q1(t) Q0(t+1) Q1(t+1) PI Q: What is wrong with the 2-bit counter implementation shown above

  • A. The combinational circuit is incorrect
  • B. The circuit state changes correctly but continuously rather than at the rising

edge of the clock signal

  • C. The output of the circuit is unreliable because inputs can get corrupted
slide-18
SLIDE 18

Implementing the 2 bit counter

18

State Table

Q1(t) Q0(t) Q1(t+1) Q0(t+1) 1 1 1 1 1 1 1 1

We store the current state using D-flip flops so that:

  • The inputs to the combinational circuit don’t change while the

next output is being computed

  • The transition to the next state only occurs at the rising edge of the

clock

Q0(t) Q1(t)

D Q Q’ D Q Q’

CLK Implementation of 2-bit counter

slide-19
SLIDE 19

19

Generalized Model of Sequential Circuits

  • 1. Components F-Fs
  • 2. Specification
  • 3. Implementation: State Table/ Excitation Table

S(t) X Y CLK

slide-20
SLIDE 20

Modified 2 bit counter

20

Q0(t) Q1(t)

D Q Q’ D Q Q’

CLK

x(t) Q0(t) Q1(t)

y(t)

slide-21
SLIDE 21

Modified 2 bit counter

21

Q0(t) Q1(t)

D Q Q’ D Q Q’

CLK

x(t) Q0(t) Q1(t)

y(t) Characteristic Expression: y(t) = Q0(t+1) = Q1(t+1) =

slide-22
SLIDE 22

Modified 2 bit counter

22

Q0(t) Q1(t)

D Q Q’ D Q Q’

CLK

x(t) Q0(t) Q1(t)

y(t) Characteristic Expression: y(t) = Q1(t)Q0(t) Q0(t+1) = D0(t) = x(t)’ Q0(t)’ Q1(t+1) = D1(t) = x(t)’(Q0(t) + Q1(t))

slide-23
SLIDE 23

23

State table

0 0 0 1 1 0 1 1

PS

input

x=0 x=1

Q1(t) Q0(t) | (Q1(t+1) Q0(t+1), y(t)) Present State | Next State, Output

S0 S1 S2 S3

PS

input

x=0 x=1

Netlist ó State Table ó State Diagram ó Input Output Relation

State Assignment

Characteristic Expression: y(t) = Q1(t)Q0(t) Q0(t+1) = D0(t) = x(t)’ Q0(t)’ Q1(t+1) = D1(t) = x(t)’(Q0(t) + Q1(t))

slide-24
SLIDE 24

24

State table

0 0 0 1 1 0 1 1

PS

input

x=0 x=1 01, 0 00, 0 10, 0 00, 0 11, 0 00, 0 00, 1 00, 1

Q1(t) Q0(t) | Q1(t+1) Q0(t+1), y(t) Present State | Next State, Output

S0 S1 S2 S3

PS

input

x=0 x=1

S1, 0 S0, 0 S2, 0 S0, 0 S3, 0 S0, 0 S0, 1 S0, 1

Let: S0 = 00 S1 = 01 S2 = 10 S3 = 11

Remake the state table using symbols instead of binary code , e.g. ’00’ Netlist ó State Table ó State Diagram ó Input Output Relation

State Assignment

y(t) = Q1(t)Q0(t) Q0(t+1) = D0(t) = x(t)’ Q0(t)’ Q1(t+1) = D1(t) = x(t)’(Q0(t) + Q1(t))

slide-25
SLIDE 25

25

Netlist ó State Table ó State Diagram ó Input Output Relation Given inputs and initial state, derive output sequence

S1 S2 S3 S0

Time 1 2 3 4 5 Input 1

  • State

S0 Output

S0 S1 S2 S3

PS

input

x=0 x=1

S1, 0 S0, 0 S2, 0 S0, 0 S3, 0 S0, 0 S0, 1 S0, 1

slide-26
SLIDE 26

26

Netlist ó State Table ó State Diagram ó Input Output Relation Example: Given inputs and initial state, derive

  • utput sequence

x/y

S1 S2 S3 S0

0/0 0/0 0/0 1/0 1/0

Time 1 2 3 4 5 Input 1

  • State

S0 S1 S0 S1 S2 S3 Output 0 1

(0 or 1)/1

S0 S1 S2 S3

PS

input

x=0 x=1

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

slide-27
SLIDE 27

27

y(t) = Q1(t)Q0(t) T0(t) = x(t) Q1(t) T1(t) = x(t) + Q0(t)

X

T Q Q’ T Q Q’

y

Q0 Q1 T0 T1

Example 3 Circuit with T Flip-Flops

slide-28
SLIDE 28

28

Logic Diagram => Excitation Table => State Table

y(t) = Q1(t)Q0(t) T0(t) = x(t) Q1(t) T1(t) = x(t) + Q0(t) Q0(t+1) = T0(t) Q’0(t)+T’0(t)Q0(t) Q1(t+1) = T1(t) Q’1(t)+T’1(t)Q1(t)

id Q1(t) Q0(t) x T1(t) T0(t) Q1(t+1) Q0(t+1) y 1 1 1 1 2 1 1 1 1 3 1 1 1 1 1 4 1 1 5 1 1 1 1 1 6 1 1 1 1 1 7 1 1 1 1 1 1

Excitation Table: Truth table of the F-F inputs

slide-29
SLIDE 29

Excitation Table: iClicker

29

In excitation table, the inputs of the flip flops are used to produce

  • A. The present state
  • B. The next state
slide-30
SLIDE 30

30 id Q1(t) Q0(t) x T1(t) T0(t) Q1(t+1) Q0(t+1) y 1 1 1 1 2 1 1 1 1 3 1 1 1 1 1 4 1 1 5 1 1 1 1 1 6 1 1 1 1 1 7 1 1 1 1 1 1

Excitation Table =>State Table => State Diagram

PS\Input X=0 X=1 S0 S1 S2 S3 State Assignment S0 00 S1 01 S2 10 S3 11

slide-31
SLIDE 31

31 id Q1(t) Q0(t) x T1(t) T0(t) Q1(t+1) Q0(t+1) y 1 1 1 1 2 1 1 1 1 3 1 1 1 1 1 4 1 1 5 1 1 1 1 1 6 1 1 1 1 1 7 1 1 1 1 1 1

Excitation Table =>State Table => State Diagram

S0 S1 S3 S2 PS\Input X=0 X=1 S0 S0,0 S2,0 S1 S3,0 S3,0 S2 S2,0 S1,0 S3 S1,1 S0,1 State Assignment S0 00 S1 01 S2 10 S3 11

slide-32
SLIDE 32

32 id Q1(t) Q0(t) x T1(t) T0(t) Q1(t+1) Q0(t+1) y 1 1 1 1 2 1 1 1 1 3 1 1 1 1 1 4 1 1 5 1 1 1 1 1 6 1 1 1 1 1 7 1 1 1 1 1 1

Excitation Table =>State Table => State Diagram

0/0

S0 S1 S3 S2

0/0 1/1 0/1 0, 1/0 1/0 1/0

PS\Input X=0 X=1 S0 S0,0 S2,0 S1 S3,0 S3,0 S2 S2,0 S1,0 S3 S1,1 S0,1 State Assignment S0 00 S1 01 S2 10 S3 11

slide-33
SLIDE 33

33

Netlist ó State Table ó State Diagram ó Input Output Relation

0/0

S0 S1 S3 S2

0/0 1/1 0/1 0, 1/0 1/0 1/0

PS\Input X=0 X=1 S0 S0,0 S2,0 S1 S3,0 S3,0 S2 S2,0 S1,0 S3 S1,0 S0,1

Time 1 2 3 4 5 Input 1 1 1

  • State

S0 Output

Example: Output sequence

slide-34
SLIDE 34

34

Netlist ó State Table ó State Diagram ó Input Output Relation

0/0

S0 S1 S3 S2

0/0 1/1 0/1 0, 1/0 1/0 1/0

PS\Input X=0 X=1 S0 S0,0 S2,0 S1 S3,0 S3,0 S2 S2,0 S1,0 S3 S1,0 S0,1

Time 1 2 3 4 5 Input 1 1 1

  • State

S0 S0 S2 S1 S3 S0 Output 0 1

Example: Output sequence

slide-35
SLIDE 35

Implementation

35

State Diagram => State Table => Logic Diagram

  • Canonical Form: Mealy and Moore Machines
  • Excitation Table
  • Truth Table of the F-F Inputs
  • Boolean algebra, K-maps for combinational

logic

  • Examples
  • Timing
slide-36
SLIDE 36

36

Canonical Form: Mealy and Moore Machines

Combinational Logic

x(t) y(t) CLK

C2 C1

y(t) CLK x(t)

C1 C2

CLK x(t) y(t)

slide-37
SLIDE 37

37

Mealy Machine: yi(t) = fi(X(t), S(t)) Moore Machine: yi(t) = fi(S(t)) si(t+1) = gi(X(t), S(t)) C1 C2

CLK x(t) y(t)

Mealy Machine C1 C2

CLK x(t) y(t)

Moore Machine

S(t) S(t)

Canonical Form: Mealy and Moore Machines

slide-38
SLIDE 38

38

Implementation: State Diagram => State Table => Netlist

Pattern Recognizer: A sequential machine has a binary input x in {a,b}. For x(t-2, t) = aab, the output y(t) = 1, otherwise y(t) = 0.

S1 S0

a/0 b/0 a/0 b/1

S2

a/0 b/0

slide-39
SLIDE 39

39

State Diagram => State Table with State Assignment

State Assignment S0: 00 S1: 01 S2: 10

PS\x a b S0 S1,0 S0,0 S1 S2,0 S0,0 S2 S2,0 S0,1 PS\x 1 00 01,0 00,0 01 10,0 00,0 10 10,0 00,1

Q1(t+1)Q0(t+1), y a: 0 b: 1

slide-40
SLIDE 40

40

Example 2: State Diagram => State Table => Excitation Table => Netlist PS\x 0 1 00 01,0 00,0 01 10,0 00,0 10 10,0 00,1

id Q1Q0x D1D0 y 000 01 1 001 00 2 010 10 3 011 00 4 100 10 5 101 00 1 6 110

  • 7

111

slide-41
SLIDE 41

41

0 2 6 4 1 3 7 5

x(t) Q1

0 1 - 1 0 0 - 0

Q0

D1(t): D1(t) = x’Q0 + x’Q1 D0 (t)= Q’1Q’0 x’ y= Q1x id Q1Q0x D1D0 y 000 01 1 001 00 2 010 10 3 011 00 4 100 10 5 101 00 1 6 110

  • 7

111

  • Example 2: State Diagram => State Table

=> Excitation Table => Netlist

slide-42
SLIDE 42

42

D Q Q’ D Q Q’

Q1 Q0 D1 D0 Q0 Q1 x’ D1(t) = x’Q0 + x’Q1 D0 (t)= Q’1Q’0 x’ y= Q1x x y Q’1 Q’0 x’ Example 2: State Diagram => State Table => Excitation Table => Netlist

slide-43
SLIDE 43

43

D Q Q’ D Q Q’

Q1 Q0 D1 D0 Q0 Q1 x’ x y Q’1 Q’0 x’

Example 3: State Diagram => State Table => Excitation Table => Netlist S1 S0

a/0 b/0 a/0 b/1

S2

a/0 b/0

iClicker: The relation between the above state diagram and sequential circuit.

  • A. One to one.
  • B. One to many
  • C. Many to one
  • D. Many to many

E. None of the above

slide-44
SLIDE 44

44

Finite State Machine Example

  • Traffic light controller

– Traffic sensors: TA, TB (TRUE when there’s traffic) – Lights: LA, LB

TA LA TA LB TB TB LA LB

Academic Ave. Bravado Blvd. Dorms Fields Dining Hall Labs

slide-45
SLIDE 45

45

FSM Black Box

  • Inputs: CLK, Reset, TA, TB
  • Outputs: LA, LB

TA TB LA LB CLK Reset Traffic Light Controller

slide-46
SLIDE 46

46

FSM State Transition Diagram

  • Moore FSM: outputs labeled in each state
  • States: Circles
  • Transitions: Arcs

S0 LA: green LB: red Reset

slide-47
SLIDE 47

47

FSM State Transition Diagram

  • Moore FSM: outputs labeled in each state
  • States: Circles
  • Transitions: Arcs

S0 LA: green LB: red S1 LA: yellow LB: red S3 LA: red LB: yellow S2 LA: red LB: green TA TA TB TB Reset

slide-48
SLIDE 48

48

FSM State Transition Table

PS Inputs NS TA TB S0 X S1 S0 1 X S0 S1 X X S2 S2 X S3 S2 X 1 S2 S3 X X S0

slide-49
SLIDE 49

49

State Transition Table

PS Inputs NS Q1(t) Q0(t) TA TB Q1(t +1) Q0(t +1) X 1 1 X 1 X X 1 1 X 1 1 1 X 1 1 1 1 X X

State Encoding S0 00 S1 01 S2 10 S3 11

Q1(t+1)= Q1(t)Å Q0(t) Q0(t+1)= Q’1(t)Q’0(t)T’A + Q1(t)Q’0(t)T’B

slide-50
SLIDE 50

50

FSM Output Table

PS Outputs Q1 Q0 LA1 LA0 LB1 LB0 1 1 1 1 1 1 1 1 1 1

Output Encoding green 00 yellow 01 red 10

LA1 = Q1 LA0 = Q’1Q0 LB1 = Q’1 LB0 = Q1Q0

slide-51
SLIDE 51

51

FSM Schematic: State Register

S1 S0 S'1 S'0 CLK

state register

Reset r

slide-52
SLIDE 52

52

Logic Diagram

S1 S0 S'1 S'0 CLK

next state logic state register

Reset TA TB

inputs

S1 S0 r

slide-53
SLIDE 53

53

FSM Schematic: Output Logic

S1 S0 S'1 S'0 CLK

next state logic

  • utput logic

state register

Reset LA1 LB1 LB0 LA0 TA TB

inputs

  • utputs

S1 S0 r