User`s manual

4.0 - Programming PMAC
Page - 33
It is possible to use a set of P-variables as an array. To read or assign values from the array, simply replace the constant
specifying the variable number with an expression in parentheses.
Example:
P1=10 ; Array index variable
P3=P(P1) ; Same as P3=P10
To write to the array M-variables must be used. An M-variable defined to the corresponding P-variable address will allow
changing any P-variable and therefore the contents of the array.
Example: Values 31 to 40 will be assigned to variables P1 through P10
M34->L:$1001 ; Address location of P1
M35->Y:$BC22,0,16 ; Definition word of M34
OPEN PLC 15 CLEAR
P100=31
WHILE (P100!>40) ; From 31 to 40
M34=P100 ; Value is written to the array
P100=P100+1 ; Next value
M35=M35+1 ; Next Array position (next P-variable)
ENDWHILE
DISABLEPLC15 ; This PLC runs only once
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.
4.3.6 - 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 particularly useful 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 very 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 these
default precedences.
4.3.7 - 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.
Whether the units for the trigonometric functions are degrees or radians is controlled by the global I-variable I15.
SIN
This is the standard trigonometric sine function.
COS
This is the standard trigonometric cosine function.