Teach pendant programming
Using Registers and Math Instructions
A register (R[i]) is a numeric variable that holds an integer or a decimal fraction, and the controller provides 200 of them for counting parts, computing offsets, and tracking program state. This guide shows how to comment a register on the DATA screen, teach the arithmetic and comparison instructions (add, subtract, multiply, divide, MOD, DIV, IF, SELECT), and verify the logic in test mode. It also covers the rounding, divide-by-zero, and indexing errors that surface only when a line runs.
- Step 1.
Identify the value that needs tracking
Decide exactly what the register represents, such as a cycle counter, a pallet index, or a computed offset distance. A register holds one integer or one decimal fraction, so pick a single clear meaning for each register you use.
- Step 2.
Open the register data screen and pick an open register
Press MENU, then NEXT, then select DATA, or press the DATA key directly. Press F1, [TYPE] and select Registers to show the DATA Registers screen, which lists R[1] through R[200] with their current values.
Caution: Confirm the register you choose is not already used elsewhere in the cell. Changing a register that another program relies on can affect that program's behavior.
- Step 3.
Comment the register so its purpose is clear
On the DATA Registers screen, move the cursor to the register number field and press ENTER, select a comment input method, then type the comment and press ENTER. A comment such as PART_COUNT or PALLET_IDX makes the program readable and prevents a later reuse mistake.
- Step 4.
Know what a register instruction can load
A register instruction can load a constant, another register R[i], an argument register AR[i], a position register element PR[i,j], a group, analog, digital, robot, panel, or peripheral I/O value, a program timer TIMER[i], or the timer overflow flag. That range lets one register capture a count, a sensor reading, or an I/O state in a single line.
- Step 5.
Initialize the register near the start of the program
Registers hold their value across cycles, so add an explicit instruction such as R[1]=0 at the top when the count must start fresh each run. The manual's sample program does exactly this: R[1]=0, then a loop increments and tests it.
- Step 6.
Teach the register instruction on a program line
Move the cursor to [End], press F1, [INST], and select Registers to open the REGISTER statement menu. Pick the form you need, for example 2 for ...=...+..., then use [CHOICE] to fill each element as R[ ], PR[ ], PR[i,j], or SR[ ] until the line reads like R[1]=R[1]+1.
- Step 7.
Choose the arithmetic operator
The register statement menu offers add, subtract, multiply, divide, DIV, and MOD forms. R[i]=(value)+(value) stores a sum, the minus form stores a difference, and the star and slash forms store a product and a quotient.
- Step 8.
Use MOD and DIV for counters and indexes
MOD loads the remainder of a division and DIV loads the integer part of the quotient, so R[i]=(x-(x MOD y))/y is equivalent to x DIV y. These two are the natural tools for wrapping a pallet index or splitting a running count into rows and columns.
- Step 9.
Build a polynomial when one line can do the work
You can write up to five operators on one line, for example R[2]=R[3]-R[4]+R[5]-R[6] or R[10]=R[2]*100/R[6]. Plus and minus can mix on a line, and star and slash can mix, but you cannot mix plus or minus with star or slash on the same line.
- Step 10.
Use indirect addressing to reach a register by index
Writing R[R[4]] uses the value stored in R[4] as the register number, so R[R[4]]=R[1]+1 writes into whichever register R[4] currently points at. This lets one loop step through a table of registers by incrementing the index register.
- Step 11.
Reference the register in a conditional branch
Teach IF R[i] (operator) (value) with a JMP LBL[i] or CALL as the processing, using the operators >, >=, =, <=, <, or <>. For example IF R[1]=R[2], JMP LBL[1] branches when the two counts match, and a label can be 1 to 32766.
- Step 12.
Combine conditions with and or or when needed
One IF line can carry up to five conditions joined by and, or up to five joined by or. You cannot mix and with or on the same line; if you switch one operator the controller changes the rest to match and posts a message that the operator was replaced.
- Step 13.
Use SELECT for a clean multi-way branch on one register
SELECT R[i]=value, processing lets you route on several values of one register, with an ELSE for anything that does not match. Once a matching value fires its JMP or CALL, no later matching line runs, so order the cases with that in mind.
- Step 14.
Test the register logic in test mode at reduced speed
Run the program through several cycles in test mode and watch the register update live on the DATA Registers screen. Confirm the count increments, the branch fires at the intended value, and the ELSE path behaves before you run at production speed.
- Step 15.
Decide whether the register resets or persists
Because a register keeps its value when the program ends, decide whether the count should carry across runs or start over. If it must persist, leave the initialization out of the loop; if it must reset, keep an explicit R[i]=0 where the run begins and verify it in test mode.
- Step 16.
What can go wrong: an equality test misses because of rounding
Comparing a register that holds a decimal fraction against a value with the = operator can fail, because the stored contents may not match the exact real value after rounding. When you compare against a real value, use an operator without an equal sign, such as < or >, so the branch does not silently skip.
- Step 17.
What can go wrong: a division stops the program
If a divide or MOD or DIV instruction ever runs with a zero divisor, the line faults with a divide-by-zero error and the program stops. Guard the divisor first, for example test IF R[6]=0 and branch away before the R[10]=R[2]/R[6] line runs.
Caution: Correct the value that reached zero before you rerun. Clearing the error and running again without fixing the divisor just faults on the same line.
- Step 18.
What can go wrong: an index register points nowhere valid
With indirect addressing like R[R[4]], if R[4] holds a number outside 1 to 200 or was never initialized, the line faults with an invalid index error when it executes. Initialize and range-check the index register before the indirect line, since the number and type of an indexed access are only checked at run time.
- Step 19.
What can go wrong: a hand edit on the DATA screen breaks a running behavior
Typing a new value into the register value field on the DATA Registers screen takes effect immediately for every program that reads it. Check how the register is used across the cell before you overwrite it, because a stray value can push logic down an unintended branch.
Caution: Never change a register value from the DATA screen until you know how the running programs use it. Verify any change in test mode with the work area clear before returning to production.
Common questions
- How long does Using Registers and Math Instructions take?
- Using Registers and Math Instructions is rated Intermediate and takes about 30 minutes across 19 steps.
- What tools do I need?
- You will need Teach pendant with the TP enable switch, The program that will read or update the register, A note of which registers are already used in the cell.
- What should I do before starting?
- A basic program structure already exists. You can create and edit TP programs on the pendant. You know what value the program needs to count or calculate.
- What is the first step?
- Identify the value that needs tracking. Decide exactly what the register represents, such as a cycle counter, a pallet index, or a computed offset distance. A register holds one integer or one decimal fraction, so pick a single clear meaning for each register you use.