State diagrams are a useful way of representing your state machines. Unfortunately, they can be difficult to develop. It often takes a considerable amount of time to make a visually appealing sketch.
One solution is to use the Latex typesetting program. In some ways \LaTeX is like your favorite word processor. The difference is that the formatting is controlled using textual descriptions. Also, all original documents are completed in .txt or .tex files. When they are complete, a tex “compiler” is this used to produce the finished product, typically in the form of a .pdf document. In some respects, it is like developing web pages using html.
The beauty of \LaTeX is its ability to stitch together complex documents leveraging all of scripts and tricks available to a programmer. There is also something to be said about the utility and open nature of the underlying plain text documents.
\LaTeX packages such tikz make the process of rendering state tables relatively easy with representative results such as shown in Figures 1 and 2. The associated code is attached to the end of this note. These images were rendered using TeXworks.
Tech Tip: This TechForum has limited support for \LaTeX. This is especially useful for displaying math equations. For example, Ohm’s law is written as R = \dfrac{E}{I} which is then placed between two $ symbols to yield:
R = \dfrac{E}{I}
Unfortunately, the learning curve for \LaTeX is steep. Consequently, we will not attempt to describe the process in this short article. Instead, the code used to generate Figures 1 and 2 is appended to this note without comment in the hope that it will be useful.
Best Wishes,
APDahlen
P.S. If you are interested in \LaTeX please look for online tutorials. Also, be sure to look for online pages that allow you see the rendered text.
Figure 1: State diagram for a simple CAM operated state machine featuring a reset.
Figure 2: State diagram for a machine featuring complex state transitions.
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{
letterpaper,
% total={170mm,257mm},
left=0.5in,
right =0.5in,
top=0.5in,
bottom=0.75in
}
\begin{document}
\begin{tikzpicture} [state/.style=state with output, ->,>=stealth',shorten >=1pt,auto,node distance=5.0cm, semithick]
\tikzstyle{every state}=[fill=blue!20,draw=black,text=black]
\node[initial,state] (1) {$Idle$ \nodepart{lower} $0000001$};
\node[state] (2) [above right of = 1] {$Alarm$ \nodepart{lower} $0010010$};
\node[state] (3) [right of = 2] {$Forward$ \nodepart{lower} $1000110$};
\node[state] (4) [below right of = 3] {$Delay$ \nodepart{lower} $0001010$};
\node[state] (5) [below left of = 4] {$Alarm$ \nodepart{lower} $0010010$};
\node[state] (6) [left of = 5] {$Reverse$ \nodepart{lower} $0100110$};
\path (1) edge [sloped, anchor=center, above, in=205, out= 65] node {Cycle PB} (2)
(2) edge [sloped, anchor=center, above, in=160, out= 20] node {Done} (3)
edge [sloped, anchor=center, below, in=20, out=-110] node {$Reset$} (1)
(3) edge [sloped, anchor=center, above, in=110, out=-20] node {5 seconds} (4)
edge [sloped, anchor=center, below, in=10, out=-135] node {$Reset$} (1)
(4) edge [sloped, anchor=center, below , in=20, out=-110] node {$3 seconds$} (5)
edge [sloped, anchor=center, below, in=-10, out=200] node {$Reset$} (1)
(5) edge [sloped, anchor=center, below, in=-20, out=200] node {Done} (6)
edge [sloped, anchor=center, below, in=-20, out=160] node {$Reset$} (1)
(6) edge [sloped, anchor=center, below, in=-70, out=155] node {5 seconds} (1)
edge [sloped, anchor=center, below, in=-30, out=110] node {$Reset$} (1)
; % Don't forget this semicolon
\end{tikzpicture}
\newpage
\begin{tikzpicture} [state/.style=state with output, ->,>=stealth',shorten >=1pt,auto,node distance=5.0cm, semithick]
\tikzstyle{every state}=[fill=blue!20,draw=black,text=black]
\node[initial,state] (1) {$1$ \nodepart{lower} $Retracting$};
\node[state] (2) [above right of=1] {$2$ \nodepart{lower} $Retracted$};
\node[state] (3) [below right of=2] {$3$ \nodepart{lower} $Extending$};
\node[state] (4) [below left of=3] {$4$ \nodepart{lower} $Extended$};
\node[state] (5) [below of=4] {$5$ \nodepart{lower} $Fault$};
\path (1) edge [sloped, anchor=center, above] node {xSenRet} (2)
edge [sloped, anchor=center, below, in=200, out=-20] node {$xEN$} (3)
edge [sloped, anchor=center, below, bend right] node {t $>$ timeMove} (5)
(2) edge [sloped, anchor=center, above] node {xEn} (3)
edge [sloped, anchor=center, below, min distance=7cm, in=10, out=-10] node {$\overline{xSenRet}$} (5)
(3) edge [sloped, anchor=center, above] node {xSenExt} (4)
edge [sloped, anchor=center, above, in=20, out=160] node {$\overline{xEN}$} (1)
edge [sloped, anchor=center, below, bend left] node {t $>$ timeMove} (5)
(4) edge [sloped, anchor=center, above] node {$\overline{xEN}$} (1)
edge [sloped, anchor=center, below] node {$\overline{xSenExt}$} (5)
(5) edge [sloped, anchor=center, below, min distance=2.5cm, in=230, out=170] node {xReset} (1)
; % Don't forget this semicolon
\end{tikzpicture}
\end{document}