User's Manual

PMAC User Manual
242 Writing a PLC Program
Examples of illegal integer statements:
L10=P10
P10=L10
L11=L11+P11
L13=16777216/L12
L253=L14*ATAN(L16)
Conditional Statements
In a conditional statement, any simple condition ({expression} {comparator}
{expression}) that contains only L-variables and integer constants in the range -2
23
to 2
23
-1 will be
evaluated using the faster integer arithmetic. Any simple condition 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.
The integer simple condition always compares two 24-bit signed quantities against each other, and all
intermediate values in evaluating the conditions are held as 24-bit signed quantities as well, so all values
must be kept in the range -2
23
to 2
23
-1 for proper evaluation.
All of the mathematical operations permitted in integer variable value assignment statements are also
permitted in integer condition statements. All of the same rules and speed/memory benchmarks (see
below) apply.
Compound conditions, which are comprised of simple conditions separated by AND or OR logical
operators, may contain both simple conditions evaluated with integer arithmetic and simple conditions
evaluated with floating-point arithmetic.
All of the comparators that are permitted in PMAC floating-point programs, except the ~ (approximately
equal to) and !~ (not approximately equal to) comparators, are also permitted in integer-only conditions
in compiled PLCs. These valid comparators are =, !=, >, !>, <, and !<.
Examples:
Examples of legal condition statements:
IF (L50 = 1)
WHILE (L75 < L76)
IF (L1&L2 | (L4+L5) > 0 AND P1 = Q2 OR L6 != 0)
OR (L3 & L5 = $11 AND P1 = P2 OR L1 = 0)
Examples of illegal condition statements:
IF (L50 = P1)
WHILE (L75 < 10000000)
IF (L1 + P2 = 0)
Optimization for Speed and Memory
L-Variables that are 24-bit signed values are the fastest to read and write. Unsigned 1- to 20-bit variables
without offset are next fastest, and signed 1- to 20-bit variables and those having an offset from bit 0 are
the slowest. The slower the operation, the more PLC program memory is used. However, 24-bit L-
variables will use more data memory than the smaller-width ones. Because speed is more of a concern
than data memory in most compiled PLC applications, usually all L-variables that do not have to be short
to point to a particular portion of a word (such as all the general-purpose L-variables in the user buffer)
are 24 bits wide, even if they do not require the full range.
A read or write operation on a signed 24-bit L-variable takes three DSP instruction cycles to execute and
two program memory locations to store.