Subido por eslava51

940-quickstart-programming-2007 10

Lenze PositionServo Programming Primer:
A Quick Start Programming Guide for PositionServo
Scope: This document refers to the use of the Lenze PositionServo 940 range of Servo Motion Controllers.
The document discusses the basic programming language and tools needed to create custom programs
and behavior with the Lenze PositionServo Drive. It refers predominantly to the use of the drive in Position
mode with internally (intelligently) generated motion, and the use of the internal programming
language for that purpose.
By the end of this document you will be able to create profiled motion, manipulate drive inputs and outputs,
perform decision making, create events, handle fault conditions, and compile and execute the program, all
via the user (indexer) program in PositionServo.
Note: The PositionServo can equally be applied as a centrally controlled servo amplifier in Torque, Velocity,
or Position mode, simply through the setting of basic parameters. It can also intelligently operate from a
custom (user) program in both Torque and Velocity mode. However these modes are beyond the scope of
this document and are covered by other readily available quick start guides.
Templates: Multi-lingual Programming Templates are available on the MotionView CD, from the
corporate website or via your local Lenze representative.
The template is a text file that defines the program into logical sections and gives indications of where the
different functions and statements (typically) need to be located. It will give you a solid starting point in
creating your program.
Comments in a program: Comments can be used anywhere in the program. Comments start with a
semi-colon (;) and anything after the semi-colon is considered a comment. A semi-colon must appear on
every line of code to be commented (you cannot bracket sections of code as comments).
Comments can be used to document the program or to quickly remove a line of code from execution.
In this document, every line of code will be commented to help with understanding the commands used.
Comment an entire Line
; The following section Initializes Variables prior to the main program execution
Or Comment a Program Statement
MoveP 0 ; Move to Start Position Ready for next Operation
Motion profile parameters: Before you can move the motor, you need to define a series of
parameters to define HOW it will move. This includes setting up the units of the machine and setting up the
velocity and acceleration for the move. These commands are actually just setting internal variables called
“system variables” in the drive.
UNITS: This system variable is in effect a multiplier that multiplies motor revolutions into more meaningful
user units. User Units is used to define how many revolutions the motor should perform per 1 user unit the
system will move. The user units (UU) can therefore be scaled by the customer to anything they desire:
Millimeters, inches, degrees, radians, etc.
For example, if the customer has the motor attached to a ball screw that has a pitch of 10mm, and he wants
his UU to be millimeters, then the system variable will be set using the following command:
UNITS = 0.1
; A commanded move of 10 will result in one revolution of the motor
; (10 * 0.1 = 1 rev) and 10mm of travel from the ball screw (1 rev =
; 10mm travel). The customer is commanding motion in mm.
When units is set to 1, a commanded move of distance 1 will result in one revolution of the motor shaft
When units is set to 0 motion is commanded in terms of Encoder Feedback Pulses
MAXV: This system variable sets the maximum velocity of the motion profile. This is the ‘Target’ velocity for
the motor during the acceleration part of the move, and the ‘steady state’ velocity at which the motor will
rotate for the motion profile (following acceleration and until the motor is required to decelerate).
This variable is always in the units of UU/second. If the customer wants to have his motor move at a
maximum velocity of one meter per second, and his UU is mm, then the command would be:
MAXV = 1000 ; 1000mm/second, or 1m/s
If a program requires different speeds for different moves, simply change the MAXV value before the
individual move command in your program.
ACCEL and DECEL: These system variables are used to set the acceleration and deceleration ramp for the
motion profile. The units for these variables are UU/sec2. For the above example, if the customer wants to
accelerate to (and decelerate from) the maximum velocity (1000mm/s) in 0.2 seconds, then the commands
; MAXV is the maximum speed, 0.2 is the time for acceleration.
; Set the deceleration equal to the acceleration
Two new concepts were introduced in these commands: First, when setting a variable you can use other
variables. Also, it’s possible to do math when setting a variable, like dividing the velocity by the acceleration
Velocity defined by
MAXV variable
Acceleration (Gradient)
defined by ACCEL Variable
Deceleration (Gradient)
defined by DECEL Variable
Area (Blue) = Distance
Determined by Motion
Time for Complete Move
Causing Motion: There are several methods we can use to command Motion from our motor. Enabling
the drive ready for Motion and commanding Motion are described in this section.
ENABLING THE MOTOR: To enable the motor (provide current to the motor so it has torque), just use the
command ENABLE. To disable the motor, use the command DISABLE.
JOGGING: Jogging (moving at a certain speed with no set distance) is accomplished through the MOVE
UNTIL or MOVE WHILE commands. MOVE UNTIL will jog forward until a condition becomes true. To move in
the reverse direction, use the command MOVE BACK UNTIL. These commands are often used while homing.
To jog in the reverse direction until an input comes on (more on inputs later), use the command:
MOVE UNTIL IN_A1 ; Move forward at speed defined by MAXV until input A1 is TRUE.
MOVING A DISTANCE: This is a relative move, which is a move that moves a certain distance from the
motors current point or position. This type of move is typically used when indexing forward repeatedly, such
as a feed system. The command to do this is MOVED #, where # is the distance (in UU) to be move from
the starting point. So, if you want to move forward five units, the command is:
MOVED 5 ; Move a distance of 5 units forward from wherever the motor is now.
If the actual starting position is 2 units from the ‘0’ Position (current position is 2), the end position will be 7
units. To perform a backward move just make the distance negative (i.e. MOVED –5). The velocity,
acceleration, and deceleration are determined by the MAXV, ACCEL, and DECEL variables, respectively.
MOVING TO A POSITION: This is an absolute move, which is a move to a specified position (distance)
relative to (from) the zero position. This type of move is best used for back-and-forth movement, such as a
pick-and-place. If the user wants to move to a position 5 units from zero, the command is:
MOVEP 5 ; Move to the position that is five units from the zero position.
Using this command, if the starting position is 2, the motor will move 3 units forward to end at a final
position of 5. Similarly, if the starting position is 99, the motor will move backwards 94 units and again end
up at a position of 5 units.
Note: The drive will be at zero position at power up. You can define your own zero position by writing to the
APOS variable (detailed later). This is normally done after a homing routine when the shaft position is
understood relative to the application.
Using I/O and User Variables: The PositionServo drive has digital and analog Inputs and outputs
(I/O) adequate for the majority of servo applications. Manipulation of this I/O is detailed here.
DIGITAL INPUTS: In programming terms an input is a variable that represents the present state or
condition of one of the drives digital inputs (a simple true or false evaluation, on or off, 1 or 0). There are
three input ‘groups’ (A, B and C), each with four individual inputs (1, 2, 3 and 4), and there own isolated
common terminal. If we take input A1 as an example, to evaluate this input (from the A group) use the
variable IN_A1. If it’s ON, then IN_A1 will be 1, whereas if it’s off, it will be 0.
DIGITAL OUTPUTS: Outputs are also true or false values stored within variables. There are four
programmable outputs which use the variables OUT1 to OUT4. To turn an output ON, set it equal to 1. To
turn an output off, set it equal to 0.
OUT1 = IN_A1 ; Set Output 1 ON if Input A1 is ON, and OFF if the input is OFF.
NEGATING AN INPUT: Some applications require you to evaluate if an input is off instead of when it is on.
This is called “negating” an input, or a NOT condition. You can negate an input (or any logical evaluation) by
preceding the variable with an exclamation point (!).
OUT2 = !IN_A2 ; Set Output 2 ON if Input A2 is OFF, and OFF if the input is ON.
ANALOG INPUTS: There are two Analog inputs on the PositionServo that input voltage (+/- 10V) into the
system Variable AIN1 and AIN2. The units for these variables are always Volts.
These inputs are freely programmable; however the majority of applications will use them as a Velocity or
Torque References. When in Internal (programming) torque or Velocity mode this is done by scaling and
transferring the Analog Input into a variable called IRef.
IREF = AIN1 * 5
; Reference is Analog 1 (+/- 10 volts) * 5 (scaling). Range is hence +/- 50
; IREF is in revolutions per second (RPS) so Range is +/- 50 RPS
ANALOG OUTPUTS: There is one Analog Output on the PositionServo. The system Variable is AOUT. The
unit for this variable is Volts and has a range of +/- 10. Values written to this variable outside of the limits
(+/- 10) are automatically trimmed back to 10V with the given polarity.
AOUT = AIN1 + 0.25 ; Analog Output equally analog input 1 + an offset of 0.25V
Variables and Definitions: Variables are storage locations within the drive memory where the
programmer can store system data and the results of calculations. Definitions allow us to provide ‘real world’
definitions to variables, constants and Input / outputs. Definitions make the program easier to understand
and allow us to use language relevant to our application.
USER VARIABLES: In addition to the various system variables, there are variables that the user can define.
There are 64 of these variables split into two sets, ‘V’ variables and ‘NV’ Variables. These variables are
labeled V0 through V31, and NV0 through NV31 (the difference between the two sets is irrelevant at this
stage). These variables are inherently floating point (that is, they are capable of storing decimal variables),
but can also store integers and bit-type data as well.
V5 = NV12
; Copy the Value of Variable NV12 to Variable V5
DEFINING CONSTANTS OR VARIABLES: When looking at a complex program, variable names like IN_A1 or
V0 mean very little. It is advantageous to use “real-world” descriptions in place of variable names. Therefore
it is useful to use the DEFINE command to “rename” these variables. For instance, if the input IN_B3 is an
input used to start a move, and OUT1 is used to confirm the status of this input, the programmer might use
the code:
DEFINE StartInput IN_B3
DEFINE ConfirmStartOutput OUT1
ConfirmStartOutput = StartInput
This code is equivalent to the command “OUT1=IN_B3”, which is a shorter to type method, but is not
intuitive when reading the code. A similar method can be used to define a constant value. For instance, if a
move starts at a certain point and ends at another point, the programmer might use:
DEFINE StartPoint 0 ; The start point for the move is 0 UU
DEFINE EndPoint 10 ; The end point for the move is 10 UU
If the move parameters change for a different product or for a different machine, the user only needs to
change these two lines instead of hunting through the program and trying to figure out which values need to
be changed.
When writing a complex program, it is advisable to use the DEFINE statement as much as possible so the
program is easy to follow and change when necessary. Note, however, that all DEFINE statements must be
at the beginning of the program.
Waiting and Looping:
WAITING: In many instances, it is necessary to wait for certain conditions to occur before continuing on with
the program. To accomplish this we use the WAIT command. There are a few different ways the WAIT
statement can be used:
WAIT UNTIL is used to wait until a certain condition is true. For instance, if the user wants to
start a relative move once an input has come on, the code would be:
; Do not proceed with the program until Input A1 is ON
; Move to a distance 10 UU from present position
WAIT WHILE is used to wait while a certain condition is true. It is the same as using a WAIT
UNTIL with a negated condition (i.e. WAIT UNTIL IN_A1 is the same command as WAIT WHILE
WAIT TIME is used to wait for a certain time, defined in milliseconds. To delay for ½ second,
use the command:
WAIT TIME 500 ; Wait for 500 milliseconds
WAIT MOTION COMPLETE is used to wait until all motion that has been commanded is finished
(there are no further motion commands on the motion stack).
CONDITIONAL LOOPS: In some cases, it is desirable to perform an operation several times while certain
conditions are true. Conditional loops perform a loop of code until the result of a logic comparison, specified
by the programmer, becomes true. There are two variants of this loop; the DO loop and the WHILE loop.
DO / UNTIL is used to perform the loop until a certain condition becomes true. For instance, if
the user wants to perform a series of moves 10 times, the code would be:
V0 = 0
; V0 will be our Loop counter, set to 0
; Do the following loop
; Move to a distance 10 UU from present position
Wait Time 100 ; Wait 100ms
MoveD -10
; Move to a distance -10 UU from present position
V0 = V0 + 1
; Increment our Loop Counter
Until V0 == 10 ; Check Logic, if True Exit Loop, If False Repeat
Because Do/Until loops do not check the logic condition until the last line of the loop, the code contained within
the loop will always be executed at least once.
WHILE / WEND is effectively the inverse logic of the DO / UNTIL loops, and is used to perform
the loop until a certain condition becomes False. For instance, lets take the same example we
used to the DO / UNTIL loop, to perform a series of moves 10 times, the code would be:
V0 = 0
While V0 <> 10; Check
Wait Time 100
MoveD -10
V0 = V0 + 1
; V0 will be our Loop counter, set to 0
Logic, if True execute Loop, If False end loop
; Move to a distance 10 UU from present position
; Wait 100ms
; Move to a distance -10 UU from present position
; Increment our Loop Counter
; End Loop, Return to While and re-check logic
Note now, because WHILE / WEND loops check the logic condition on the first line of the loop, the code
contained within the loop may never be executed.
UNCONDITIONAL LOOPS: It is common for a program to repeat itself when in operation. This is
accomplished using labels and the GOTO command. A label is a text field followed by a colon. The label text
cannot be the same as a command, variable, or user text defined using the DEFINE command. The GOTO
command is used to jump to one of the labels in the program. Here is a simple program that moves the
motor forward five units, waits ½ second, and then repeats:
GOTO JumpPoint
This is the label. Note that it is followed by a colon.
Move forward 5 units.
Wait 500 milliseconds
Go to the defined label. Notice the colon is NOT included.
Review of Language that has been Explained:
What follows is a sample exercise using the concepts and commands we’ve learned so far. In this example,
the user has a rotary table that’s attached to the motor through a 50:1 gearbox. When an input has a rising
edge, the table should move forward 30° in about one second. When the table starts a new move it should
switch off and output and switch is in its final position, an output will be turned on. When the move is done,
the program should wait for the next input and repeat the process.
DEFINE GearboxRatio 50
DEFINE MoveDistance 30
; The ratio of the gearbox to the motor shaft.
; The distance to be moved per increment (degrees).
DEFINE MoveTime 1000
DEFINE Ramp 100
DEFINE StartInput IN_A1
DEFINE CompleteOutput OUT1
The time of the move (ms).
The time taken to accel to speed / decal to 0 speed.
The input used to trigger the start of the move
The output used to indicate that the move is complete
Allow use of word True in program instead of using 1
Allow use of word False in program instead of using 0
UNITS= (1 / 360)* GearboxRatio ; This equation has 2 parts. Firstly we put our motion commands
; in degrees, i.e. a move of distance 1 will be 1/360th of a
; motor shaft rev. Secondly we refer the units (motion) to the
; gearbox shaft by multiplying by the gearbox ratio.
; This command is a little more complicated, but remember that
; velocity is distance over time. The move distance is defined.
; The time is determined by the total move time minus the accel
; time. There is an in-depth explanation below. In many
; applications we can simply define a constant for the maximum
; velocity the machine should run at (i.e MAXV = 30).
; The acceleration time is defined above, and the velocity was
; just calculated. Acceleration is velocity divided by time.
; Set the deceleration equal to the acceleration.
WAIT UNTIL !StartInput
GOTO MoveStart
This is a label for the loop being used in this program.
Turn off the indication that the move is complete.
Wait for the input to be OFF, then…
Wait for the input to turn ON. These two commands combine
to form an “edge detection” for a rising edge.
Move 30 units (degrees in our application)
Turn on the indication that the move is complete.
Wait 500mS After Move (so you can see Output on)
Jump to the label to wait for the next trigger signal.
A couple of notes about this program: First, note that there is no WAIT MOTION COMPLETE command after
the move. This is because, by default, the MOVED and MOVEP commands will automatically wait for the
motion to complete before continuing to the next command. Also note that because the important
parameters for the program are defined at the beginning, it is very simple to change the program. If the
move needs to be 45° instead of 30°, it is only necessary to change the second line to DEFINE
MoveDistance 45 and everything else (velocity and acceleration rates, specifically) will take care of itself.
This explanation of setting the MAXV command has little to do with programming and more with general
motion control concepts, but it is important to understand.
Take the following motion profile as an example:
The time ‘a’ is the acceleration and the total move time is ‘t’. For our program ‘a’ is 100ms, and ‘t’ is 1000ms.
The distance moved is the area under the profile curve. ‘X' is the speed we want to calculate.
Knowing that the area under the curve is the distance traveled and using simple geometry, we know that
the distance moved during acceleration is da=1/2*a*x, and the deceleration is the same.
The distance traveled during the constant-speed part of the move is dt=(t-2a)*x.
So the total distance traveled is;
Solving for x (which is the velocity), we get x=dtotal/(t-a).
Plugging in the variable names from the program, the result is the equation used in the program:
Conditional Operations, comparatives and multiple conditions:
IF/ELSE STATEMENTS: An IF/ELSE statement is used to make a decision. It must be closed with an ENDIF
command. For instance, if a user wants to set a variable to 15 if an input is on, and 30 if it’s not, then the
code would be:
; If the input is ON,
V1=15; Set the variable to 15
; Otherwise,
; Set the variable to 30
; The end of the IF statement
You can have multiple commands for IF and ELSE statements. ELSE statements are optional. IF statements
can also be “nested” to check for several conditions.
COMPARATIVES: Comparatives are used to compare one value to another. Comparatives in the
PositionServo are:
Greater Than
Less Than
Greater or Equal
Less or Equal
Note that equality uses a double-equal when it is comparing values (like A==B, where the result is true or
false) to differentiate it from a command that sets the values equal (such as A=B, where A takes the value
of B). For instance, if the program has a certain variable that has a maximum value of 15, then the code
might be:
IF V1>15
; If the variable is greater than the maximum value,
V1=15; set the variable to the maximum value.
; Close the IF statement.
MULTIPLE LOGIC CONDITIONS (AND/OR): More than one condition can be checked when making a logical
decision. There are two types of operators (Boolean operators) used to check multiple conditions within a
logic statement, those being the AND and the OR operators.
For an AND condition, the symbol && is used; Example, for the command “IF IN_A1 && IN_B1 && IN_C1”
then IN_A1, IN_B1, and IN_C1 must all be true (on) for the IF statement to evaluate as true.
With the OR condition, the symbol || is used. (The | is called a “pipe” and is typically shift-\ on the
keyboard.) For the command “IF IN_A1 || IN_B1 || IN_C1”, then one or more of IN_A1, IN_B1, and IN_C1
must be true for the IF statement to evaluate as true.
If the user wants to move 5 units if input B1 is on AND either input B2 OR B3 is on:
IF IN_B1 && (IN_B2 || IN_B3) ;If B1 and either B2 or B3 is on,
; Move 5 units
;Close the IF statement
Other Important System Variables:
APOS: This is the actual position that the motor is currently at. You can see where the motor is at by
monitoring this variable, or you can change the definition of the current position by redefining this variable.
For instance, after a machine is homed you want to set the actual position counter to zero. To do this, the
code is:
APOS=0 ; Set the actual position to zero.
Note that this setting this variable doesn’t move the motor. It simply tells the drive that the motor’s current
position is to be considered the zero position.
PHCUR: This variable indicates the amount of current being used by the motor measured in Amps. It is a
read-only variable. In many applications, the homing process needs to be accomplished by (lightly) running
the motor to a hard stop to find the end of travel. To do this, the PHCUR variable can be compared to a
preset value. For instance:
;Move the motor backwards until more than 2A
;of current is being used by the motor.
VAR_DRIVEMODE: This variable can be used (typically at the start of the program) to set the drive operating
mode. There are three modes selectable by setting VAR_DRIVEMODE as follows;
; Set the Drive in Torque Mode
; Set the Drive in Velocity Mode
; Set the Drive in Position Mode
Note, you can change operating modes when required during program execution but do not change modes
on the fly (with drive enabled) as this may cause unexpected behavior of the motor. There are advanced
techniques available for applications of this nature with detail in the PositionServo Programmer Guide.
VAR_REFERENCE: This variable can be used (again, typically at the start of the program) to set the drive to
internal or external operation mode. Internal mode should be set when the reference for the motion of the
drive is generated from the indexer program (such as with a move command, or writing to IREF Variable).
External mode is set when a separate controller is used to provide a motion reference to the drive. Settings
for VAR_REFERENCE are as follows;
; Set the Drive in External Mode
; Set the Drive in Internal Mode
You can use variables VAR_DRIVEMODE and VAR_REFERENCE to set the operating mode at the start of the
program or use them to change or select a different mode from the indexer program based on different
logical conditions.
What are events? The processor in the PositionServo drive is actually doing several things at once. There is
the main program execution, of course, which is what this document has focused on so far. In addition,
there’s the actual motion (which is triggered by the main program, but is really a separate processor task),
communication, fault handling, events, and other processes. Events are a task that runs independent of the
main program execution. So, in essence, an event is something that’s happening in the background.
Every 256µs, the event scanner checks all active events and activates the ones that should be activated.
Events can be triggered by an input, a time period, or a true/false expression. When the criteria for the
event are met, the event executes. There are a maximum 32 events that can be created in the program.
There are some operations that events cannot directly do. Generally these operations fall into two
categories, ‘generating motion’ and ‘causing a delay’.
For instance, an event cannot directly cause motion because only the main program has a link to the motion
task. However, the JUMP statement can be used in an event to “redirect” the program execution to a new
point in the program, allowing the programmer to trigger motion.
Also the Event task cannot contain a delay because it will affect the other tasks the processor is running as
well as invalidating other events that are scheduled to execute.
Defining events: Events are defined by using the EVENT command followed by the name and condition for
the event.
TIMED EVENTS: Specifies a time period between subsequent executions of the event code. For
instance, if the user wants to have an Output toggle state every 500mS, the code might be:
IF OUT1 = 1
OUT1 = 0
OUT1 = 1
Perform this event (named “TOG_OP1”) every 500ms.
If Output 1 is Currently Switched on…
Turn the output off
Turn the output on
End the event definition
INPUT TRIGGERED EVENTS: Specifies the Input to check and the logic transistion (switching on
or switching off) that will trigger the event code to execute. For instance, if the user wants to
have an Output switch on when input B1 comes on, the code might be:
EVENT Detect_B1 INPUT IN_B1 Rise
OUT1 = 1
Perform event (named “Detect_B1”) when input B1
Rising edge detected (transition logic 0 to 1).
Turn the output on
End the event definition
We can also use the word ‘Fall’ in place of the word ‘rise’ to detect a transition from logic 1 to 0.
LOGIC TRIGGERED EVENTS: Specifies a logical condition to check that (if true) will trigger the
event code to execute. For instance, if the user wants to have an Output activate when the
motor position is above 100, the code might be:
OUT1 = 1
Perform event (named “SWT_OP1”) when APOS register is
greater than 100.
Turn the output on
End the event definition
Here the output will activate when the APOS register is greater than 100.
We might wish to create a second event here to switch the output off when APOS is equal or less that 100,
otherwise the output will ‘latch on’.
Another important point is that the code to turn on output 1 will be executed every 256uS while APOS > 100.
Typically we would turn the event off (see below) after its first activation to prevent repetition, and switch on
again when output 1 was reset to 0.
These methods are used to define the event, but the event is not active until it is turned on in the main
program (see next section). It is also important to remember that the events must be defined just after any
DEFINE statements at the beginning of the program.
Turning on events: All events are off (deactivated) when the program is started. All events are also switched
off following a fault on the drive (see fault handler section). The EVENT statement is also used to activate
the event in the main program. To turn on one of the events we defined in the previous section, the code is:
Turn on event named “TOG_OP1” on.
Turn an event off with EVENT [Name] OFF. You can turn the event off from within the event code itself to
prevent the event being executed repeatedly after the first activation.
The Fault Handler:
The fault handler is the process task that is activated in the event of a fault occurring on the drive. It is
important that you give proper consideration to the fault handler and to how you with to respond to the
different fault conditions that may occur.
When a fault occurs the PositionServo will perform the following actions:
1) The drive will be disabled to prevent further Motion
2) The Motion Stack will flushed on any Motion Statements awaiting execution
3) All Events will be disabled (they are not automatically enabled on leaving the fault handler)
4) Communications process (thread) will be suspended; Communications will be resumed on
exiting the fault handler.
5) The code for the fault detected is written to the DFAULTS register of the drive.
6) The main program execution is terminated and control is handed to the fault handler routine
The Fault handler routine appears at the end of the user program. It is started with the ON FAULT label
and ended with the ENDFAULT statement.
The fault routine is designed to put the drive in a safe condition, and to allow you to detect the
fault that has occurred and make a logical decision on how you wish to respond to that fault. If
you wish to recover from a fault then this should be done by resuming the main program
execution at a point that will execute the necessary statements for recovering the fault.
There are three options to existing the fault handler, the RESET statement, the RESUME Statement, and
the ENDFAULT statement.
If processing of the fault handle reaches and executes the ENDFAULT statement (program is not restarted
with either RESET or RESUME) then the Indexer program will simply stop executing with the drive
remaining in its disabled state. The user would typically then check the fault condition on the drive display
and restart program execution through MotionView (by pressing restart / run), through cycling power (if
auto-boot parameter is set to enabled), or through an instruction via the communications link. This should
be the default action for most faults that occur. You can then choice to react to a few specific faults
(those with a predictable cause) using the RESET or the RESUME command.
The RESET command will cause the processor to exit the fault handler and to try and restart main program
execution from the beginning (like pressing the restart button in MotionView). RESET does not clear any
variables in the drive which is why it is important that you initialize variables correctly at the beginning of
your program.
The RESUME statement allows you to specify a program label (see waiting & looping section) in the main
program to try and restart main program execution. Typically this is the statement you will use to jump to a
fault recovery section of the main program where you will attempt to recover the fault.
Wait statements and any commands related to motion are not allowed in the fault handler section. You
should use the RESUME statement and jump to a fault recovery procedure in the main program that can
then contain these statements.
A Typical Fault handler routine is shown below.
; ************ Fault Handler Routine ************
; Defines Start of Fault Handler
Out1 = 1 ; Turn on Output 1 to Indicate Fault
If DFAULTS == 36
; Check if DFAULTS register contains fault 36
Resume Fault Recovery
; Fault 36 is hardware enable (A3) missing. Assume…
; Operator Error and Resume at Fault Recovery Label
; Check if DFAULTS register contains fault 36
; Fault 1 is Over-voltage. Try to recover by restarting
; user program from first program statement
; Defines End of Fault Handler
; All other faults will cause indexer program to stop.
Putting it all together to write a sample program:
This sample program demonstrates the use of the PositionServo Drive in a typical Indexing (Rotary)
Table Application. The code executes a programmed homing routine on start up, and then performs a
series of Index Moves based on the value of two constants ‘Step_Change’ and ‘Step_Wait’ declared at
the start of the program. ‘Step_Change’ tells the drive how far to move the Index table for each Index
Move and ‘Step_Wait’ gives the interval between each Indexing Move / Motion.
;********** PositionServo User Indexing Program **********
; ********************** Header **********************
Indexing Table - Basic Feed Forward - PositionServo Training Program
Program is for an Indexer Table that is allowed to Travel Clockwise Only.
The Size of the Steps taken by the Indexer is Uniform and Defined by a Variable
;Version Num: V1.0.1
; ********************** I/O List **********************
Input A3
Safety stop
Input A4
Input B1
System Reset
Input B2
Homing Sensor
Output 1
In Position
; **************** Initialize and Set Variables ****************
; Define Constants and Variables. Assign I/O and Initialize Variable Values
UNITS = 1/ 360
; Units in Degrees
Accel = 720
; Set Acceleration Rate for Moves (degrees per second2)
Decel = 720
; Set Deceleration Rate for Moves (degrees per second2)
; Set Reference to Internal
; Set Operating mode to Position mode
Define True 1
Define False 0
; Allow 'True' Keyword to be Used in Logic
; Allow 'False' Keyword to be Used in Logic
Safety_Stop_Input IN_A3
Run_Stop_Input IN_A4
System_Reset IN_B1
Homing_Sensor IN_B2
Position_Out Out1
Step_Change 60
Step_Wait 1000
Move_Velocity 3600
Target_Position V2
Constant value for size of Index Move (in degress)
Constant value for time between Index Moves (ms)
Constant value for move Velocity (degree / sec)
Define Variable to Incremented with New Index Positions
Application specific name for Input A3
Application specific name for Input A4
Application specific name for Input B1
Application specific name for Input B2
Application specific name for Output 1
; ********************** Events **********************
;Event to Check for the system Reset Button Being Pressed
Event Reset_Restart Input System_Reset Rise
Jump Program_Start
; Restart Program from Program_Start Label
; ******************* Main Program *******************
Wait Until Run_Stop_Input == False
; Ensure Run Input is Off Before Starting Program
; Program Label for GOTO, JUMP, or Resume Statement
; Disable Drive (Ensure Disabled)
Event Reset_Restart Off
; Turn off Event to detect a system Reset (Input) Occurring
Target_Position = 0
APOS = 0
Position_Out = False
Wait Until Run_Stop_Input == True
Event Reset_Restart On
; Initialise Traget Position Register
; Initialise APOS as 0
; Switch off the 'In Position' Output
; Ensure Run Input is Active Before Starting Program
; Enable Drive / Go to Run State
; Turn on Event to Check Drive Run Input (going off)
Maxv = Move_Velocity / 5
Move back until Homing_Sensor
Maxv = Move_Velocity / 10
Move until homing_sensor == 0
APOS = 0
Maxv = Move_Velocity
Homing Routine, Performed at Start Up and after Homing
Routine Request input goes high
set slow velocity for homing
move back at slow velocity until homing sensor is activate
set very slow velocity
move forward off homing sensor
Set actual position register to 0
Set velocity back to normal speed
Wait Until Run_Stop_Input == True
; Suspend Motion Until the system Run Input is Present.
; Allows Indexinging to be suspended.
Target_Position = Target_Position + Step_Change
; Increment the Target Position Variable
Position_Out = False
; Switch off the 'In Position' Output
MoveP Target_Position, S
; Implement / Apply the Next Index Step - Use S-Ramp
Position_Out = True
; Switch on the 'In Position' Output
Wait Time Step_Wait
; Wait Time between Index Steps
Goto Program_Loop
; Repeat Indexing Loop
wait until Run_Stop_Input == False
Goto Program_Start
; Wait until Drive run input is disabled
; **************** Fault Handler Routine ****************
Enter Fault Handler code here
If DFAULTS == 36
; If fault caused by Hardware Enable off.
Resume Fault_Reset
; Jump to Fault Handler Section
; All other faults (than fault 36) terminate indexer program
Application Picture:
Appendix: Compiling, downloading, and executing a user program:
COMPILING: The compiler is a tool that checks the code of the program and makes sure that there are no
errors. To compile a program, press F6 from the programming screen. If the compiler can not understand
your program due to errors in syntax, undefined variable tags, etc., a dialog box will appear on your screen
indicating that the compiling has failed. The status screen at the bottom of the MotionView window will
display the type of error and the line number where the error was found.
DOWNLOADING: The ‘Compile and Load’ function (Shift-F6 from the programming screen) causes
MotionView to compile the user program and, if the compilation is successful, download it to the drive. If an
error occurs during compilation, the program will not be downloaded to the drive.
RESTARTING THE PROGRAM: The restart function (Shift-F5 from the programming screen) resets any drive
trips / faults and sets the program to restart from the beginning.
EXECUTING THE PROGRAM: To execute the program, the F5 button is used. The program can also be
automatically executed on drive power-up by using the “Autoboot” option in the Parameter menu. If
Autoboot is enabled, then program starts as soon as the PositionServo drive is powered on.
STOPPING THE PROGRAM: To stop the program, the Alt-F5 key is used. This will stop program execution
and highlight the next line of code it was about to execute. Pressing run again will restart program execution
from this point (think of it as a pause button). The drive is not disabled, and the current motion command
and any further motion commands on the motion stack will still be executed on the motor. Use the Restart
button if you want to stop any further motion and reset the drive.
MONITORING PROGRAM VARIABLES: The debug view can be used to monitor system variables in the drive.
To open the debug view, press the F10 key. A list of system and user variables appears on the right side of
the dialog box. Move these over to the monitor area to view their value. For inputs and outputs, indicators at
the bottom of the dialog box are used to show the status of the input or output.
Typical procedure for downloading and running a program:
1. From the MotionView programming screen, press Shift-F6 to compile the program and load it to the
drive. If any errors occur during compilation, correct them.
2. Press Shift-F5 to reset any faults on the drive and restart the program from the beginning.
3. Press F5 to execute the program.
4. After testing, press Alt-F5 to stop the program from executing.