User's Manual

PMAC User Manual
Writing a PLC Program 237
Precise Timing
Since PLCs 1 to 31 are the lowest computation priority on PMAC, the cycle time cannot be determined
precisely. To hold up an action for a fairly precise amount of time, use a WHILE loop, but instead of
incrementing a variable, use an on-board timer. PMAC has four 24-bit timers to write to, and count down
once per servo cycle. These timers are at registers X:$0700, Y:$0700, X:$0701, and Y:$0701. Usually a
signed M-variable is assigned to the timer; a value is written to it representing the desired time in servo
cycles (multiply milliseconds by 8,388,608/I10); then the PLC waits until the M-variable is less than 0.
With M70->X:$0700,24,S:
M70=P1*8388608/I10 ; Set timer to 500 msec
WHILE (M70>0) ; Loop until counts to zero
ENDWHILE ; Exit PLC program here when true
For more timers, probably the best technique to use is in memory address X:0. This 24-bit register counts
up once per servo cycle. Store a starting value for this, then in each scan subtract the starting value from
the current value and compare the difference to the amount of time to wait. By subtracting into another
24-bit register, handle rollover of X:0 gracefully.
First, define the following M-variables with on-line commands:
M0->X:$0,24 ; Servo counter register
M85->X:$07F0,24 ; Free 24-bit register
M86->X:$07F1,24 ; Free 24-bit register
Then we write as part of our PLC program:
M85=M0 ; Start of timer
M86=M0-M85 ; Time elapsed so far
WHILE (M86<P86) ; Less than specified time?
M86=M0-M85 ; Time elapsed so far
ENDWHILE ; Exit PLC program here when true
Compiled PLC Programs
It is possible to compile PMAC PLC programs for faster execution. The faster execution of the compiled
PLCs comes from two factors: first, from the elimination of interpretation time, and second, from the
capability of the compiled PLC programs to execute integer arithmetic. Floating-point operations in
compiled PLC programs run 2 to 3 times faster than in interpreted PLC programs; integer (including
boolean) operations run 20 to 30 times faster in compiled form.
Note:
The size of the compiled code mentioned here refers to the space that the actual
compiled code will occupy in the PMAC memory. It does not refer to the size of
the compiler's output file on the PC's disk drive.
PMAC does not perform the compilation of the PLC programs itself. The compilation is done in a PC;
the resulting machine code is then downloaded to PMAC.
PMAC can store and execute up to 32 compiled PLC programs as well as 32 interpreted (uncompiled)
PLC programs for a total of 64 PLC programs. 15K (15,360) 24-bit words of PMAC memory are
reserved for compiled PLCs; or 14K (14,336) words if there is a user-written servo as well. No other task
may use this memory, and compiled PLCs may not use any other memory.
A compiled PLC program is labeled PLCC n (PLC-Compiled #n) on PMAC. This distinguishes it from
an interpreted PLC, which is simply labeled PLC n. There is no special relationship between the
interpreted and compiled PLCs of the same number.