User's Manual

Turbo PMAC User Manual
374 Writing and Executing PLC Programs
Notice that we had to make sure that P11 could follow M11 both up and down. We set P11 to 0 in a
level-triggered mode. We could have done this edge-triggered as well, but it does not matter as far as the
final outcome of the routine is concerned. It is about even in calculation time, and it saves program lines.
Any SEND, COMMAND, or DISPLAY action statement should be done only on an edge-triggered
condition, because the PLC can cycle faster than these operations can process their information, and the
communications channels can get overwhelmed if these statements are executed on consecutive scans
through the PLC.
IF (M11=1) ; input is ON
IF (P11=0) ; input was not ON last time
COMMAND"#1J+" ; JOG motor
P11=1 ; set latch
ENDIF
ELSE
P11=0
; reset latch
ENDIF
WHILE Loops
Normally a PLC program executes all the way from beginning to end within a single scan. The exception
to this rule occurs if the program encounters a true WHILE condition. In this case, the program will
execute down to the ENDWHILE statement and exit this PLC. After cycling through all of the other
PLCs, it will re-enter this PLC at the WHILE condition statement, not at the beginning. This process will
repeat as long as the condition is true. When the WHILE condition goes false, the PLC program will skip
past the ENDWHILE statement and proceed to execute the rest of the PLC program.
If we want to increment our counter as long as the input is true, and prevent execution of the rest of the
PLC program, we could program:
WHILE (M11=1)
P1=P1+1
ENDWHILE
This structure makes it easier to hold up PLC operation in one section of the program, so other branches
in the same program do not need extra conditions to prevent their execution when this condition is true.
Contrast this to using an IF condition (see above).
Some COMMAND action statements should be followed by a WHILE condition to ensure they have taken
effect before proceeding with the rest of the PLC program. This is always true if a second COMMAND
action statement follows and requires the first COMMAND action statement to finish. (Remember,
COMMAND action statements are processed only during the communications section of the background
cycle.)
To have an input to stop any motion in a Coordinate System and start motion program 10 use the
following PLC:
IF (M11=1) ; input is ON
IF (P11=0) ; input was not ON last time
P11=1 ; set latch
COMMAND"&1A" ; ABORT all motion
WHILE(M5187=0) ; wait for motion to stop
ENDWHILE
COMMAND"&1B10R"
; start program 10
ENDIF
ELSE
P11=0
; reset latch
ENDIF