finite state machines - cecs -...

75
Finite State Machines 1 ENGN3213: Digital Systems and Microprocessors L#12-13

Upload: dangtram

Post on 04-Apr-2019

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Finite State Machines

1 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 2: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Register Transfer Level Abstraction

2 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 3: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

The Finite State Machine Abstraction

➤ Changes state according to different inputs. In each state there is a uniqueoutput. (Moore machine) . The outputs may also depend directly on inputs(Mealy machine) .

➤ FSM are sequential systems (use flip-flops to make transitions). In eachstate combinational circuits produce the outputs from inputs.

➤ Only use synchronous state machines in this course

3 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 4: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

The control path of an RTL system is based on a finite state machine. An FSM is quite abstract, but for thisdiscussion one can think of an FSM as a system that possesses a finite number of states. In each state the outputof the system is fully deterministic. When a new set of inputs is applied, the system undergoes a transition to adifferent state with different outputs. The bubbles in the above figures represent the states and the arrow loopsrepresent the transitions.

Notice that the inputs are written on the loops in the case of the Moore machine. Generally the outputs can bewritten inside the state bubbles of the Moore machine.

In the case of the Mealy machine both the inputs and the outputs are written on the loops. (WHY?)

In this course we will only consider synchronous FSMs. Synchronous FSMs are FSMs in which all transitionsoccur on the active edge of the clock. Moreover, even external inputs to the FSM, though naturally asynchronousbecause they cannot know about the clock, will be rendered synchronous through an appropriate circuit.

Apart from the above state diagrams one can also represent a FSM with a state transition table as follows...

InputsPresentState State

Next Outputs

State transition table

4 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 5: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Finite State Machine Structure

➤ State machines consist of a state memory which in implementation is abank of n flip-flops. For n flip-flops there are 2n possible statesrepresentable WHY?

➤ The flip-flops are in parallel and undergo their transitions (change state) onthe tick of a common clock - synchronous state machine

➤ The next state is determine by the next state logic, F which is a functionof the inputs and the current state.

➤ The output logic, G determines the output as a function of the currentstate and the (possibly) the inputs.

➤ Thus we see that a synchronous FSM consists of two combinational bits(the input and output logic blocks) and one sequential bit (the statememory block)

5 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 6: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machine Electronic Block Diagram

D

D

D

D

Q

Q

Q

Q

Next State

Logic

Output

Logic

F(inputs,State) G(state, input?)

OutputsInputs

Combinational CombinationalSequential

6 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 7: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machine Models: Moore Machine

7 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 8: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machine Models: Mealy Machine

8 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 9: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Describing FSMs Mathematically

Equations. Moore machine:s(t + 1) = F(s(t), x(t)) −state equation

z(t) = G(s(t)) −output equation

Equations. Mealy machine:s(t + 1) = F(s(t), x(t)) −state equation

z(t) = G(s(t), x(t)) −output equation

x(t) - input, s(t) - state, z(t) - output

9 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 10: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Excitation and Characteristic equations

➤ The State transition equation consists of a excitation equation and acharacteristic equation.

➤ The Excitation equation specifies the input applied to a flip- flop deviceas a function of current state and inputs.

➤ The Characteristic equation specifies the next state of a flip- flop deviceas a function of its excitation. That is, it is the state transition equation offlip-flop itself.➤ S-R latch: Q∗ = S + RQ➤ D flip-flop: Q∗ = D➤ J-K flip-flop: Q∗ = JQ + KQ➤ T flip-flop with enable: Q∗ = TQ + TQ

10 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 11: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machine Equations

D

D

D

D

Q

Q

Q

Q

Next State

Logic

Output

Logic

F(inputs,State) G(state, input?)

OutputsInputs

Combinational CombinationalSequential

Characteristic EquaiionExcitation Equation

11 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 12: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

A Remark About the Flip-Flops

➤ In as much as most state machines nowadays are designed using PLDs,CPLDs, FPGAs or ASICs, positive edge triggered D flip-flops are mostcommonly used to design FSMs

