Take Your Next Design From Statecharts To Code

Oct. 2, 2008
They aren't just pretty pictures. These simple flow diagrams can help you convert your ideas into programs.
SOME BACKGROUND Also known as state diagrams, statecharts can be found on napkins and coding screens as designers turn ideas into application code. They’re simple to use and understand, as they’re just a bunch of “circles and arrows and a paragraph on the back of each one explainin’ what each one was, to be used as evidence against us,” to quote Arlo Guthrie and his classic song, “Alice’s Restaurant.” Events cause transitions between states, and most implementations allow actions based on transitions as well as within a state.INTRODUCTION State diagrams were used well before graphical tools were in place. But now, state diagrams are part of the development environment, with more advanced tools generating code directly. The diagrams from one tool look like those found in another, making it one of the more universal descriptive programming tools available. Check out the state of the latest tools.GO WITH THE FLOW Developed by the MathWorks, the Simulink graphical modeling environment incorporates event-driven state diagrams with its Stateflow module. It also incorporates deterministic execution semantics and can generate C code using the Stateflow Coder module. Additionally, it supports the Mealy and Moore finite-state machines. Stateflow can perform run-time checks to detect errors such as transition conflicts, cyclical problems, and state inconsistencies as well. For further details, see www.mathworks.com.FORMAL STATES The non-for-profit industry consortium Object Management Group (OMG) handles a range of standards, including UML (Unified Modeling Language). Within UML are state diagrams, the quintessential definition. The syntax and semantics are used throughout the industry, from basic diagramming tools to code-generating environments like IBM/Telelogic Rhapsody (see “UML And C No Longer Oil And Water,” ED Online 13985). State diagrams are just one of many modeling diagrams within the formal UML definition, but they’re almost universal when it comes to designers. Many slideshows mainly consist of state diagrams defining and application. Go to www.ibm.com and www.omg.org for more information.ADDING STATES TO GRAPHICAL APPS National Instruments’ LabVIEW graphical programming language and environment has been around for more than 20 years, but state diagrams are a rather recent addition (see “For Multicore Graphics Programming Support, Try LabVIEW 8.5” at ED Online 17116). The new StateChart feature is integrated with the existing graphical modeling environment, allowing states to contain LabVIEW code. State charts support the same type of graphical simulation and debugging as conventional LabVIEW virtual instrument models. Likewise, LabVIEW can generate C code or target FPGAs from applications that incorporate state diagrams. For more, see www.ni.com.

See Associated Figure

C STATES IAR’s visualState turns state charts into C/C++ code (see “What’s New In Programming Languages,” ED Online 14688). Integrated with the company’s Embedded Workbench C/C++ development environment, the tool is based on a subset of the UML (see “Formal States”). The C/C++ code is generic enough to be used with other platforms. But the system works best when combined with Embedded Workbench tools like the C-Spy debugger, which allows real-time feedback via the source diagrams. See www.iAr.com for details.

See Associated Figure

THE FINAL STATE Regardless of the development environment you choose, state diagrams can be incorporated into your design process.

About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!