User's Manual

PMAC User Manual
236 Writing a PLC Program
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 get executed on consecutive scans
through the PLC. More examples of how to program using these statements can be found in later sections.
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.
To increment the counter as long as the input is true, and prevent execution of the rest of the PLC
program, 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 have to have extra conditions and they do not execute 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 true if a second COMMAND action
statement that requires the first COMMAND action statement to finish will follow. (Remember, COMMAND
action statements are processed only during the communications section of the background cycle.) To
have an input stop any motion in a Coordinate System and start motion program 10. The following PLC
could be used.
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(M187=0) ; wait for motion to stop.
ENDW
COMMAND"&1B10R" ; start program 10
ENDIF
ELSE
P11=0 ; reset latch
ENDIF
Note:
M187 is the Coordinate System In-Position bit as defined in Example program 1.