User's Manual

PMAC User Manual
154 Computational Features
See the instructions for each type of M-variable definition in the On-Line Commands section of this
manual. Many suggested M-variable definitions are given in SETUP.PMC in the Examples section of the
manual.
It is a good idea to prepare a single file with all of the M-variable definitions and to put at the top of this
file the command M0..1023->*. This will remove all existing definitions, and help to prevent
mysterious problems caused by stray M-variable definitions.
The M-variable definitions are stored as 24-bit codes at PMAC addresses Y:$BC00 (for M0) to Y:$BFFF
(for M1023). For all but the thumbwheel multiplexer port M-variables, the low 16 bits of this code
contains the address of the register pointed to by the M-variable (the high eight bits tell what part of the
address is used and how it is interpreted). If another M-variable points to this part of the definition, it can
be used to change the subject register. The main use of this technique is to create arrays of P- and Q-
variables, as is explained above, with examples, in the descriptions of those variables. It can also be used
to create arrays in dual-ported RAM or in user buffers (see on-line command DEFINE UBUFFER).
Limited Range
Many M-variables have a more limited range than the PMAC full computational range. If a value outside
of the range of an M-variable is placed to that M-variable, PMAC automatically rolls over the value to
within that range and does not report any errors.
For example, with a single bit M-variable, any odd number written to the variable ends up as 1, any even
number ends up as 0. If a non-integer value is placed in an integer M-variable, PMAC automatically
rounds to the nearest integer.
Using M-Variables
Once defined, an M-variable may be used in programs just as any other variable — through expressions.
When the expression is evaluated, PMAC reads the defined memory location, calculates a value based on
the defined size and format, and utilizes it in the expression.
Care should be exercised in using M-variables in expressions. If an M-variable is something that can be
changed by a servo routine (such as instantaneous commanded position), which operates at a higher
priority the background expression evaluation, there is no guarantee that the value will not change in the
middle of the evaluation. For instance, if in the expression (M16- M17)*(M16+M17) the M-variables are
instantaneous servo variables, the user cannot be sure that M16 or M17 will have the same value both
places in the expression, or that the values for M16 and M17 will come from the same servo cycle. The
first problem can be overcome by setting P1=M16 and P2=M17 right above this, but there is no general
solution to the second problem.
Operators
PMAC operators work like those in any computer language: they combine values to produce new values.
Arithmetic Operators
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.
Modulo Operator
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.