Reference Guide

PMAC Quick Reference Guide
PLC Programs 65
Timers
Timing commands like DWELL or DELAY are reserved only to motion programs and cannot be used for
timing purposes on PLCs. Instead, 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.
Example:
M90->X:$0700,0,24,S ; Timer register 1 (8388608/I10 msec)
M91->Y:$0700,0,24,S ; Timer register 2 (8388608/I10 msec)
M92->X:$0701,0,24,S ; Timer register 3 (8388608/I10 msec)
M93->Y:$0701,0,24,S ; Timer register 4 (8388608/I10 msec)
OPEN PLC3 CLEAR
M1=0 ; Reset Output1 before start
M90=1000*8388608/I10 ; Set timer to 1000 msec, 1 second
WHILE (M90>0) ; Loop until counts to zero
ENDWHILE
M1=1 ; Set Output 1 after time elapsed
DIS PLC3 ; disables PLC3 execution (needed in this example)
CLOSE
If more timers are needed, 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 with each scan subtract the starting value
from the current value and compare the difference to the amount of time to wait.
Example:
M0->X:$0,24 ; Servo counter register
M85->X:$07F0,24 ; Free 24-bit register
M86->X:$07F1,24 ; Free 24-bit register
OPEN PLC 3 CLEAR
M1=0 ; Reset Output1 before start
M85=M0 ; Initialize timer
M86=0
WHILE(M86<1000) ; Time elapsed less than specified time?
M86=M0-M85
M86=M86*I10/8388608 ; Time elapsed so far in milliseconds
ENDWHILE
M1=1 ; Set Output 1 after time elapsed
DISABLEPLC3 ; disables PLC3 execution (needed in this example)
CLOSE
Even if the servo cycle counter rolls over (starts from zero again after the counter is saturated), by
subtracting into another 24-bit register rollover is handled gracefully.
Rollover Example:
M0 = 1000
M85 = 16777000
M86 = 1216
Bit 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
M0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 0
M85 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0
M86 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0
Carry-out bit