Introduction – Lenze E94P PositionServo with MVOB User Manual

Page 33

Advertising
background image

PM94H201B_13xxxxxx_EN

L

31

Introduction

1.11.2 Loops

SML language supports WHILE/ENDWHILE block statement which can be used to create conditional loops. Note that
IF-GOTO and DO/UNTIL statements can also be used to create loops.

The following example illustrates calling subroutines as well as how to implement looping by utilizing WHILE / ENDWHILE
statements.

;***************************** Initialize and Set Variables **********************

UNITS = 1

;Units in Revolutions (R)

ACCEL = 15

;15 Rev per second per second (RPSS)

DECEL = 15

;15 Rev per second per second (RPSS)

MAXV = 100

;100 Rev per second (RPS)/6000RPM

APOS = 0

;Set current position to 0 (absolute zero position)

DEFINE LOOPCOUNT

V1

DEFINE LOOPS

10

DEFINE DIST

V2

DEFINE REPETITIONS V3

REPETITIONS = 0
;********************************* Main Program **********************************

WAIT UNTIL IN_A3

;Make sure the Enable input is made before continuing

ENABLE

PROGRAM_START:

MAINLOOP:

LOOPCOUNT=LOOPS

;Set up the loopcount to loop 10 times

DIST=10

;Set distance to 10

WHILE

LOOPCOUNT

;Loop while loopcount is greater than zero

GOSUB MDS

;Call to subroutine

WAIT TIME 100 ;Delay executes after returned from the subroutine

LOOPCOUNT=LOOPCOUNT-1

;decrement loop counter

ENDWHILE

REPETITIONS=REPETITIONS+1 ;outer loop

IF

REPETITIONS < 5

GOTO MAINLOOP

Wait Motioncomplete

;Wait for MDV segments to be completed

ENDIF

END

;******************************** Sub-Routines ***********************************

MDS:

V4=dist/3

MDV V4,10

MDV V4,10

MDV V4,0

RETURN
Note: Execution of this code will most likely result in F_23. There are 3 MDV statements that are executed 10 times
totaling 30 moves. Then the condition set on the repetitions variable makes the program execute the above another
4 times. 4 x 30 = 120. The 120 moves, with no waits anywhere in the program will most likely produce an F_23 fault
(Motion Queue overflow). Where the possibility exists to overflow the Motion Queue additional code should be used to
detect ‘Motion Queue Full’ condition and to wait for space on the Motion Queue to become available.

Advertising