Lecture 03-IoT
Understanding State Machines and Statecharts
Statecharts/State Machines
Used for modeling the behavior of objects
Derived from the Unified Modeling Language (UML) standard
Key Components:
Identify inputs
Identify outputs
Identify possible states
Create State Machine (or Finite State Machine)
Definition of State Machine
A State Machine is a computational model with:
Behavior that depends not only on the current input but also on some history of prior inputs.
Characterized by an internal state that represents this history.
Example:
If the phone is ON and a button is pressed, it turns OFF; if OFF, it turns ON.
Demonstrates the concept of states:
Possible states include ON and OFF with transitions managed by events.
Finite State Machines (FSM)
FSM Implementation:
Two primary representations:
State Diagram
Algorithmic State Machine
Types of State Machines:
Mealy State Machine: Outputs depend on both current states and inputs.
Moore State Machine: Outputs depend only on the current state.
Actions in State Machines
State changes can trigger actions:
Example: State transition from OFF to ON might print a message or activate a device.
Extended State Machines
Extended State Machines:
Include variables and complex states.
Example: Utilizing an integer variable
cthat increments during state transitions.
Example: Traffic Signal Controller
Main road remains green, while the minor road is red until a car is detected.
Upon detection:
Change state, start timer; assert
TIMEDsignal at the end.
State Diagrams and Algorithmic State Charts (ASM)
ASM
ASM Characteristics:
State box: Represents a state (unconditional outputs).
Decision box: Determines transitions based on conditions.
Conditional output box: Outputs based on the decision made.
Comparing Mealy and Moore Machines
Mealy Machine:
Fewer states possible due to immediate output response.
Vulnerable to transient glitches in inputs.
Output may change without waiting for the next clock pulse.
Moore Machine:
More states due to output only reacting to state changes.
Synchronous outputs with no glitches, stable value at all times.
Design and Implementation Examples
Mechanical Ride Example
States:
OFF: Motor off.
ON: Motor at 50% speed (after button press); times out after 20 seconds to revert to OFF.
Fan Control Example
States:
Idle
Slow Speed
Medium Speed
Fast Speed
Each state corresponds with specific LED indications and motor speeds (30%, 60%, 100%).
Traffic Light System
States:
Green: On for 30 seconds, then blinks before changing.
Yellow: On for 4 seconds.
Red: On for 30 seconds before cycling back to Green.
Statecharts/State Machines - Used for modeling the behavior of objects - Derived from the Unified Modeling Language (UML) standard - Key Components: - Identify inputs - Identify outputs - Identify possible states - Create State Machine (or Finite State Machine)
A State Machine is a computational model with: - Behavior that depends not only on the current input but also on some history of prior inputs. - Characterized by an internal state that represents this history. - Example: - If the phone is ON and a button is pressed, it turns OFF; if OFF, it turns ON. - Demonstrates the concept of states: - Possible states include ON and OFF with transitions managed by events.
FSM Implementation: - Two primary representations: - State Diagram - Algorithmic State Machine - Types of State Machines: - Mealy State Machine: Outputs depend on both current states and inputs. - Moore State Machine: Outputs depend only on the current state.
State changes can trigger actions: - Example: State transition from OFF to ON might print a message or activate a device.
Extended State Machines: - Include variables and complex states. - Example: Utilizing an integer variable
cthat increments during state transitions.Main road remains green, while the minor road is red until a car is detected. - Upon detection: - Change state, start timer; assert
TIMEDsignal at the end.
ASM
ASM Characteristics: - State box: Represents a state (unconditional outputs). - Decision box: Determines transitions based on conditions. - Conditional output box: Outputs based on the decision made.
Mealy Machine: - Fewer states possible due to immediate output response. - Vulnerable to transient glitches in inputs. - Output may change without waiting for the next clock pulse.
Moore Machine: - More states due to output only reacting to state changes. - Synchronous outputs with no glitches, stable value at all times.
Design and Implementation Examples
Mechanical Ride Example: - States: - OFF: Motor off. - ON: Motor at 50% speed (after button press); times out after 20 seconds to revert to OFF.
Fan Control Example: - States: - Idle - Slow Speed - Medium Speed - Fast Speed - Each state corresponds with specific LED indications and motor speeds (30%, 60%, 100%).
Traffic Light System: - States: - Green: On for 30 seconds, then blinks before changing. - Yellow: On for 4 seconds. - Red: On for 30 seconds before cycling back to Green.