Robotics in Manufacturing

Teach pendant programming

Calling a Subprogram

Break repeated teach pendant logic, such as a pick or place sequence, into its own program and run it with a CALL instruction. Control transfers to the first line of the called program, and the END instruction returns control to the line right after the CALL. This guide covers teaching the call, passing arguments, nesting, and the errors that show up when arguments or stack size are wrong.

Intermediate~25 min18 steps
  1. Step 1.

    Identify the repeated logic

    Find sequences of instructions that appear in more than one place or in more than one program, such as a pick, a place, or a gripper open and close. Moving that block into one subprogram means you edit it once and every caller gets the change.

  2. Step 2.

    Register the subprogram with a clear name

    Create a new program dedicated to the repeated task and give it a descriptive name. The program name should not begin with a numeral. Set the comment (up to 16 characters), the group mask for the motion group it controls, and write protection if the logic should stay fixed.

  3. Step 3.

    Build the subprogram's instructions and positions

    Teach the motion and logic that make up the repeated task inside the new program, including any positions specific to it. Keep the subprogram focused on one job so it stays reusable from several callers.

  4. Step 4.

    End the subprogram so control returns cleanly

    Confirm the subprogram finishes with an END instruction. When END runs, control returns to the instruction immediately after the CALL in the main program, so the main routine picks up where it left off.

  5. Step 5.

    Open the main program and place the cursor

    Select the calling program and move the cursor to the line where the subprogram should run, typically to [End] when appending. The teach pendant enable switch must be on to edit.

  6. Step 6.

    Open the instruction menu and choose CALL

    Press F1, [INST] to display the control instruction menu, which lists 1 Registers, 2 I/O, 3 IF/SELECT, 4 WAIT, 5 JMP/LBL, 6 CALL, and 7 Palletizing. Select 6 CALL, then on the CALL statement menu select 1 CALL program.

  7. Step 7.

    Select the program to call

    The program list appears; move the cursor to the subprogram and select it to teach the line, for example CALL PROGRAM2. Use F2, MACRO to pick from the macro list instead, F4, INDIRECT to name the program through a string register, or F5, STRING to type the program name directly.

  8. Step 8.

    Decide whether the call needs arguments

    Arguments let you pass data between the two programs only, using argument registers in the subprogram. The first argument becomes AR[1], the second AR[2], and so on, for example CALL PROC_1(1, R[3]) sends a constant and register R[3].

  9. Step 9.

    Teach the argument values

    With the cursor at the end of the CALL line, press [CHOICE] to open the argument selection menu; if no arguments are needed, press [ENTER] to move on. Arguments can be a constant, a character string (1 to 34 characters), an argument register, a register, or a string register, and up to 30 arguments can be set. Changing only the program name keeps the arguments intact, but re-specifying the whole CALL instruction deletes all of them, so reteach the arguments if you replace the call.

  10. Step 10.

    Respect the argument register rules in the subprogram

    Read the passed values through AR[1], AR[2] and so on wherever the subprogram needs them, such as R[1]=R[1]+AR[1]. The value stored in an argument register cannot be changed inside the subprogram, so copy it into a normal register first if you need to modify it.

  11. Step 11.

    Jump into the subprogram to review it

    With the cursor on the subprogram name in the CALL line, press [ENTER] to switch the edit screen to that subprogram, and press [PREV] to return to the calling program. You can step into nested calls this way and back out up to five levels.

  12. Step 12.

    Set the stack size if the call chain is deep

    Stack size, set on the program detail screen, is the memory reserved when a program call runs. If a call fails with a stack overflow, raise the stack size: start at 500, then try 800, then 1000 until the call runs.

  13. Step 13.

    Choose CALL or RUN for the execution behavior you want

    CALL waits for the subprogram to finish, then continues the line after the call. RUN (program name) starts the other program so it runs concurrently while the caller keeps going; synchronize the two with register instructions and register condition wait instructions.

  14. Step 14.

    Test the call in test mode at reduced speed

    Step through the CALL line in test mode and confirm the subprogram executes and returns to the correct line. Watch that any arguments produce the values you expect before running at production speed. From the CALL line you can press [ENTER] on the subprogram name to open it and single-step inside, which helps confirm the taught path.

  15. Step 15.

    Reuse the subprogram from other programs

    Add a CALL to the same subprogram wherever the logic is needed rather than duplicating instructions. Confirm the subprogram's motion group matches each caller and that its taught positions are valid in every context, since a position taught for one fixture may be wrong for another.

  16. Step 16.

    What can go wrong: arguments on a conditional-branch call

    A program call used for branching, such as IF R[1]=3, CALL PROC_5, cannot carry arguments. Restructure it as IF R[1]<>3, JMP LBL[1], then CALL PROC_5(1, R[2]), then LBL[1], so the argument-bearing call sits on its own line.

  17. Step 17.

    What can go wrong: argument count or type mismatch

    The number and type of arguments are not checked when you teach the line, only when the line runs, so a mismatch surfaces later as an execution error. Confirm the main program passes the same number of arguments the subprogram uses and that each type matches how the subprogram reads it.

    Caution: An uninitialized constant or an uninitialized register index in an argument raises an unspecified-statement error when that line executes. Fill in every argument value and index before running the program.

  18. Step 18.

    What can go wrong: the call fails on a deep nest

    A long chain of calls, or calls inside calls, can exhaust the reserved stack and stop the program with a stack overflow. Increase the stack size on the program detail screen in steps, or flatten the call structure so fewer programs are open at once.

    Caution: Do not clear a stack or argument error and simply rerun without fixing the cause. Correct the argument set or stack size first, then retest in test mode at reduced speed with the work area clear.

Common questions

How long does Calling a Subprogram take?
Calling a Subprogram is rated Intermediate and takes about 25 minutes across 18 steps.
What tools do I need?
You will need Teach pendant with the TP enable switch, The main program that will issue the call, A list of the positions and registers the repeated logic uses.
What should I do before starting?
The repeated logic to be moved into a subprogram is already identified. You can create and edit TP programs on the pendant. You know which registers and motion group the logic depends on.
What is the first step?
Identify the repeated logic. Find sequences of instructions that appear in more than one place or in more than one program, such as a pick, a place, or a gripper open and close. Moving that block into one subprogram means you edit it once and every caller gets the change.

Attribution

Procedure steps on this page are checked against the site's editorial safety rules and manufacturer-manual sourcing standards.

Last reviewed: 2026-07-21.

Edited by Mike Ramsey / Reliable Media.Editorial process