➤ This is what our VERILOG model describes

➤ Sometimes however more efficient (less CMOS gate) designs can bemade with negative edge triggered D flip-flops or J-K flip-flops

12 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 13: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Representations of Finite StateMachines

13 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 14: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Diagrams

The state is a description of a system characterised by a give n set ofinputs

➤ States are symbolised by a bubble in the form of a circle or a box.

➤ Loops or branches between the state bubbles represent state transitionswith the input condition for the transition written on them.

➤ For a Mealy machine the outputs depend on both the input and the state.Thus they are written underneath the inputs on the loops

➤ The outputs of a Moore machine can be written inside the state bubbles

14 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 15: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Revision?: Pedestrian Traffic Controller (Moore machine)

s0

G, HALT

Y, HALT

s1

R, WALK

s2

R, HALT

s3

W

W

RESET

15 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 16: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Output Table (Next State Table)

Another representation of the FSM is the next state table (also sometimescalled next state/output table .

➤ The left-most column gives the state of the system.

➤ The next columns give the state to which a transition must occur for thestated set of input signals.

➤ The final column are the outputs .

16 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 17: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Examples of FSMs: Alarm Circuit (Moore machine)

17 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 18: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Examples of FSMs: Alarm Circuit State Diagram

18 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 19: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Examples of FSMs: Alarm Circuit (Moore machine)

Present next next Outputstate state states0 s0 trip=0 s1 trip=1 0 Silent

s1 s0 reset=1s1 reset = 01 Sound

19 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 20: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Examples of FSMs: Coke Vending Machine

coin.return

s0

s1

s2

s3

s4

s5

sum

<75

coin

.ret

urn

sum=75

sum>75

chan

ge_a

vaila

ble

change_available

return_change

return_all_coins

release_candy

coin.return

20 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 21: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Examples of FSMs: Candy Vending Machine

Presentnext next next releasereturn allreturnstate state state state candy coins changes0 s0 if coin=0 s1 if coin=1 s5 if coin = 0 0 0 0

and return=0 and return = 0and return = 1s1 s0 if sum<75s2 if sum=75 s3 if sum>75 0 0 0s2 s0 - - 1 0 0s3 s4 if change s5 if change - 0 0 0

available = 1 available = 0 -s4 s2 - - 0 0 1s5 s0 - - 0 1 0

21 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 22: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

FSM Analysis Steps

Starting from a FSM logic diagram:1. Determine the state transition and output functions F and G.

a) Find the excitation equation.b) Using the characteristic equation, determine the corresponding

next-state values (trivial with D Flip-Flop)c) Find the output equations

2. Construct state/output table: For each state/input combination, determinethe next state and output values

3. Draw the state diagram

22 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 23: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example (Mealy Machine)

23 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 24: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example: Step 1a) Excitation Equations

24 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 25: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example: Step 1bc) Transition/output Equa tions

25 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 26: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example: Step 2) State/output Tables

26 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 27: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example: Step 3) State Diagram

27 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 28: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example 2

28 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 29: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example 2 (CTD)

29 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 30: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example 2 (CTD)

30 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 31: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

State Machines: Example 2 (CTD)

31 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 32: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Verilog Description of an FSM

➤ Verilog can be used to describe higher levels of abstraction than circuits.

➤ The transition between states is a sequential operation (in the sense of asequential circuit )

➤ In a FSM the actions that produce outputs from the inputs are alwayscombinational

➤ Follow Wakerly Tables 7-58 and 7-59:➤ State transitions model with sequential ALWAYS block➤ Next state logic model with combinational ALWAYS block➤ Output logic model with combinational ALWAYS block

32 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 33: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Design and Synthesis of FiniteState Machines

33 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 34: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Last Lecture

➤ We saw the definition of the Mealy and Moore state machines.

➤ We defined the next state (or output) table and the state diagram.

