Presentation is loading. Please wait.

Presentation is loading. Please wait.

AS Computer Studies Finite State Machines 1.

Similar presentations


Presentation on theme: "AS Computer Studies Finite State Machines 1."— Presentation transcript:

1 AS Computer Studies Finite State Machines 1

2 Starter Imagine yourself stood at a crossing, at a junction with two directions of traffic. What are the different STATES of the lights (the order, which lights can be on etc). What would cause the lights to change?

3 Objectives Understand the stages of problem solving.
Become familiar with finite state machines and their purpose. Be able to create and construct a finite state machine.

4 Starter Review The lights you have are: RED AMBER GREEN RED MAN
GREEN MAN The process is: RED  RED AMBER  GREEN  AMBER  RED Causes of the lights to change would be: Traffic coming from a different direction. A pedestrian activating the crossing Causing the RED MAN to go off and the GREEN MAN to come on.

5 Finite State Machines (FSM) I
Traffic crossings can be in ONE state at any ONE time. Finite means countable. Traffic crossings have a set number of possible states they can be in. Traffic crossings have five different states: RED  RED AMBER  GREEN  AMBER  RED They have a number of inputs (traffic sensors, crossing button). They have a number of outputs (the different lights)

6 Finite State Machines (FSM) II
For traffic lights to move between states, it needs to ALWAYS know it’s current state. The traffic lights couldn’t move from Red to Green if it was already on green for example. When the pedestrian crossing button is pressed: The lights change from green to amber The logic device records the new state. The lights change from amber to red. The red man turns off The green man turns on

7 How does this look A diagram of how Traffic Lights Work (at surface level) Logical Device (Traffic Lights) programmed with state transition diagram Memory Inputs (traffic sensor or Pedestrian button) Outputs Actual traffic lights Or Red/Green man Change memory to next state (e.g. Red  Red Amber)

8 What is a finite state machine (FSM)?
A machine that has a fixed set of possible states. It has a set of inputs that can change the state. It has a set of outputs which can reflect the state change. This can range from 2 states to millions!

9 Quick Task Write down all the different states for a car (keep it simple) Think about what inputs and outputs you would need. Answer: Engine on, Moving Engine on, Slowing Down Engine on, Stationary Engine off, Stationary Inputs: Key to start ignition, Accelerator, brakes Outputs: Motion, Indicator signals

10 State Transition Diagrams
These are a way of explaining a FSM in a graphical way. Each state is represented by a circle. A transition (movement) between each state is shown by an arrow. Labelled with the inputs that causes the transition. Labelled with any outputs which happened because of the transition.

11 An Example: Showing an FSM in a State Transition Diagram
Let’s take the example of a pen as an Finite State Machine It has two finite states. The pen is extended out (i.e. the pen is ON – STATE 1) The pen is retracted (i.e. the pen is OFF – STATE 0) It has allowable inputs: clicking the pen’s button. It has possible outputs: the pen nib extended or retracted. State 0 State 1 Button clicked

12 Quick Task A light switch is a simple example of a finite state machine. Draw a FSM illustrate this. TIPS: STEP 1: Identify the states STEP 2: Identify the inputs STEP 3: Identify the outputs STEP 4: Identify the transitions

13 Quick Task Review A light switch is a simple example of a finite state machine. STEP 1: Identify the states: Switch On, Switch Off STEP 2: Identify the inputs: Switching on the switch STEP 3: Identify the outputs: The light is on or off STEP 4: Identify the transitions: S0 (switched off) to S1 (switched on) and vice versa. NOTICE: There is no FINAL or ACCEPTING (finishing) state. State 0 State 1 Light-switch Down Light-switch Up

14 State Transition: Further Knowledge
The combination on my brief case is 249. It will only open when given this sequence. There are no outputs here. The initial start is shown by the arrow. Constantly loops around state S0 (locked) unless 2 is selected. Once 2 is selected, state s1 is reached. This continues to the final state. Double circle = Accepting state – shown in S3

15 FSM: Mealy Machines So far we have just seen State Transitions which do something. We haven’t seen them output any actual information. To do this, we use a particular type of FSM A Mealy Machine – FSM’s with outputs, have an initial state and no accepting states. Initial states have a labelled arrow called “Start”

16 Activity: Creating a Mealy Machine
We want to develop a machine which converts a set of values into characters. 0 = A 1 = B 2 = ! The system begins at state S0. If the received digit is 0 and the system is in state S0, output the letter A If the received digits is 1 and the system is in state S0 change to state S1 and output letter B. If the received digit is 2 and the system is in state S0 change to S2 and output the letter !. If the received digit is 0 and the system is in state S1, change state to S0 and output the letter A. If the received digit is 1 and the system is in state S1, output the letter B. If the received digit is 2 and the system is in state S1, change state to S2 and output character ! DRAW A STATE TRANSITION DIAGRAM TO SHOW THIS USING THE SHEET PROVIDED.

17 Conversion Machine: A Solution
What would the following sequences produce (you may need to write it down!) would produce: AABABBA! = BABAB! = BAABABB! = BBBABA! State 0 Start 0, A State1 1, B State2 2, !

18 Objectives Review Understand the stages of problem solving.
Become familiar with finite state machines and their purpose. Be able to create and construct a finite state machine.

19 Plenary Teach back. Each person will be asked to stand up and suggest one thing they have learnt today. Reflection: What do we need to know more of to deepen our understanding.


Download ppt "AS Computer Studies Finite State Machines 1."

Similar presentations


Ads by Google