230 likes | 699 Views
Finite State Machine(FSM). What is meant by “Finite”?. Finite means countable. What is Finite State Machine?. A machine that consists of a fixed set of possible states with a set of allowable inputs that change the state and a set of possible outputs.
E N D
What is meant by “Finite”? • Finite means countable. What is Finite State Machine? • A machine that consists of a fixed set of possible states with a set of allowable inputs that change the state and a set of possible outputs.
A finite state machine consists of • States • Inputs • Outputs. • The number of states is fixed; when an input is executed, the state is changed and an output is possibly produced.
Example: • Vending machines, traffic signals, Elevators, combination locks etc. • A lift is very common example of a finite state machine. • The lift system has inputs and outputs. • One input occurs when a person on second floor press the request button. • One output will occur to that person showing him the current position of the lift.
Memory and logic device • A lift must have a memory to store the current state of the lift to move in desired direction. • A lift must have a logic device to determine the next step and update the memory to reflect the new state. • To move in desired direction the lift must know the current state of lift and what step to take next.
Elevator steps • If the elevator is on the floor 1 and the floor • requested is the floor 1, then the elevator • remains on the floor 1. • If the elevator is on the floor 1 and the floor • requested is the floor 2, then the elevator is • raised up 1 floor. • If the elevator is on the floor 1 and the floor • requested is the floor 3, then the elevator is • raised up 2 floors. • If the elevator is on the floor 2 and the floor • requested is the floor 1, then the elevator is • lowered down 1 floor.
If the elevator is on the floor 2 and the floor requested is the floor 2, then the elevator remains on the floor 2. If the elevator is on the floor 2 and the floor requested is the floor 3, then the elevator is raised up 1 floor. If the elevator is on the floor 3 and the floor requested is the floor 1, then the elevator is lowered down 2 floors. If the elevator is on the floor 3 and the floor requested is the floor 2, then the elevator is lowered down 1 floor. If the elevator is on the floor 3 and the floor requested is the floor 3, then the elevator remains on the floor 3.
State Transition Diagram • State transition diagram represent an FSM graphically. • Each state is represented by a circle. • Each transition is represented by an arrow. • It is used to show all the states, inputs and outputs
Significance of FSM • FSMs are so useful because they can recognise sequences. • The set of recognisable sequences can be legal and valid programs in a given programming language.
Example of an FSM • A ball point is an example of an FSM. • It has finite number of states: • Ballpoint extended • Ballpoint retracted. • It has a set of possible inputs : clicking the pen’s button. • It has a set of possible outputs: retracting or extending of ballpoint.
State transition diagram for a ballpoint • State 0 = ballpoint retracted. • State 1 = ballpoint extended. Button clicked Button clicked State 0 State 1
State Transition table • A state transition table is a table showing what state a finite state machine will move to, based on the current state and other inputs.
Decision table • A table that show the possible outcomes for a given logical condition. • Decision table makes it easy to observe what are all possible conditions? • Example if X > 6 and Y < 7 then output ‘pass’ else output ‘fail’
Finite state automata • A finite state machine with no output is called finite state automata. • FSA have an initial state and one or more accepting state and a double circle to indicate the accepting state or goal state.
Mealy machine • FSMs with outputs have an initial state and usually no accepting states. They are called mealy machines. • The intial state is indicated with a special arrow labelled ‘start’.