ece 171 digital circuits chapter 13 flip flops herbert g. mayer, psu status 11/23/2015 copied with...

64
ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Upload: lorena-hall

Post on 19-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

ECE 171Digital Circuits

Chapter 13Flip Flops

Herbert G. Mayer, PSUStatus 11/23/2015

Copied with Permission from prof. Mark Faust @ PSU ECE

Page 2: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Syllabus

Latches Flip Flops. Algorithmic State Machines Characteristic Equations Timing Diagram Races Metastable State References

Page 3: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Possible States for Light Switch

3

Page 4: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

S-R Latch

S R Q+

0 0 Q0 1 01 0 11 1 0

S-R latch is reset dominant

4

Page 5: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Alternative Nomenclature

Present State Next StateOutput Symbol Output Symbol

Q QQ Q(t+1)Qt Q(t+1)Qn Q(n+1)Q0 QY Y+

y Y

5

Page 6: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

S-R Latch States

S-R latch isreset dominant

6

Page 7: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Characteristic Equations

7

Page 8: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Present State/Next State Table(PS/NS)

8

Page 9: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Timing Diagram

9

Page 10: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Races

Critical Race Non-critical Race10

Page 11: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Metastable StateAn often overlooked condition in which the output can remain in an illegal (even oscillating) state for an indeterminant period of time.

Metastability can be caused by a runt pulse (a positive or negative pulse which never achieves either a value of a 1 or 0). This can occur when two inputs to a gate change near simultaneously (see hazards earlier).

Metastability can also occur when two inputs to a latch change near simultaneously.

Condition also arises when synchronizing with external events (e.g. asynchronous inputs to synchronous finite state machines).11

Page 12: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

State Diagrams

S R Q+

0 0 Q0 1 01 0 11 1 0

S R Q Q+

0 0 0 00 0 1 10 1 0 00 1 1 01 0 0 11 0 1 11 1 0 01 1 1 0

12

Page 13: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Algorithmic State Machines (ASM)

13

Page 14: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Clock (Oscillator) Circuit• PS/NS Table• K-map• State Diagram• Delay Model

14

Page 15: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Clock Waveforms

• Delay– Buffers– Additional (maintain odd number) inverters– RC circuit– Crystal Oscillator 15

Page 16: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Gated Sequential Circuits

• Addition of control input– Gated Latch (Level Activated)– Edge-Triggered Flip Flop– Pulse Triggered Flip Flop

16

Page 17: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Gated SR Latch

17

Page 18: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Gated SR Latch Using NANDs

18

Page 19: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Gated D Latch

D Q+

0 01 1

19

Page 20: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Gated D Latch Timing

20

Page 21: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Use as Storage Elements

21

Page 22: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Flip Flop CircuitsPulse Narrowing Circuit

22

Page 23: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Edge-Triggered D Flip Flop

23

Page 24: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Manual Reset of D Flip Flop

24

Page 25: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

74LS74A

25

Page 26: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

JK Flip FlopsJ K Q+ Comment0 0 Q No change0 1 0 Reset1 0 1 Set1 1 Q Toggle

26

Page 27: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

T Flip FlopsJ = K=T Q+ Comment0 0 0 Q No change0 11 01 1 1 Q Toggle

27

Page 28: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

State Diagrams for Binary Up Counters

28

Page 29: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

4-Bit Binary Up Counter

29

Page 30: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Counter Timing Diagram

30

Page 31: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

State Machines

• State Transition Diagrams• Next State Tables• Mealy and Moore Machines

– Mealy: Output logic uses current state and inputs– Moore: Output logic uses only current state

• One Hot vs. Encoded State Machines

31

Page 32: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

T-bird tail-lights example

32

Page 33: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Statediagram

Inputs:LEFT, RIGHT, HAZ

Outputs:Six lamps(function of state only)

33

Page 34: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Encoded or One-Hot?

• Encoded– 8 states– 23 = 8– Need 3 flip flops– Need to determine state assignment

• One-hot– Dedicate a flip flop per state– Need 8 flip flops

34

Page 35: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Implementation(Encoded, Moore Machine)

NextStateLogic

OutputLogic

Inputs Outputs

Current State

35

Page 36: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Output logicLC = L3 + LR3LB = L2 + L3 + LR3LA = L1 + L2 + L3 + LR3RA = R1 + R2 + R3 + LR3RB = R2 + R3 + LR3RC = R3 + LR3

36

