Reference Guide

PMAC Quick Reference Guide
36 Programming PMAC
CLOSE
ena PLC15 ; Enable the PLC (I5 must be 2 or 3)
P1..10 ; List the values of P1 to P10
The same concept applies for Q-Variables and M-Variables arrays, although the address range for them is
different.
Operators
PMAC operators work like those in any computer language: they combine values to produce new values.
PMAC uses the four standard arithmetic operators: +, -, *, and /. The standard algebraic precedence
rules are used: multiply and divide are executed before add and subtract, operations of equal precedence
are executed left to right, and operations inside parentheses are executed first.
PMAC also has the % modulo operator, which produces the resulting remainder when the value in front of
the operator is divided by the value after the operator. Values may be integer or floating point. This
operator is useful particularly for dealing with counters and timers that roll over.
When the modulo operation is done by a positive value X, the results can range from 0 to X (not including
X itself). When the modulo operation is done by a negative value -X, the results can range from -X to X
(not including X itself). This negative modulo operation is useful when a register can roll over in either
direction.
PMAC has three logical operators that do bit-by-bit operations: & (bit-by-bit AND), | (bit-by-bit OR),
and ^ (bit-by- bit EXCLUSIVE OR). If floating-point numbers are used, the operation works on the
fractional as well as the integer bits. & has the same precedence as * and /; | and ^ have the same
precedence as + and -. Use of parentheses can override the default precedence.
Functions
These perform mathematical operations on constants or expressions to yield new values. The general
format is:
{function name} ({expression})
The available functions are SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2, SQRT, LN, EXP, ABS, and INT.
The global I-Variable I15 controls whether the units for the trigonometric functions are degrees or radians.
SIN
This is the standard trigonometric sine function.
COS
This is the standard trigonometric cosine function.
TAN
This is the standard trigonometric tangent function.
ASIN
This is the inverse sine (arc-sine) function with its range reduced to +/-90 degrees.
ACOS
This is the inverse cosine (arc-cosine) function with its range reduced to 0 -- 180 degrees.
ATAN
This is the standard inverse tangent (arc-tangent) function.
ATAN2
This is an expanded arctangent function, which returns the angle whose sine is the expression in
parentheses and whose cosine is the value of Q0 for that coordinate system.
If doing the calculation in a PLC program, make sure that the proper coordinate system has been addressed
in that PLC program. (Actually, it is only the ratio of the magnitudes of the two values, and their signs,
that matter in this function). It is distinguished from the standard ATAN function by the use of two
arguments. The advantage of this function is that it has a full 360-degree range, rather than the 180-degree
range of the single-argument ATAN function.
LN
This is the natural logarithm function (log base e).
EXP
This is the exponentiation function (e
x
).
Note: To implement the y
x
function, use e
x ln(y)
instead. A sample PMAC expression would be
EXP(P2*LN(P1)) to implement the function P1
P2
.
SQRT
This is the square root function.
ABS
This is the absolute value function.
INT
This is a truncation function, which returns the greatest integer less than or equal to the argument
(INT(2.5)=2, INT(-2.5)=-3).