User's Manual

PMAC User Manual
Writing Programs for PMAC 201
DWELL(P5)
P1=P1+1
ENDWHILE
The variables P2, P3, P4, and P5 could be set by the host with on-line commands (e.g. P2=2000) by a
PLC program because of inputs and/or calculations, or even by another motion program.
With calculations inside the motion program, we can get even more sophisticated. General mathematical
expressions can be built in a PMAC motion program using constants, variables, functions and operators
(see Computational Features). The calculations can be done in separate program statements, assigning the
calculated value to a variable, and then using the variable in another statement. Alternately, the
expression can be used directly in a motion specification statement, in which case the value of the
expression is not retained after the statement is executed.
Subroutines and Subprograms
It is possible to create subroutines and subprograms in PMAC motion programs to create well-structured
modular programs with re-usable subroutines. The GOSUBx command in a motion program causes a
jump to line label Nx of the same motion program. Program execution will jump back to the command
immediately following the GOSUB when a RETURN command is encountered. This creates a subroutine.
The CALLx command in a motion program causes a jump to PROG x, with a jump back to the command
immediately following the CALL when a RETURN command is encountered. If x is an integer, the jump
is to the beginning of PROG x; if there is a fractional component to x, the jump is to line label
N(y*100,000), where y is the fractional part of x. This structure permits the creation of special
subprograms, either as a single subroutine, or as a collection of subroutines, that can be called from other
motion programs.
Passing Arguments to Subroutines
These subprogram calls are made more powerful by use of the READ statement. The READ statement in
the subprogram can go back up to the calling line and pick off values (associated with other letters) to be
used as arguments in the subprogram. The value after an A would be placed in variable Q101 for the
coordinate system executing the program, the value after a B would be placed in Q102, and so on (Z
value goes in Q126).
This structure is useful for creating machine-tool style programs, in which the syntax must consist solely
of letter-number combinations in the parts program. Since PMAC treats the G, M, T, and D codes as
special subroutine calls (see below), the READ statement can be used to let the subroutine access values
on the part-program line after the code.
Example:
For example, the command CALL500 X10 Y20 causes a jump to the top of PROG 500. If, at the top
of PROG 500, there is the command READ(X,Y), the value with X will be assigned to Q124 (X is the
24th letter) and the value with Y will be assigned to Q125. Now the subroutine can work with the values
of Q124 and Q125 (in this case, 10 and 20, respectively), processing them as needed.
What Has Been Passed?
The READ statement also provides the capability of seeing what arguments have been passed (the letters
listed in the READ statement are those that can be passed). The bits of Q100 for the coordinate system are
used to note whether arguments have been passed successfully; bit 0 is 1 if an A argument has been
passed, bit 1 is 1 if a B argument has been passed, and so on, with bit 25 set to 1 if a Z argument has been
passed. The corresponding bit for any argument not passed in the latest subroutine or subprogram call is
set to 0.