Electronic Design

Take Your Next Design From Statecharts To Code

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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish