User's Manual

PMAC User Manual
240 Writing a PLC Program
A small routine in a compiled PLC to make Machine Output 1 follow Machine Input 1 would be:
IF (L11=1)
L1=1
ELSE
L1=0
ENDIF
It is acceptable to access a register in one program statement with an L-variable, and then access the same
register, even the same part of the register, in another program statement with an integer M-variable or I-
variable. Mixing L-variable access and P- or Q-variable access to a P- or Q-variable register will yield
nonsensical results, because the P- and Q-variable access always treats the register as a floating-point
number.
For general-purpose integer variables, the L-variables will probably replace what was previously done
with P-variables in the program. Since L-variables must be defined to a specific address, it is important to
find open areas of PMAC memory to hold these variables. To make this easier, declare a User buffer on
PMAC with the DEFINE UBUFFER {size} command, where {size} represents the number of 48-
bit words of PMAC memory to be reserved for this buffer. The buffer starts at address $9FFF and
continues back toward the start of memory for the specified number of words. For example, the
command DEFINE UBUFFER 256 reserves addresses $9F00 to $9FFF, both X and Y registers, for user
use, including L-variables.
A user buffer cannot be created if there is already any buffer in PMAC that was created with a DEFINE
command (rotary program, leadscrew comp, etc.). It is easiest to create the user buffer immediately after
re-initializing the card with a $$$*** command.
Debug these programs using integer M-variables assigned to user buffer registers as the general-purpose
variables, instead of P-variables. This will make the changeover to compiled integer form easier.
If there are just a few general-purpose L-variables, use the open memory areas $0770 to $077F, and
$07F0 to $07FF (both X and Y registers.)
Remember that because the L-variable definitions are used only at the time of compilation, it is not
possible to use the array indexing techniques with L-variables that can be performed using M-variables by
changing the definitions at run time.
Variable Value Assignment Statements
Variable value assignment statements are used by PMAC to write to any register, whether an output, a
general-purpose variable in memory, a memory register used for a specific purpose, such as a gain, or a
hardware register, such as a flag-control register. Many of these statements can be executed using integer
arithmetic.
Valid Values
In a given variable value assignment statement ({variable}={expression}), L-variables cannot
be combined with any other type of variable; that is, if there is any L-variable in the statement, all
variables in the statement, on both sides of the equals sign, must be L-variables. Any constants in the
statement must be integers in the range -8,388,608 to 8,388,607 (-2
23
to 2
23
-1).
Any variable-value assignment statement in a compiled PLC containing an L-variable that also contains
another type of variable, a non-integer constant, or an integer constant outside the range -2
23
to 2
23
-1 will
be rejected by the compiler. The compiler will report the error and line number.