Sie sind auf Seite 1von 8

52.

139 Computer Organisation and Design

Lecture 13

FSM - Finite State Machines


Sequential systems (SS) contain data stored in memory elements internal to the system. SS behaviour depends on both the set of inputs supplied and on the contents of the internal memory, or the state of the system. Thus a SS cannot be described with a truth table. Instead, it is described as a finite state machine (FSM).

Lecture 13

52.139 Computer Organisation and Design

Page 2

FSM - Finite State Machines


A FSM has a set of states and two functions:
the next-state function and the output function.

The set of states correspond to all the possible values of the internal storage.
n bits of storage results in 2n states.

next-state function - a combinatorial function that, given the inputs and the current state, determines the next state of the system. output function - produces a set of outputs from the current state and the inputs.
Lecture 13 52.139 Computer Organisation and Design Page 3

Block Diagram of a FSM


Current state Clock Inputs Next-state function Next state

Output function

Outputs

A state machine consists of internal storage that contains the state and two combinatorial functions: the next-state function and the output function
Lecture 13 52.139 Computer Organisation and Design Page 4

Moore and Mealy FSMs


Moore machine
Where the output function of the FSM is restricted to depend on just the current state. Can be faster

Mealy machine
Where the output function of the FSM depends on both the current state and the current input May be smaller

These two machines are equivalent in their capabilities and one can easily be transformed into the other.
Lecture 13 52.139 Computer Organisation and Design Page 5

FSM Example: The Traffic Light Controller


These traffic lights are at the junction of a northsouth route and an east-west route. Consider only the green and red lights for simplicity. The lights cycle no faster than 30 seconds in each direction:
a 1/30 Hz clock drives the state changes.

There are two output signals:


NSlight: When asserted the light on the north-south road is green, otherwise it's red. EWlight: When asserted the light on the east-west road is green, otherwise it's red.
Lecture 13 52.139 Computer Organisation and Design Page 6

FSM Example: The Traffic Light Controller


In addition there are two inputs:
NScar: Asserted when there is a car detected on the north-south road EWcar: Asserted when there is a car detected on the eastwest road

Rules: the traffic light should change from one direction to the other only if a car is waiting to go in the other direction; otherwise, the light should continue to show green in the same direction as the last car that crossed the junction.
Lecture 13 52.139 Computer Organisation and Design Page 7

FSM Example: The Traffic Light Controller


To implement this simple traffic light we need two states: NSgreen: the traffic light is green in the northsouth direction. EWgreen: the traffic light is green in the eastwest direction. We also need to create the next-state function, which can be specified with a table

Lecture 13

52.139 Computer Organisation and Design

Page 8

Traffic Lights FSM - Next-State Table


Current State NSGreen NSGreen NSGreen NSGreen EWGreen EWGreen EWGreen EWGreen
Lecture 13

Inputs NScar 0 0 1 1 0 0 1 1 EWcar 0 1 0 1 0 1 0 1

Next State NSGreen EWGreen NSGreen EWGreen EWGreen EWGreen NSGreen NSGreen
Page 9

52.139 Computer Organisation and Design

Traffic Lights FSM - Output Function


The FSM is completed by specifying the output function:
Current State NSgreen EWgreen Outputs NSlight 1 0 EWlight 0 1

Lecture 13

52.139 Computer Organisation and Design

Page 10

FSM - Implementation
State assignment - State numbers must be assigned to states. For example
NSgreen is assigned to state 0 and EWgreen to state 1.

The state register in this case would contain a single bit. The next-state function would be given as:
nextState=(!currentStateEWcar)+(currentState!NScar)

currentState:
the contents of the state register (0 or 1)

nextState:
the output of the next-state function that will be written into the state register at the end of the clock cycle.

Lecture 13

52.139 Computer Organisation and Design

Page 11

FSM - Implementation
A FSM can be implemented with a register to hold the current state and a block of combinatorial logic that computes the next-state functions and the output function.
Outputs Combinational logic Next state State register

Inputs

Lecture 13

52.139 Computer Organisation and Design

Page 12

FSM - Implementation
The output function is also simple:
NSlight = !currentState EWlight = currentState

The combinatorial logic block is often implemented using structured logic, such as a PLA.
A PLA can be constructed automatically from the next-state and output-function tables and using computer-aided design (CAD) tools.
Lecture 13 52.139 Computer Organisation and Design Page 13

Graphical Representation of FSMs


nodes are used to indicate states; inside the nodes is a list of the outputs that are active for that state; NSgreen directed arcs are used to show the next-state function; labels on the arcs specifying the input condition as logic functions.

EWcar

EWgreen NSlite NScar EWlite

______ EWcar

______ NScar

Lecture 13

52.139 Computer Organisation and Design

Page 14

Departmental Lock System


This FSM state transition diagram (STD) represents the operation of an electronic lock unlocked by means of a Personal Identification Number (PIN) entered via a keypad and/or a magnetic 'swipe' card key. The lock has two modes of operation:
Normal hours: where an acceptable PIN is either a 'swipe' of a valid magnetic card key or a keypadentered PIN common to all users; Out of normal hours: where an acceptable PIN is a 'swipe' of a valid magnetic card key and a keypadentered PIN specific to that user.
Lecture 13
nHaPrP aP unboltDoor aP aP nHaPrP aP rP entryDenied
GreenLED off YellowLED off RedLED on GreenLED on YellowLED off RedLED off

dayTimeBolt
GreenLED off YellowLED off RedLED off

rP

nHaPrP

eveningBolt
GreenLED off YellowLED on RedLED off

rP

rP

nHaPrP

52.139 Computer Organisation and Design

Page 15

Departmental Lock System - Questions


Identify the states used in the implementation of this electronic lock and explain why these states are necessary Identify the inputs used in the implementation of this electronic lock and describe briefly their purpose. State any assumptions you may have made. Specify the next-state function of the FSM by means of a table with the headings 'Current State', 'Inputs', and 'Next State'. Specify the output function of the FSM by means of a table
Lecture 13
nHaPrP aP unboltDoor aP aP nHaPrP aP rP entryDenied
GreenLED off YellowLED off RedLED on GreenLED on YellowLED off RedLED off

dayTimeBolt
GreenLED off YellowLED off RedLED off

rP

nHaPrP

eveningBolt
GreenLED off YellowLED on RedLED off

rP

rP

nHaPrP

52.139 Computer Organisation and Design

Page 16

Das könnte Ihnen auch gefallen