If structure, Tutorial – Rockwell Automation 1398-PDM-xxx IQ Master Version 3.2.4 for IA-2000 and IQ-5000 Positioning Drive Modules, IQ-55 User Manual

Page 166

Advertising
background image

144

IQ Programming Structure • Program Structure Instructions

Publication 1398-PM601A-EN-P — October 2000

TUTORIAL

When a CALL statement is executed, execution is transferred to the first line of the subroutine. The sub-
routine is executed until a RETURN statement is executed. When the RETURN is executed, program
execution returns to the program line in the main program following the CALL. Subroutines may con-
tain more that one RETURN statement.

Subroutines may not be nested. Only the main body of the program may contain a CALL to a subrou-
tine. Refer to Part 5

Language Reference for more detailed information on the SUB, CALL and

RETURN statements. The following flowchart and code segment illustrate the use of subroutines.

IF Structure

The IF statement is used to execute an instruction or a block of instructions one time if a condition is
true. The simplified syntax for the IF instruction is:

IF condition

{

conditional statements

}

Refer to Part 5

Language Reference for more detailed information. The following flowchart and code

segment illustrate the use of the IF instruction.

statements

CALL UpdateDisplay

O2 = ON

statements

SUB UpdateDisplay

V1 = POS1

V2 = FE

V3 = POSN

PRINT 1,1, V1

PRINT 2,1, V2

PRINT 3,1, V3

RETURN

statements

If I1 = ON

{

O2 = OFF

MOVD = 3

}

statements

Start Subroutine

UpdateDisplay

Position to Display

Following Error to Display

Feedback Position to Display

Return

Start

Call UpdateDisplay

Output 2 ON

End

Is input 1 ON?

Start

Yes

No

Output 2 OFF

Move Distance 3 inches

End

Output 2 ON

Move Distance 4 inches

Advertising