2 loops, Introduction – Lenze PM94P01C User Manual
Page 33

PM94P01C
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 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 ********************************
PROGRAM_START:
;Place holder for main program loop
ENABLE
;Enable output from drive to motor
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
DIST=DIST/2
;decrease dist by 1/2
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
Running this code as is will most likely result in F_23. There are 3 MDV statements that are
executed 10 times = 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).