Lenze PMSS1000 Simple Servo User Manual

Page 35

Advertising
background image

Indexer-Programmer-Manual.pdf REV 1.3

Subroutines
A subroutine is a group of SML statements that is located at the end of the main body of the program. It
starts with label which is used by GOSUB statement to call this subroutine and ends with RETURN
statement. The subroutine is executed by using GOSUB statement in the main body of the program.
Subroutines can not be called from EVENT or FAULT handlers.
When a GOSUB statement is executed, execution is transferred to the first line of the subroutine. The
subroutine is executed until a RETURN statement is met. When the RETURN is executed, program
execution returns to the program line in the main program following GOSUB statement. Subroutines may
have more then one RETURN statement in its body.

Subroutine may be nested for up to 16 times. Only the remaining body of the program may contain a
GOSUB statement. Refer to Part 3 Language Reference for more detailed information on the GOSUB
and RETURN statements. The following flowchart and code segment illustrate the use of subroutines.

…statements

GOSUB CalcMotionParam
MOVED V1
OUT2=1

…statements

END

;Subs usually located after END
;statement of main program
;

CalcMotionParam:
V1 = (V3*2)/V4
RETURN

35

Advertising