FSM Lecture 1- Introduction to Finite State Machine

  • Post author:
  • Post category:Blog

 

Introduction to Finite State Machine

 

 

Finite State Machine(FSM)

  • A state machine is a software computation model. It’s just a model to solve a complex application, and it comprises a finite number of states. Hence it is also called a Finite State Machine. States are nothing but situations of your application (different situations).
  • Since states are finite, there is a finite number of transitions among the states. Transitions are triggered by the incidents or input events fed to the state machine. An FSM is an event-driven reactive system.
  • A state machine also produces an output. The output produced depends on the current state of the state machine sometimes, and sometimes it also depends on the input events fed to the state machine.
Figure 1. Flat state machine
Figure 1. Flat state machine

Figure 1 shows a Flat state machine. There are different types of state machines, like Flat state machines, Hierarchical state machines, and various other things.

In figure 1, you can see that there are various states, which are interconnected. And these states represent different situations of the application. 

 

Figure 2. Situation representation of a state
Figure 2. Situation representation of a state

In figure 2, the red color line shows the situation represented as a state in the state machine diagram, which handles different events and it may produce different outputs.

 

Figure 3. Interconnections between states
Figure 3. Interconnections between states

Figure 3 shows there are various interconnections between the states. These are called Transitions. And transitions are caused because of an event, which is received by the state machine.

Since the application moves between different states, producing various outputs and processing various events, this may be called a state machine. It is drawn using the syntax of UML state machine specification, and we will be using the UML specification throughout this course.

 

Benefits of using state machines:

  • It is used to describe situations or scenarios of your application (Modelling the lifecycle of a reactive object through interconnections of states.
  • FSMs are helpful to model complex applications that involve lots of decision-making, producing different outputs, and processing various events.
  • State machines are visualized through state machine diagrams in the form of state charts, which helps to communicate between non-developers and developers.
  • FSM makes it easier to visualize and implement the changes to the behavior of the project.
  • Complex application can be visualized as a collection of different states processing a fixed set of events and producing a fixed set of outputs. 
  • Loose coupling: An application can be divided into multiple behaviors or state machines, and each unit can be tested separately or could be reused in other applications.
  • Easy debugging and easy code maintenance.
  • Scalable
  • Narrow down the whole application completely to state-level complexity, analyze and implement.

 

Different types of state machines:

  1. Mealy machine
  2. Moore machine
  3. Harel state charts
  4. UML state machines

Some of these state machines are used for software engineering, and some state machines are still being used in digital electronics, VLSI design, etc.

 

In this article, we are interested in UML state machines. Because this state machine is predominantly used in software engineering to model software engineering problems. It is influenced by David Harel’s statechart formalism.

Various tools available in the market can interpret your UML statecharts and generate the base-level code. That is the advantage of using UML specification-based state machine diagrams. You can auto-generate the code in C or C++, or Java using some of these tools.

 

UML Modelling tool and code generator

  • Rhapsody® by IBM®
  • QM™ Model-based design tool by Quantum Leaps, LLC
  • Visual State by IAR
  • Yakindu state chart tools by Itemis AG

Some are paid tools, and some are open-source. These tools can interpret your model and can auto-generate the code. 

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.