{"id":3199,"date":"2012-06-18T10:25:15","date_gmt":"2012-06-18T09:25:15","guid":{"rendered":"https:\/\/blogs.mentor.com\/colinwalls\/?p=3199"},"modified":"2026-03-26T16:37:57","modified_gmt":"2026-03-26T20:37:57","slug":"in-a-state","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/embedded-software\/2012\/06\/18\/in-a-state\/","title":{"rendered":"In a state"},"content":{"rendered":"<p>Once again, I am going to look at a topic helpfully suggested by my colleague Rizwan Rasheed. Unless you have used <a href=\"http:\/\/www.mentor.com\/products\/sm\/model_development\/bridgepoint\/\" target=\"_blank\" rel=\"noopener noreferrer\">UML<\/a>, or a similar tool\/methodology, you may not have encountered state machines.<\/p>\n<p>Although they are the basis of some formal methodologies, the concept of a state machine can be used by itself as an approach to program design, which, IMHO, is particularly appropriate to many embedded applications &#8230;<!--more--><\/p>\n<p>When I first heard the term, I was confused by the word &#8220;machine&#8221;. Of course, we are not talking about a mechanical device at all, but a conceptual one. The concept is quite simple and can be summed up in a few statements:<\/p>\n<ul>\n<li>At any time a system is in a particular state.<\/li>\n<li>Specific, precisely-defined events can result in the system moving to another state.<\/li>\n<li>A sequence of actions may be performed on entry of a new state.<\/li>\n<\/ul>\n<p>A &#8220;system&#8221; could be anything, but we are only really concerned with software. However, for an embedded system, taking a more holistic view &#8211; i.e. software and hardware &#8211; might lead to better design.<\/p>\n<p>The usual tool that is applied to designing systems is a state transition diagram. Each state is represented by a box, which may contain a description of the entry actions, and transitions between states are represented by arrows\/lines.<\/p>\n<p>To illustrate the concept, I will talk about a commonly used example; a microwave oven.<\/p>\n<ul>\n<li>The starting state is &#8220;door closed, oven off&#8221;. There are 2 events that can trigger transitions out of this state: opening the door or starting the oven.<\/li>\n<li>If the state becomes &#8220;door open&#8221;, the entry actions might be to turn off the magnetron [to be sure!] and turn on the light. The only transition could be back to &#8220;door closed, oven off&#8221;, when the entry action would be to turn off the light.<\/li>\n<li>If the state becomes &#8220;cooking&#8221;, the entry actions might be to turn on the magnetron and the light. The possible triggers for a state transition might be the user stopping the microwave or opening the door.<\/li>\n<\/ul>\n<p>Hopefully, you get the idea.<\/p>\n<p>To me, the attraction of thinking in terms of states is that it maps well onto the usage of many embedded devices. The stimulus to state transition is commonly a user action, so a clean design can come out of careful consideration of what a user might [want to] do in any given situation. A state transition diagram is also a concise and precise way to describe the [required] functionality of a system and can map directly on to the implementation, thus increasing the likelihood that the product will behave in the way the designer intended.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once again, I am going to look at a topic helpfully suggested by my colleague Rizwan Rasheed. Unless you have&#8230;<\/p>\n","protected":false},"author":71677,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1],"tags":[300,472,473,474],"industry":[],"product":[],"coauthors":[],"class_list":["post-3199","post","type-post","status-publish","format-standard","hentry","category-news","tag-embedded-software","tag-state-machine","tag-state-transition-diagram","tag-uml"],"_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/3199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/users\/71677"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/comments?post=3199"}],"version-history":[{"count":1,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/3199\/revisions"}],"predecessor-version":[{"id":10076,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/3199\/revisions\/10076"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/media?parent=3199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/categories?post=3199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/tags?post=3199"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/industry?post=3199"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/product?post=3199"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/coauthors?post=3199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}