PMAC Quick Reference Guide 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 8-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 or arrays in dual-ported RAM or in user buffers (see on-line command DEFINE UBUFFER ).
Many M-Variables have a more limited range than PMAC’s full computational range. If a value outside of the range of an M-Variable is placed to that M-Variable, PMAC rolls over the value automatically 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 rounds to the nearest integer automatically. 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. Array Capabilities 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 Programming PMAC 35