You are on page 1of 14

CENG 563

Real-Time and Embedded System Design

Lecture 3-A
1

Finite State Machines

Asst. Prof. Tolga Ayav, Ph.D.

Department of Computer Engineering
İzmir Institute of Technology

mapping states and inputs to states. y1. An FSM is a 6-tuple. z1....  is a next-state function (i.e. Finite State Machines Finite state machines (FSMs) are powerful design elements used to implement algorithms in hardware. .. yn}... zl}.. . X is a set of inputs {x0. (Z x X → Y)  is an output function. <Z. where: Z is a set of states {z0. xm}. . Y. mapping current states to outputs (Z → Y). İzmir Institute of Technology Real-Time and Embedded System Design . x1. and z0 is an initial state. z0>.. X. . .. Y is a set of outputs {y0. transitions).

Moore and Mealy FSMs İzmir Institute of Technology Real-Time and Embedded System Design .

 : (Z → Y) İzmir Institute of Technology Real-Time and Embedded System Design . FSM Model: Moore Outputs depends on states.

FSM Model: Mealy Outputs depends on states and inputs.  : (X x Z → Y) İzmir Institute of Technology Real-Time and Embedded System Design .

Y. ⧫  is a next-state function (i. V. ⧫ Y is a set of outputs {y0.e.. FSMD (Finite-state machines with datapaths) When using an FSM for embedded system design. ⧫ V is a set of variables {v0. where: ⧫ Z is a set of states {z0.. two new features would be helpful: more complex data types (such as integers or floating point numbers).. ⧫ X is a set of inputs {x0. z0>. . mapping current states to outputs (Z → Y). This model is sufficient for purely control systems that do not input or output data.. (Z x X → Y) ⧫  is an output function.. and variables to store data. X.. xm}. However. and the functions therefore represent boolean functions with boolean operations. and ⧫ z0 is an initial state. <Z... . when we must deal with data. . . zl}. y1. vn}.. mapping states and inputs to states. An FSMD is a 7-tuple. İzmir Institute of Technology Real-Time and Embedded System Design .. yn}. v1. the inputs and outputs represent boolean data types. . x1. . z1.. transitions)..

not only boolean operations. FSMD (Finite-state machines with datapaths)  Various data types are allowed (like the ones in a typical programming language)  During execution of the model. the complete system state consists not only of the current state. but also the values of all variables  and  includes arithmetic operations. İzmir Institute of Technology Real-Time and Embedded System Design .   also includes variable updates.

3. to other states. 4. ensure that exiting transition conditions are exclusive (no two conditions could be true simultaneously) and complete (one of the conditions is true at any time). giving each a descriptive name. Describing a system as a state machine 1. For each state and/or transition. with associated conditions. Declare all variables. 2. İzmir Institute of Technology Real-Time and Embedded System Design . list the possible transitions. For each state. list the associated actions 5. For each state. List all possible states.

The inputs are a sensor for the seat to know when a person has sat down. a seat belt sensor that tells when the belt is fastened. The output is the buzzer seat 1: person sat down timer_on 0: no person Seat belt controller belt 1: seat belt fastened buzzer 0: not fastened timer 1: expired 0: not expired İzmir Institute of Technology Real-Time and Embedded System Design . This system has three inputs and one output. State Machine in C Design a Simple Seat Belt Controller: The controller's job is to turn on a buzzer if a person sits in a seat and does not fasten the seat belt within a fixed amount of time. and a timer that goes off when the required time interval has elapsed.

State Diagram for the Seat Belt Controller İzmir Institute of Technology Real-Time and Embedded System Design .

else if(!seat) state=IDLE. case BUZZER: while(1) FSM().} break. if(belt) state=BELTED. } break. timer_on=1. else if(timer) state=BUZZER. State diagram case SEATED: if(belt) state=BELTED. C Code: #define IDLE 0 #define SEATED 1 #define BELTED 2 #define BUZZER 3 void FSM() { switch(state) { case IDLE: if(seat) {state=SEATED. case BELTED: if(!seat) state=IDLE. } } İzmir Institute of Technology Real-Time and Embedded System Design . void main() else if(!belt) state=SEATED. break. { break.

must be run in concurrency. This requires many transitions in the diagram. (b) same example with hierarchy. (a) three-state example without hierarchy. (c) concurrency. İzmir Institute of Technology Real-Time and Embedded System Design . Seatbelt controller. assume that any state goes to a newly defined state when a pust button is pressed. cruise controller etc. Adding Hierarchy/Concurrency:HCFSM In the seatbelt controller example.

as well as including the hierarchy and concurrency extensions of HCFSM. İzmir Institute of Technology Real-Time and Embedded System Design . Program State Machine (PSM) The program-state machine (PSM) model extends state machines to allow use of sequential program code to define a state’s actions (including extensions for complex data types and variables).

G. Assignment 2 1. V={SA. 2. 3. Write a C program running this FSMD and the seatbelt controller FSM concurrently. K} etc.) and draw the diagram. Write a C program implementing this FSMD. Construct an FSMD model of automobile cruise controller. İzmir Institute of Technology Real-Time and Embedded System Design . SD. Define the sets of FSMD (For example.