LC = Q2’×Q1×Q0’ + Q2×Q1’×Q0’LB = Q2’×Q1×Q0 + Q2’×Q1×Q0’ + Q2×Q1’×Q0’LA = Q2’×Q1’×Q0 + Q2’×Q1×Q0 + Q2’×Q1×Q0’ +

Q2×Q1’×Q0’RA = Q2×Q1’×Q0 + Q2×Q1×Q0 + Q2×Q1×Q0’ +

Q2×Q1’×Q0’RB = Q2×Q1×Q0 + Q2×Q1×Q0’ + Q2×Q1’×Q0’RC = Q2×Q1×Q0’ + Q2×Q1’×Q0’

Q2

Q1

Q0

Page 37: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Next State Logic

• State transition table for encoded states

• Next step depends on implementation choice– Synthesize or Structural with choice of FFs 37

Page 38: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Transition Equations

38

Q2* = Q2’× Q1’ × Q0’ × (HAZ + LEFT × RIGHT) + Q2’ × Q1’ × Q0’ × (RIGHT × HAZ’ × LEFT’) + Q2’ × Q1’ × Q0 × (HAZ) + Q2’ × Q1 × Q0 × (HAZ) + Q2 × Q1’ × Q0 × (HAZ’) + Q2 × Q1’ × Q0 × (HAZ) + Q2 × Q1 × Q0 × (HAZ’) + Q2 × Q1 × Q0 × (HAZ)

Q2* = Q2’× Q1’ × Q0’ × (HAZ + RIGHT) + Q2’ × Q0 × HAZ + Q2 × Q0

Page 39: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Transition Equations

39

