User's Manual

PMAC User Manual
Writing a PLC Program 233
WRITING A PLC PROGRAM
PLC Programs
In addition to the motion programs, which operate sequentially and synchronously in time (any move
command takes a specified amount to execute before succeeding program lines are executed) PMAC has
64 PLC programs that operate asynchronously and with rapid repetition (32 compiled PLC programs as
well as 32 uncompiled PLC programs). They are called PLC programs because they perform many of the
same functions as hardware programmable logic controllers. PLC programs have most of the same
logical constructs as the motion programs, but no move-type statements.
Most compiled PLC programs are very similar, if not identical to uncompiled PLC programs. In fact,
before compiling a PLC program, it should be tested and debugged as an uncompiled PLC. The
differences between the two types of PLC programs are in the area of buffer control, L-variables, some
command syntax, and the use of the compiler. Because of these similarities, much of the section about
uncompiled PLC programs also applies to compiled PLC programs. The information specifically
concerning compiled PLC programs is contained in the section entitled Compiled PLC Programs.
When to Use
PLC programs are designed for actions that are asynchronous to the motion. If the action you want is
synchronous to the programmed motion (e.g. once per move), use a motion program instead to create the
action.
Common Uses
PLC programs are particularly useful for monitoring analog and digital inputs, setting outputs, sending
messages, and monitoring motion parameters, issuing commands as if from a host, changing gains, and
starting and stopping moves. By their complete access to PMAC variables and I/O and their asynchronous
nature, they become powerful adjuncts to the motion control programs.
32 PLC Programs
PLC programs are numbered 0 through 31 for both the compiled and uncompiled PLCs. This means that
both a compiled PLC n and an uncompiled PLC n can be stored in PMAC. PLC program 0 is a special
fast program that operates at the end of the servo interrupt cycle with a frequency specified by variable I8
(every I8+1 servo cycles). This program is meant for a few time-critical tasks, and it should be kept
small, because its rapid repetition can steal time from other tasks.
Caution:
A PLC 0 that is too large can cause unpredictable behavior and can even trip the
PMAC Watchdog Timer by starving background tasks of time to execute.
PLC programs 1 through 31 operate continually in background as time allows, effectively in an infinite
loop. They get interrupted by the higher priority tasks of motor phasing, servo loop closure, more
planning, and PLC 0.
Entering a PLC Program
The PLC program statements are entered as buffered command lines into PMAC. In preparation, it is a
good idea to make sure no other buffers have been left open by issuing a CLOSE command. It is also
good practice to make sure that memory has not been tied up in data gathering or program trace buffers,
by issuing DELETE GATHER and DELETE TRACE commands.