Subroutines and loops, 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 147

Advertising
background image

• Subroutines and Loops

125

Publication 1398-PM601A-EN-P — October 2000

TUTORIAL

time regardless of which type of acceleration is used.

To use S-Curve acceleration in a D-V stick requires only the addition of an “,S” at the end of the state-
ment. So the first stick in the previous example would be written

D=3,V=56,S

. Modify the previous

motion profile to use S-Curve acceleration. Using S-Curve acceleration on all of the sticks of the previ-
ous example would yield a velocity profile something like this:

Subroutines and Loops

Often it is necessary to repeat a series of steps in several places in a program. Subroutines can be useful
in such situations. The syntax of a subroutine is simple. Subroutines must be placed after the main pro-
gram, must start with

SUB subname

(where

subname

is the name of the subroutine), and must end

with a return (

RET)

. Note that there may be more than one

RET

statement in a subroutine. Subroutines

are called using the

CALL

statement.

Loops are also supported and can be used for actions that need to be repeated more than once.

The following example shows a subroutine called MDS and two types of loops. The MDS subroutine
implements a MOVD command using S-Curve acceleration to accelerate and decelerate. One loop uses
the LOOP command, the other uses an IF-JUMP command and a label.

TITLE "MDSTEST"

ASSIGN dist V1

ASSIGN myloopcnt

V10

myloopcnt = 0

main:

LOOP 20

dist = loopindex/2

CALL MDS

DWELL 0.1

RPT

dist = -Pcmd

CALL MDS

DELAY 2

myloopcnt = myloopcnt + 1

IF myloopcnt < 10 JUMP main

SUB MDS

;S-Curve MOVD subroutine

;This subroutine will do a MOVD of dist units using S-Curve acceleration and ;deceler-

ation.

Advertising