Q1* = Q2’ × Q1’ × Q0 × (HAZ’) + Q2’ × Q1 × Q0 × (HAZ’) + Q2 × Q1’ × Q0 × (HAZ’) + Q2 × Q1 × Q0 × (HAZ')

Q1* = Q0 × HAZ’

Page 40: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Transition Equations

40

Q0* = Q2’ × Q1’ × Q0’ × (LEFT × HAZ’ × RIGHT’) + Q2’ × Q1’ × Q0’ × (RIGHT × HAZ’ × LEFT’) + Q2’ × Q1’ × Q0 × (HAZ’) + Q2 × Q1’ × Q0 × (HAZ’)

Q0* = Q2’× Q1’ × Q0’ × HAZ’ × (LEFT Å RIGHT) + Q1’ × Q0 × HAZ’

Page 41: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Implementation(Encoded, Moore Machine)

NextStateLogic

OutputLogic

Inputs Outputs

Current State

41What should the clock’s period be?

Page 42: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

How Fast Can the Clock Be?

42

CombinationalLogic

Clock

D1

Q

D2

FF tpd

Combinational tpd

FF tsetup

FF 1 FF 2

Page 43: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Clock Skew

43Clock

D1

Q

D2

FF tpd

Combinational tpd

FF tsetup

Even with careful routing, clock will not arriveat all FFs at the same time. This skew in clockarrival time affects max clock rate.

Clock Skew

Clock Periodmin = FF tpd + FF tsetup + C tpd + tskew

Page 44: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

One-Hot

45

IDLE* = IDLE × (HAZ + LEFT + RIGHT)’ + L3 + R3 + LR3

L1* = IDLE × LEFT × HAZ’ × RIGHT’

R1* = IDLE × RIGHT × HAZ’ × LEFT’

L2* = L1 × HAZ’

R2* = R1 × HAZ’

L3* = L2 × HAZ’

R3* = R2 × HAZ’

LR3* = IDLE × (HAZ + LEFT × RIGHT) + (L1 + L2 + R1 + R2) × HAZ

Page 45: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Better Still – Behavioral Verilog

46

parameterIDLE = 8'b00000001,L1 = 8'b00000010,L2 = 8'b00000100,L3 = 8'b00001000,R1 = 8'b00010000,R2 = 8'b00100000,R3 = 8'b01000000,LR3 = 8'b10000000;

reg [7:0] State, NextState;

case (State) IDLE: begin if (Hazard || Left && Right) NextState = LR3; else if (Left) NextState = L1; else if (Right) NextState = R1; else NextState = IDLE; end

L1: begin if (Hazard) NextState = LR3; else NextState = L2; end

L2: begin

if (Hazard) NextState = LR3; else NextState = L3; end

L3: begin NextState = IDLE; end

R1: begin if (Hazard) NextState = LR3; else NextState = R2; end

R2: begin if (Hazard) NextState = LR3; else NextState = R3; end

R3: begin NextState = IDLE; end

LR3:begin NextState = IDLE; endendcase

Page 46: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Example: Traffic Light Controller

47

N

S

EW

Sensors in road detect approaching car on NS and EW roads, generating input signals NScar and EWcar respectively.Lights are controlled by outputs NSlite and EWlite.Traffic lights should change only if there is a car approaching from the other direction. Otherwise the lights should remain unchanged.

NScar

EWcar

Clock

Traffic Light

Controller

NSlite

EWlite

r

Page 47: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Example: Traffic Light Controller

48

r

State assignmentNSgreen = 0EWgreen = 1

Page 48: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Example: Serial Line Code Converter

49

BitIn

BitClock

ClockClear

NRZ toManchester

Encoder

BitOut

S00

S10

S31

S21

0

0 0

1

1 1

fFSM Clock = 2 x fBitClock

Page 49: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

NRZ to Manchester (Moore FSM)

50

S00

S10

S31

S21

0

0 0

1

1 1

0ns 50ns 100ns 150ns 200ns 250ns 300ns

TestBench.BitOut

TestBench.Clear

TestBench.BitClock

TestBench.FSMClock

TestBench.BitIn

Rising edge of BitClock coincides with rising edge of FSM clock.BitIn changes at falling edge of BitClock Use falling edge of FSM clock for synchronization (will be at midpoint of bit time) so no danger of sampling BitClock while it’s changing

Page 50: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

51

//// Moore FSM for serial line conversion: NRZ to Manchester encoding//

module NRZtoManchester(Clock, Clear, BitIn, BitOut);input Clock, Clear, BitIn;output BitOut;reg BitOut;

// define states using same names and state assignments as state diagram and table// Using one-hot method, we have one bit per state

parameterS0 = 4'b0001,S1 = 4'b0010,S2 = 4'b0100,S3 = 4'b1000;

reg [3:0] State, NextState;

// Update state or reset on every - clock edge

always @(negedge Clock)beginif (Clear) begin

State <= S0; $display("Reset: S0"); endelse begin

State <= NextState; $display("State: %d",State); endend

Page 51: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

52

// Outputs depend only upon state (Moore machine)

always @(State)begincase (State)

S0: BitOut = 1'b0;S1: BitOut = 1'b0;S2: BitOut = 1'b1;S3: BitOut = 1'b1;

endcaseend

// Next state generation logic

always @(State or BitIn)begincase (State)

S0: if (BitIn) NextState = S3;else NextState = S1;

S1: if (BitIn) $display("S1 Error!");else NextState = S2;

S2: if (BitIn) NextState = S3;else NextState = S1;

S3: if (BitIn) NextState = S0;else $display("S3 Error!");

endcaseendendmodule

Page 52: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

53

Page 53: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Airplane Gear Example

54

PilotLever

GearIsUpAirplane Landing

Gear Control

Valve

PlaneOnGround

GearIsDown

Pump

RedLED

GreenLED

PilotLeverOperated by pilot to control landing gear(1:down 0:up)

PlaneOnGroundSensor 1 when plane on ground

GearIsUpSensor 1 when landing gear fully up

GearIsDownSensor 1 when landing gear fully down

TimeUp1 when two second timer expired

ValveControls position of valve (1:lowering 0:raising)

PumpActivates hydraulic pump (1: activate)

ResetTimer1 to reset count-down timer, 0 to count

RedLEDIndicates landing gear in motion

GreenLEDIndicates landing gear down

Do not retract landing gear if plane on groundPlane should be airborne two seconds before retracting gear

TimeUp Timer

Page 54: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Airplane Landing Gear Example

55

Lever

GearUp

Airplane Landing

Gear Control

Valve

OnGround

GearDown

Pump

RedLED

GreenLED

LeverOperated by pilot to control landing gear(0:down 1:up)

OnGroundSensor 1 when plane on ground

GearUpSensor 1 when landing gear fully up

GearDownSensor 1 when landing gear fully down

ValveControls position of valve (0:lowering 1:raising)

PumpActivates hydraulic pump

RedLEDIndicates landing gear in motion

GreenLEDIndicates landing gear down

Do not retract landing gear if plane on groundRespond to changes in lever position(in case plane started with lever in up position)Plane should be airborne two seconds before retracting gear

Page 55: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

State Transition Diagram

56

Waitingfor

TakeOff

Waitingfor

TimerGearUp

RaisingGear

LoweringGear

~PlaneOnGround

PlaneOnGround

TimeUp && ~PilotLever

GearIsUp

~PilotLever

PilotLever

PlaneOnGround

Reset

State ResetTimer

Pump Valve RedLED GreenLED

WaitingforTakeoff 1 0 X 0 1

WaitingforTimer 0 0 X 0 1

RaisingGear X 1 0 1 0

GearUp X 0 X 0 0

LoweringGear X 1 1 1 0

GearDown X 0 X 0 1

GearDown

~PilotLever

GearIsDown

PilotLever

Page 56: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Vending Machine Example

• Taken from Katz & Borriello, “Contemporary Logic Design”

57

Page 57: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

VII - Finite State Machines

© Copyright 2004, Gaetano Borriello and Randy H. Katz

58

VendingMachine

FSM

N

D

Reset

Clock

OpenCoinSensor

ReleaseMechanism

Example: vending machine

• Release item after 15 cents are deposited• Single coin slot for dimes, nickels• No change

Page 58: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

VII - Finite State Machines

© Copyright 2004, Gaetano Borriello and Randy H. Katz

59

Example: vending machine• Suitable abstract representation

– tabulate typical input sequences:• 3 nickels• nickel, dime• dime, nickel• two dimes

– draw state diagram:• inputs: N, D, reset• output: open chute

– assumptions:• assume N and D asserted

for one cycle• each state has a self loop

for N = D = 0 (no coin)

S0

Reset

S2

D

S6[open]

D

S4[open]

D

S1

N

S3

N

S5[open]

N

S8[open]

D

S7[open]

N

Page 59: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

VII - Finite State Machines

© Copyright 2004, Gaetano Borriello and Randy H. Katz

60

Example: vending machine• Minimize number of states - reuse states whenever possible

symbolic state table

present inputs next outputstate D N state open 0¢ 0 0 0¢ 0

0 1 5¢ 01 0 10¢ 01 1 – –

5¢ 0 0 5¢ 00 1 10¢ 01 0 15¢ 01 1 – –

10¢ 0 0 10¢ 00 1 15¢ 01 0 15¢ 01 1 – –

15¢ – – 15¢ 1

Reset

N

N

N + D

10¢

D

15¢[open]

D

Page 60: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

VII - Finite State Machines

© Copyright 2004, Gaetano Borriello and Randy H. Katz

61

present stateinputs next state outputQ1 Q0 D N D1 D0 open

0 0 0 0 0 0 00 1 0 1 01 0 1 0 01 1 – – –

0 1 0 0 0 1 00 1 1 0 01 0 1 1 01 1 – – –

1 0 0 0 1 0 00 1 1 1 01 0 1 1 01 1 – – –

1 1 – – 1 1 1

Example: vending machine

• Uniquely encode states

Page 61: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

VII - Finite State Machines

© Copyright 2004, Gaetano Borriello and Randy H. Katz

62

D1 = Q1 + D + Q0 N

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

OPEN = Q1 Q0

Example: Moore implementation

• Mapping to logic 0 0 1 1

0 1 1 1

X X 1 X

1 1 1 1

Q1D1

Q0

N

D

0 1 1 0

1 0 1 1

X X 1 X

0 1 1 1

Q1D0

Q0

N

D

0 0 1 0

0 0 1 0

X X 1 X

0 0 1 0

Q1Open

Q0

N

D

Page 62: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

VII - Finite State Machines

© Copyright 2004, Gaetano Borriello and Randy H. Katz

63

present state inputs next state outputQ3Q2 Q1Q0 D N D3D2 D1D0 open0 0 0 1 0 0 0 0 0 1 0

0 1 0 0 1 0 01 0 0 1 0 0 01 1 - - - - -

0 0 1 0 0 0 0 0 1 0 00 1 0 1 0 0 01 0 1 0 0 0 01 1 - - - - -

0 1 0 0 0 0 0 1 0 0 00 1 1 0 0 0 01 0 1 0 0 0 01 1 - - - - -

1 0 0 0 - - 1 0 0 0 1

D0 = Q0 D’ N’

D1 = Q0 N + Q1 D’ N’

D2 = Q0 D + Q1 N + Q2 D’ N’

D3 = Q1 D + Q2 D + Q2 N + Q3

OPEN = Q3

Example: vending machine

• One-hot encoding

Page 63: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Types of FSMs

69

state feedback

inputs

outputsreg

combinational logic for next state logic for

outputs

inputs outputs

state feedback

regcombinational

logic fornext state

logic foroutputs

inputs outputs

state feedback

regcombinational

logic fornext state

logic foroutputs

Moore

Mealy

Synchronous Mealy

Page 64: ECE 171 Digital Circuits Chapter 13 Flip Flops Herbert G. Mayer, PSU Status 11/23/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

References

1. T.b.d.