Operation & Software Manual
222
Direct Drives & Systems
Chapter D: Programming ETEL Doc. - Operation & Software Manual # DSC2P 903 / Ver. F / 3/6/05
14.2.4 Routine commands: CAL, RET and POP
The controller programming allows the use of routines. A routine is an independent part of a sequence,
delimited by a label and a RET command (RETurn). When the controller meets the CAL command (CALl), the
routine is executed until it reaches the RET command, then the sequence continues from the command
following the CAL command.
It is possible for a routine to call another routine (refer to the example below), which can itself call a third routine,
etc. It is possible to go up to 256 levels. The routines are said to be embedded. However, a routine cannot
call itself.
When a routine is called, the number of the line following the CAL command is memorized in a stack. As soon
as the routine is finished, the sequence goes on from the line stored on the top of the stack and this line is
erased from the stack. With embedded routines the stack may contain a large amount of line numbers, and if
the controller detects an error when the sequence is executing a high level subroutine, the sequence jumps to
the particular label n°80, as seen previously. If in this label the error is processed and the sequence execution
is started from the first line, then the numbers of lines which were stored in the stack will remain because they
have not been erased with the RET command. A second error may appear and fill in a bit more the stack. A
capacity overflow may happen if several errors happen. To avoid it, the contents of the stack is erased while
treating the error on label 80 with the POP command (POP up).
Remark: The values contained in the accumulator are kept when a routine is over (RET) even if the routine
also uses an accumulator and even if there are several embedded routines.
If the RET command is used in a routine; it is not possible to use a POP command in the same
routine (stack erased, no address where to go back to).
Example:
:10.1 ;Label 10, example start
CAL.1=50 ;Routine call, the sequence execution goes on from label 50.
Instruction 3
Instruction 4
END.1 ;End of main sequence, the sequence execution finishes.
:50.1 ;Label 50. First routine starts.
Instruction 5
CAL.1=100 ;The routine calls a subroutine, the execution goes on from label 100.
Instruction 6
RET.1 ;End of the first routine, the sequence goes on with instruction 3.
:100.1 ;Label 100. Second routine starts.
Instruction 7
Instruction 8
RET.1 ;End of the second routine, the sequence execution goes on with the instruction
which follows the CAL command, it is instruction 6.
:80.1 ;Particular label 80. In case of error, the sequence execution goes on from this label.
POP.1 ;The stack is erased.
Instruction 9 ;The error is processed.
JMP.1=10 ;Jump to label 10
END.1 ;Stop the sequence
In the example above, the commands have been executed in the following order: Instruction 5, 7, 8, 6, 3 and
4. Instruction 9 is only executed when an error is displayed.
Command <P1> <P1> value Comment
CAL.<axis> = <P1> <label_#> 0-511 Call of the subroutine located in label shown by <P1>.
RET.<axis> --
Tells the end of the subroutine. The execution goes on at line following CAL
instruction.
POP.<axis> - - Clears all levels of the stack.