omron — PMAC Quick Reference

PMAC Quick Reference Guide 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 so they do not execute when this condition is true. Contrast this to using an IF condition (see above). COMMAND and SEND Statements One of the most common uses of PLCs is to start motion programs and Jog motors by means of command statements.

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.) For example, to stop any motion in a Coordinate System and start motion program 10, the following PLC can be used:

M187->Y:$0817,17,1 ; &1 In-position bit (AND of motors) OPEN PLC3 CLEAR 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 CLOSE 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.

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 64 PLC Programs