User's Manual

PMAC User Manual
Writing a PLC Program 239
Executing Integer Arithmetic
The compiled PLCs have the capability to perform arithmetic and logical operations in 24-bit signed
integer form. By contrast, all arithmetic and logical operations in uncompiled PLC programs are
performed in 48-bit floating-point form, even if acting on integer variables. The short integer math
operations execute at least 10 times faster than the floating-point operations. Combined with the two to
three times improvement from compilation, this provides execution 20 to 30 times faster than uncompiled
floating-point operations.
A compiled PLC program can have some statements that are executed using integer arithmetic and other
statements that are executed using floating-point arithmetic. However, a given statement within the
compiled PLC is executed either entirely with integer arithmetic or entirely with floating-point arithmetic
(even if it is working with integer registers).
Using L-Variables
The use of L-variables in a PLC program statement is the sign to the compiler that the statement is to be
executed using integer operations instead of floating-point operations. L-variables can be used in two
types of statements in compiled PLCs: variable value assignment statements, and conditional statements
(IF, WHILE, AND, OR).
Creating L-Variables
To implement integer arithmetic in a compiled PLC, define any L-variables to be used and substitute
them in the programs for the variables that were used in the interpreted form (usually M-variables). The
compiler will interpret statements containing only L-variables (properly defined) and integer constants as
operations to be executed using integer arithmetic in compiled PLCs.
L-variables are defined like X- or Y-format M-variables, but they exist only for the compiler. PMAC
does not recognize L-variables or L-variable definitions, and PMAC will reject any uncompiled command
containing an L-variable that is sent to it. All L-variable definitions must precede the first PLC program
to be compiled in the file.
Legal L-variable names for the compiler contain the letter L followed by an integer in the range 0 to 1023,
for a total of 1024 possible L-variables (L0 to L1023).
Put all of the L-variable definition statements in a separate file that will be combined with the main PLC
file using the #include statement (e.g. #include lvardef.pmc). This single line can be
commented out with a semicolon while debugging the programs in interpreted mode. Remember that if
using a standalone compiler, this definition file must be combined with the main file into a single file
before the compiler can run. A compiler running as part of the CNC Executive or the PMAC Executive
will combine these automatically, if using a single main load file, which includes all of the other files.
For variables referencing fixed locations in the PMAC memory and I/O space, the L-variables will simply
replace M-variables, and the L-variable definition will be made exactly like the M-variable definitions. It
is acceptable to retain the M-variable definition as well. Retain the M-variable definitions for debugging
purposes because PMAC will not accept a query command for the value or definition of an L-variable.
For example, Machine Output 1 and Machine Input 1 on the JOPTO port are typically referenced by the
following definitions in uncompiled programs:
M1->Y:$FFC2,8 ; Machine Output 1
M11->Y:$FFC2,0 ; Machine Input 1
For the compiled PLC programs, you could create equivalent M-variable definitions:
L1->Y:$FFC2,8 ; Machine Output 1
L11->Y:$FFC2,0 ; Machine Input 1