➤ We defined the following terms to describe state machines: excitation andcharacterisitc equations, next state logic, state memory and output logic.

➤ We looked at a counter example where the circuit was given and we drewup the next state table and the state diagram

34 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 35: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Finite State Machine Design and Synthesis

➤ Design is the creative part, like writing a program

➤ The design process is actually the opposite process of the state machineanalysis.

➤ Synthesis is like turning the crank, like Xilinx compiler does

➤ Recall the analysis steps:1. Determine the state transition and output functions2. Construct the next-state and output tables3. Draw the state diagram

35 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 36: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Finite-State Machine Design Steps

1. Determine the inputs / outputs. Determine the states and give themmnemonic names

2. Draw up a state diagram and a next state table.

3. Render the inputs, outputs and states in binary format.

4. Draw an excitation table - a truth table showing the inputs and current statebinary values as inputs and the desired next state binary values as theoutputs.

5. Use K-maps to obtain produce minimal next state and outputcombinational logic.

6. Use the standard VERILOG formulation to simulate your design and checkfor correct operation. Revise as appropriate.

7. Check for potential practical problems (e.g. non-ideal effects).

36 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 37: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Design Examples

1. The alarm controller

2. Up/Down/Stop Counter

3. Pedestrian Traffic Controller

4. Vending Machine Controller

.... Practice makes perfect!

37 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 38: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Controller

Problem Statement:

1. The alarm should sound when the beam is broken. Level triggering

2. The alarm should reset from the “sounding” to the “armed” state when areset button is pushed (level triggering) regardless of the status of thebeam.

38 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 39: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Controller State Diagram

39 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 40: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Conrtroller: State/Output Table

➤ Based on the state diagram, the state/output or next state table can beconstructed.

➤ Notation: A-armed, S-sound, T-trip level and R-reset level.

Present statenext statenext statenext statenext stateT ′R′ T ′R TR TR′

A A A S SS S A A S

40 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 41: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Conrtroller: State/Output Table (CTD)

Present state next state next state next state next stateT ′R′ T ′R TR TR′

A A A S SS S A A S

Now we need to code the symbols (states/output) into binary numbers (notethe use of the Gray code)

Present state next state next state next state next stateStates 00 01 11 10

0 0 0 1 11 1 0 0 1

41 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 42: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Conrtroller Excitation Table

Consider the values within the next state table to be not only the ensuingstates in response to the inputs, but also the input states to the inputlogic that produces the input excitation

Present state next state next state next state next stateS/ TR 00 01 11 10

0 0 0 1 11 1 0 0 1

42 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 43: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Conrtroller Excitation Truth Table

T R S Q0 0 0 0

0 1 0 0

1 0 0 1

1 1 0 1

0 0 1 1

0 1 1 0

1 0 1 1

1 1 1 0

43 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 44: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Conrtroller: Input Logic

Do Karnaugh maps to work out the Boolean input logic.

S/ TR 00 01 11 10

0 0 0 1 11 1 0 0 1

Q = T · R + T · S + R · S (1)

44 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 45: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Controller Circuit

T

R

S

Clk

DFF

45 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 46: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Alarm Conrtroller: Comments

➤ Is the input T · R really necessary?

➤ Are there any glitches produced according to the truth table?

➤ Use the techniques of lecture 11 to synchronise the level sensitive inputs T

and R to the clock.

46 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 47: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter

1. Design a synchronous up/down/stop counter that➤ has two input buttons (‘mode’ and ‘stop’).➤ If the ‘mode’ button is 0, it counts upwards. If the ‘mode’ input is 1 it

counts downwards.➤ If ‘stop’ is pressed, it holds the current state regardless of input mode.➤ Output indicates the even states (second and fourth).

2. For example, if the states are binary number then for every input, it willsequence through:

47 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 48: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter State Diagram

48 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 49: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: State/Output Table

Based on the state diagram, the state/output table can be constructed:

