An important point is that any state diagram (and logic) that you use to
control a process should be related to the process and not to internal
computer program states or actions.  Make the state names represent states
of the process being controlled and name them accordingly.  For example,
Purging Vessel, Filling Vessel, Emptying Vessel, etc.  Don't confuse states
with tasks.  States relate to ongoing (usually not instantaneous) conditions
of the process (e.g. emptying tank or filling tank) and tasks relate to
process changes (e.g. open/close valves or start motors, read weight).

In the most general case, I use 4 asynchronous loops running in parallel and
accessing the same "Task" queue (which contains strings indicating which
task is to be executed).  First, I create the task queue, then insert the
first task, "Initialize".  The Task queue reference number output from the
Initialize Enqueue Element function is wired in parallel to each of the 4
loops.  This forces the loops to start after the Initialize task is
requested.  Not all of the Loops described below are needed for every
situation or program that is written.

LOOP DESCRIPTIONS
LOOP 1--Its job is to pop-up user interface windows.  After a user interface
window closes, this loop will typically request a task to be executed by
placing a string on the Task queue.  I use Loop 1 exclusively to handle
pop-ups so the other loops may continue to run without being interrupted by
pop-up windows.  If no pop-up windows are needed then this loop is not
present.


LOOP 2--This is the User Interface loop and contains an event structure that
responds to user push button requests or control value changes, etc.  When a
request is made, this loop appends a task request string to the Task queue.


LOOP 3--This is the State Diagram loop and it implements the state logic
using strings for the state values.  A shift register on this loop carries
the state string descriptors.  Each state can call for tasks by placing a
task string on the Task queue.

The State Diagram loop may contain states such as: Idle; Initialize;
Filling; Emptying; Create Report.  There is very little logic required to do
these tasks within the state diagram loop.  Its job is to keep track of the
status (state) of the process being controlled and to monitor analog and
digital inputs and to call for needed Tasks to be executed by the Task
Execution loop.

Each state in the State Diagram loop usually contains a case statement with
T/F cases.  The True case has logic for the first time the state is entered.
The False case contains logic for normal operation in the state.  You can
detect the first time entering a state by comparing the current state with
the last state by adding an extra element to the state shift register.  When
they are not equal then this is the first time in the state.


LOOP 4--This is the Task Execution loop.  It is the only one of the 4 loops
that can cause things to happen directly.  It continually monitors and
removes the Task queue strings that are placed on the Task queue by the
other loops and performs the corresponding tasks.  Typical tasks done are:
moving process actuators, reading non-scanned inputs like weigh scales,
plotting, saving to disk, printing reports, and updating screen controls.

Frequently, there are several tasks that must be executed in sequence.  For
example, assume that after Task 1 is done that Task 2 must immediately be
started.  This can be accomplished entirely within Task1, by placing a Task
2 string on the Task queue as part of the Task 1 logic.  This eliminates the
need for the logic in Loops 1,2 and 3 to place both Task1 and Task 2 on the
Task queue.  Of course, Task 1 can be skipped when Task 2 is directly
requested by Loops 1, 2 and 3.

In some cases, you may want the state transition logic (or other loops) to
wait for all active tasks to be completed before moving to the next state.
You can accomplish this by setting a Busy Boolean flag True when the Task
Execution loop is processing tasks and clearing it when the Task loop is
idle.


I've found this architecture to be quite flexible.  It is the basis for most
of my high level programs.

Lewis Drake
Process Automation Corporation
Belle Mead, NJ
908 359-1011
www.processauto.com



Reply via email to