# [SOLVED]FSM in embedded systems

#### Pushkar1

Joined Apr 5, 2021
416
I have been visited many tutorials to understand what is FSM ( Finite state machine ) in embedded systems. I am trying to understand what is FSM in embedded systems.

Is LED a FSM system?
Is Switch a FSM system?
Is motor a FSM system?

I'm looking for explanation if these are FSM so why do you consider FSM and if all these are not FSM so what's reason and why don't you consider FSM.

#### Papabravo

Joined Feb 24, 2006
20,626
A Finite State Machine is an abstract concept, or a thought experiment (In German a "Gedanken-experiment"). A collection of real components can implement the behavior of the FSM machine, but the machine itself remains an abstraction.
In simple terms an FSM consists of:
1. A finite number of states
2. A finite number of inputs
3. A finite number of outputs
4. A state transition matrix, or state transition diagram
Within that broad definition there are two subspecies of FSM called the Mealy Machine, and the Moore Machine. Each of these is named after the inventors:
George H. Mealy(1955 paper), and Edward F. More(1956 paper).
In the Moore machine, the outputs are a function of the state alone.
In the Mealy machine, the outputs are a function of the transitions from one state to another.

It can be shown that the behaviors of the two machine are equivalent, that is they can each implement the behavior of the other. One implementation may require less actual hardware than the other.
In practice they can be implemented in hardware or in the program of a suitably constructed processor.

#### Pushkar1

Joined Apr 5, 2021
416
@Papabravo excellent explanation. FSM depends on the behavior of system
There are the two important parts of state machine that are states and transitions.

I don't know one point if we have requirements of system how do we decide how many states can be in system.

#### Papabravo

Joined Feb 24, 2006
20,626
@Papabravo excellent explanation. FSM depends on the behavior of system
There are the two important parts of state machine that are states and transitions.

I don't know one point if we have requirements of system how do we decide how many states can be in system.
It is possible to have machines perform the same function and have different numbers of states. Redundant states are certainly possible and sometimes desirable for other reasons. An examples would be to detect invalid states and take some recovery action. The abstract state diagram has no way to enter an invalid state, but a real implementation might have a way to get to one and you need to provide a transition from the invalid state to a valid one. That said, you can argue that for any given specification there is a machine with a minimum number of states. AFAIK there is no algorithm that can arrive at such a minimization.

#### Pushkar1

Joined Apr 5, 2021
416
@Papabravo I see three types of arrows in common finite state machine.

1. Circular arrow start from a state and end with same state

2. Arrow that start from one state and end with another state

3. Arrow start from other state and end with another state

What does circular arrow indicate in FSM? I think it show that system is in current state

What does two other arrow indicate in FSM?

#### Papabravo

Joined Feb 24, 2006
20,626
@Papabravo I see three types of arrows in common finite state machine.

1. Circular arrow start from a state and end with same state

2. Arrow that start from one state and end with another state

3. Arrow start from other state and end with another state

What does circular arrow indicate in FSM? I think it show that system is in current state

What does two other arrow indicate in FSM?
The circular arrow, mentioned in point 1., is used to HOLD the machine in a particular state, waiting for any condition to occur that would lead to a transition. A common programming example is waiting for a character to come in from a keyboard, or a communication channel. There is nothing to do, so at each 'tick' of the 'clock', you leave and renter the same state, in essence doing nothing, until a condition occurs which allows you to "temporarily" leave the "waiting for input" state.

I think the other two conditions are the same thing and represent different steps associated with 'sequences of inputs' in a particular order.

#### BobaMosfet

Joined Jul 1, 2009
2,102
I have been visited many tutorials to understand what is FSM ( Finite state machine ) in embedded systems. I am trying to understand what is FSM in embedded systems.

Is LED a FSM system?
Is Switch a FSM system?
Is motor a FSM system?

I'm looking for explanation if these are FSM so why do you consider FSM and if all these are not FSM so what's reason and why don't you consider FSM.
People tend to complicate this. Any STATE MACHINE is a process that is controlled by whatever STATE it happens to be in. For example, let's say you have a global variable 'STATE'. You set that to 'INPUT', and each procedure in your system checks that variable to see what STATE the process is currently in. If, after someone enters input and hits the <ENTER> button (or whatever), the STATE variable could change to STATE = PROCESSING. Then, as long as STATE is that way, the machine is in a PROCESSING state.

This, coupled with interrupts, events, and so for, makes for a very dynamic, lively system able to respond to whatever a user wants to do, at anytime.

#### BobTPH

Joined Jun 5, 2013
8,157