ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

The State Machine for Everyone

Updated on May 3, 2017

State Machine is a technical term commonly used in computer design and Computer Science . It is a programming and designing technique where a complex and repetitive task is broken down into smaller and definable pieces called states . By executing these states in precise step and timing, the complex task can be resolved in a satisfactory and exact fashion repeatedly without error.

The omnipotent computer can be considered to be built of state machines. We use computer to solve the same complex tasks precisely and repeatedly without error . The State Machine is the perfect tool and algorithm to accomplish it.

Other Applications

Outside of the computer design and Computer Science, similar state machine technique can also be observed in:


1) Genetics

A gene 's open reading frame (ORF) is the series of codons (3 DNA bases) that specify the amino acid sequence of that gene's protein . The ORF begins with the initiation codon (usually ATG) and ends with a termination codon (TAA, TAG, TGA).

2) Washing machine

Drop clothes into tank, add water and detergent, stir, rinse, and spin.


3) Refrigerator

In the cooling process, liquid Freon is pumped into a set of coils, turns to gas, and absorbs heat. In the dissipating process, gaseous Freon is compressed into a set of coils, turns to liquid, and gives off heat.


4) Internal-Combustion Engine

Crankshaft position 1: intake valve open, enters air/fuel mixture.

Crankshaft position 2: compressing air/fuel mixture.

Crankshaft position 3: firing the spark plug to ignite air/fuel mixture and forcing the Crankshaft down.

Crankshaft position 4: exhaust valve open, out goes the exhaust gases.

Basic Principle

The state machine starts with an initial state (also called the idle state) where it is waiting for the occurrence of an input condition . Just like the washing machine, the washing cycle starts when the Control Dial on the panel is being set to the start of the cycle by the operator.

When the first input condition is active, the state machine goes to the 2nd state where a set of pre-defined functions are executed. It stays in this state till the occurrence of another input condition. Just like the washing machine, it starts to add water to the clothes in the tank.

When the 2nd input condition is active, the state machine goes to the 3rd state and so on till it reaches the last state to complete the pre-defined task. After that, the state machine returns to the initial state. Just like the washing machine, after the water reaches the desired level, it executes the stirring function. After a pre-set timer has expired, the washing machine goes to the rinse and spin cycles in similar fashion till the washing cycle is completed. It then returns to its initial state waiting for the next batch of clothes to be washed.


Working out the Bugs

Bringing up the very first washing machine, adjustments are needed to each cycle in order to achieve the cleanest clothes using the least amount of water and the minimum amount of time. After the state machine completes its preliminary design, for a simple and non-critical task, it can be immediately applied, checked, and adjusted for its accuracy on the job . For a critical or complex task, it is more practical to test the design in a simulated laboratory environment. The present-day microprocessor inside a computer can be considered as a complex state machine. It can take several hundred engineers and several years to design, debug , and build.

Practical Example

In the daily routine , we can apply the state machine technique to the cooking of a favorite dish. In order to cook a particular dish in the minimum amount of time and effort but with a consistent flavor and taste , the following general states need to be considered:

1) Prepare a list of the ingredients with the exact quantity and seasonings.

2) Define the exact time the heat that needs to be applied to the ingredients before adding seasonings.

3) Define how the ingredients are to be stirred and mixed.

4) Define how long to wait for the seasonings to be absorbed by the ingredients before the dish is ready to serve.

To work out the details, it takes time and practice. But, it is essential to document them. When the desired results are repeatedly consistent, this cooking state machine is completed. In the future, all you have to do to cook this particular dish is to execute this cooking state machine to the letter.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)