Present statenext statenext statenext stateOutputA B Up D Down A stop OddB C Up A Down B stop EvenC D Up B Down C stop OddD A Up C Down D stop Even

Now we need to code the symbols (states/output) into binary numbers

49 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 50: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: State/Output Table (CTD)

➤ The methods of coding into numbers are not unique.➤ Binary coding, Gray coding, etc.

50 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 51: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: State/Output Table (CTD)

➤ Lets use the Gray code➤ For the up/down inputs, we can assign one bit M (mode) M=0 for the up

input, and M=1 for the down input.➤ For the stop input we still need one more bit (S=1 for stop).➤ The output (y) will be 1 for the second and fourth states.

51 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 52: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: State/Output Table (CTD)

The next-state table becomes

Now we need to decide the flip-flop devices, and thus find out the inputs for theflip-flop.

52 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 53: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter (CTD)

➤ From the next-state table, we need to find out the required flip- flop inputs(or excitation table).

➤ If we use the D flip-flop, the FF inputs are directly the next- state values,but for JK FF, it is a bit more complex.

53 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 54: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: State/Output Table (CTD)

54 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 55: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: (CTD)

55 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 56: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: (CTD)

56 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 57: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Up/Down/Stop Counter: State/Output Table (CTD)

57 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 58: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

58 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 59: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

s0

G, HALT

Y, HALT

s1

R, WALK

s2

R, HALT

s3

W

W

RESET

59 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 60: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

60 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 61: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Pedx Controller: State/Output Table

Now we need to code the symbols (states/output) into binary numbers (notethe use of the Gray code)

Present state W = 0 W = 1

00 00 0101 10 1010 11 1111 00 00

Use Karnaugh maps...Q1,Q2 W = 0 W = 1 Q1,Q2 W = 0 W = 1

00 0 0 00 0 101 1 1 01 0 011 0 0 11 0 010 1 1 10 1 1

61 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 62: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Pedx Controller: State/Output Table

Thus the excitation logic becomes Q1 × Q2 and Q2 · (Q1 + W ).

62 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 63: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

63 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 64: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

64 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 65: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Pedx Controller: D Flip-Flop Circuit Diagram

65 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 66: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Vending Machine Controller

Problem Statement Design a state machine controller for a vending machine

to satisfy the following,

➤ Sell one item worth 75c

➤ Return change and deliver the item when the coins inserted into themachine exceed the sum of 75c

➤ Return all coins upon request without releasing the item

66 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 67: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Vending Machine Controller State Diagram

coin.return

s0

s1

s2

s3

s4

s5

sum

<75

coin

.ret

urn

sum=75

sum>75

chan

ge_a

vaila

ble

change_available

return_change

return_all_coins

release_candy

coin.return

67 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 68: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Vending Machine Controller Next State Table

68 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 69: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

69 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 70: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

70 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 71: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

CN.RTN

s0

s1

s2

s3

s4

s5C

N.R

TN

CA

CA

RCH

RAC

RC

CN.RTN

000001 - F

ABCDEF

100000 - A

000010 - E

000100 - D

010000 - B

001000 - CSM2

SM

0

SM1

71 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 72: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Vending Machine Conmtroller Equations

With D flip-flops with RESET, activation of the RESET signal will force the statemachine into state s0 = 000001.

DA = F · CN · RTN + C · CA

DB = C · CA

DC = E · SM2

DD = E · SM1 + B

DE = F · CN · RTN

DF = F · CN · RTN + E · SM0 + D + A

Note simplication afforded by one hot coding .

72 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 73: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

73 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 74: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Two State Moore Machine in Verilog

74 ENGN3213: Digital Systems and Microprocessors L#12-13

Page 75: Finite State Machines - CECS - ANUcourses.cecs.anu.edu.au/courses/ENGN3213/lectures/lectures12_and... · Finite State Machine Structure State machines consist of a state memory which

Two State Mealy Machine in Verilog

75 ENGN3213: Digital Systems and Microprocessors L#12-13