Backup Sinumerik 840D Tool Offsets with WZ_SAVE Cycle

David Krause11 min read
Motion ControlSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Overview

The WZ_SAVE user cycle reads tool offset and magazine location data from a SINUMERIK 840D or 840D sl controller and writes an executable NC subroutine to the local passive file system. Operators run a single call - e.g., WZ_SAVE("4711") from MDI or an AUTOMATIC block - and the cycle produces a subprogram file WZ4711.SPF in /_N_SPF_DIR that, when invoked later, replays every captured length, radius, and wear value back into the controller's tool table using EXECSTRING-generated assignment statements.

This approach is a controller-resident backup that requires no HMI service archive, no external PC, and no interruption of the production schedule. It is engineered for the shop-floor scenario where a tool operator has just finished a setup, the wear values are about to be accepted, and a quick local snapshot is needed before the next job overwrites anything in the magazine list. The cycle also solves a second problem: regenerating the same tool data into the same T numbers after a tool table reset, after a controlled power-down on a controller that lost its NV-RAM contents, or after an inadvertent clear of wear values by an operator.

Prerequisites

  • SINUMERIK 840D or 840D sl with HMI Advanced or SINUMERIK Operate
  • NC software version 6.4 or higher (EXECSTRING was introduced in 6.4)
  • Read/write access to /_N_CUS_DIR for cycle storage
  • Read/write access to /_N_SPF_DIR for the generated restore file
  • All magazines on the machine must hold the same number of pockets (geometric uniformity assumption)
  • Access rights for $TC_MPP6 and $TC_DP* in the current access level
Software version warning. On NC software version 6.02 the EXECSTRING command does not exist. Calling it on older firmware yields alarm 12550 (Channel %1 block %2 name %3 not defined or option not available) or causes the interpreter to abort before the WRITE statement. Upgrade to NCK software 6.4 or higher, or switch to the file-write-only variant described in Legacy Software Path below.

Tool and Magazine Data System Variables

SINUMERIK 840D exposes the entire tool management state through system variables documented in the SINUMERIK Lists Manual on the Siemens support portal. The cycle uses two families:

System variable Index 1 Index 2 Returned content
$TC_MPP6[m,n] Magazine number m Location number n (1-based) T number assigned to that location, or 0 if empty
$TC_DP[t,i] T number t Tool data parameter index i (1..25) REAL value of tool offset parameter i of tool t

The standard assignments for $TC_DP indexes 1..15 are listed in the SINUMERIK Programming Manual under Tool offset parameters. Indexes 16..25 are reserved for cutting-edge geometry, holder description, and OEM-specific extensions. Always validate the indexes on the specific machine-build cycle before assuming a parameter carries the meaning you expect; some machine builders repurpose indexes 21..25 for adapter length compensation.

Cycle Header and Path Conventions

The cycle is identified to the interpreter as a procedure file stored in the customer-cycle directory and called with a string argument specifying the snapshot name:

%_N_WZ_SAVE_SPF ; $PATH=/_N_CUS_DIR
PROC WZ_SAVE(STRING[60] progname)
; Assumption: All magazines equal pocket count
DEF INT magazinplatz=16   ; pockets per magazine
DEF INT magazinzahl=2     ; number of magazines
DEF INT zaehl, error, tnum, mag_num, zaehl2
DEF REAL wert
DEF STRING[20] korr
DEF STRING[30] blocksatz
progname="/_N_SPF_DIR/_N_WZ" << progname << "_SPF"
DELETE(error, progname)
...
M17

The procedure signature declares the file as a callable cycle, and the leading %_N_ prefix names the file WZ_SAVE.SPF for HMI display. The path constant ; $PATH=/_N_CUS_DIR registers the file in the customer-cycle directory so it is selectable from the Program Manager or via direct subroutine call from MDI/AUTO.

Single-Magazine Operation

On a machine with one magazine of N pockets, the outer loop iterates zaehl from 1 to magazinplatz. The logic reads the T number at each location and, for non-empty locations, builds an assignment block per parameter and writes it into the target file:

FOR zaehl = 1 TO magazinplatz
  tnum = $TC_MPP6[1, zaehl]
  IF tnum > 0
    WRITE(error, progname, "; ***Platz " << zaehl << " T=" << tnum << " ***")
    FOR n = 1 TO 25
      CASE n OF 3  GOTO LOS
              4  GOTO LOS
              6  GOTO LOS
             12  GOTO LOS
             13  GOTO LOS
             15  GOTO LOS
        DEFAULT GOTO WEITER
      LOS:
        korr = "$TC_DP" << ...
        blocksatz = "wert="
        blocksatz = blocksatz << korr
        EXECSTRING(blocksatz)
        WRITE(error, progname, korr << " = " << wert)
      WEITER:
    ENDFOR
  ENDIF
ENDFOR
WRITE(error, progname, "M17")

The CASE instruction enumerates the subset of parameter indexes captured, because the WRITE pattern is identical for each. Adding or removing parameters amounts to adding or deleting GOTOF branches. Index 3 is length 1, index 4 is length 2, index 6 is radius (geometry), indexes 12 and 13 are wear on lengths 1 and 2, and index 15 is wear on radius.

Multi-Magazine Math: the pltz_num Fix

The naive single loop running zaehl from 1 to (magazinplatz * magazinzahl) does NOT produce correct indexing into $TC_MPP6[mgzn_num, zaehl] when each magazine restarts at location 1. The correct approach wraps the loop counter with an offset that resets every magazinplaats increment:

DEF INT magazinplatz=32, mgzn_num=1, pltz_num

FOR zaehl = 1 TO magazinplatz
  pltz_num = zaehl
  IF zaehl > 16
    mgzn_num = 2            ; 2nd magazine
    pltz_num = zaehl - 16   ; wrap to local location 1..16
  ENDIF
  tnum = $TC_MPP6[mgzn_num, pltz_num]
  ...
ENDFOR

The bug that triggers alarm 17030 (Channel %1 block %2 illegal array index 2) is feeding zaehl (1..32) as the second array index when the array expects 1..16. The error text from the SINUMERIK Diagnostics Manual states: An array variable was addressed with an invalid second field index. The valid second field index must lie within the defined field size and the absolute bounds (0..32766).

There is no T-number ceiling tied to 17030; the alarm is raised about the array dimension, not the T numbering. T numbers themselves can reach ~32000 before the controller's tool-data acquisition limit (a machine data setting) is reached.

Generated Restore Subprogram

The output subprogram looks like:

; ***Platz 1 Magazin= 1 T= 1 ***
$TC_DP3[1,1]=12.345
$TC_DP4[1,1]=4.567
$TC_DP12[1,1]=0.012
$TC_DP13[1,1]=0.000
$TC_DP15[1,1]=0.005
; ***Platz 2 Magazin= 1 T= 5 ***
...
M17

When the operator calls WZ4711.SPF from MDI or via a program call from any NC program, the interpreter parses each $TC_DP assignment and writes the offset back into the corresponding tool slot. The trailing M17 terminates the subroutine cleanly. This is functionally equivalent to the Restore tool data action in HMI Services > Data, but local, controller-resident, and requiring no archive file.

EXECSTRING Availability

The EXECSTRING command was introduced in NC software version 6.4. On 6.02 (the firmware reported in the failure log), the interpreter returns alarm 12550 (name not defined or option not available) or aborts on the EXECSTRING line. Two workarounds:

  1. Upgrade NCK software to 6.4 or newer. This is the recommended path and a prerequisite for many modern tool-management features such as multitool and adjacent-location handling.
  2. Skip the EXECSTRING step and rely on the file-write-only variant. The saved file then captures the values as readable text rather than executable assignments, and a human must manually paste the lines back into the tool table. This negates the cycle's automation value but keeps the capture working on legacy firmware.

Read the SINUMERIK NC software version under Commissioning > Version on the HMI. The display reads NCK software version x.x.xx.xx. Anything below 06.04.00 indicates the older 6.02 stream; 06.04.xx onwards includes EXECSTRING.

WRITE Command Error Codes

The WRITE command returns an error code in its first parameter. The cycle stores it in error and surfaces it via the ErrW label:

Code Meaning Typical cause
1 Path not allowed $PATH= directive absent or wrong; check /_N_CUS_DIR assignment
2 Path not found Typo in /_N_SPF_DIR or controller resolution
3 File not found DELETE tried to clear a non-existent file; usually benign
4 Wrong file type Trying to open an .MPF as .SPF or vice versa
10 File is full File system quota exceeded; free space in passive FS
11 File is in use Another cycle has it open; close or wait
12 No resources free All NCK file handles in use; cycle should not normally return 12
13 No access rights Current access level insufficient; check key switch position 0..3
20 Other error Consult alarm log; usually a transient FS condition

The ErrW branch is a defensive M0 stop. On a production deployment you can replace M0 with a log write and a soft return so the cycle does not halt the program flow on a transient FS error.

Cycle State Diagram

Entry PROCDELETE old fileLOOP zaehl=1..NCompute mgzn/pltztnum=$TC_MPP6IF tnum > 0

Verification Procedure

  1. Confirm file appearance. In Program Manager, navigate to /_N_SPF_DIR and verify that WZ<yourname>.SPF exists and was modified at the expected time.
  2. Open the file in the editor and check the first 20 lines for sanity: T numbers present, no $TC_DP* syntax errors, terminating M17.
  3. Manual edit + restore. Manually adjust one offset (e.g., a wear value), then run the generated restore subprogram. Re-check the offset - it should be back to the captured value exactly.
  4. Inspect the alarm protocol. There should be no 12550 (EXECSTRING availability) or 17030 (array index) entries on a successful capture.
  5. Boundary check for non-uniform magazines. If magazine pocket counts differ, parameterize the cycle with the correct per-magazine count and verify the location wrapping at the boundary.

Common Faults and Remediation

Fault Root cause Action
Alarm 17030 on second magazine locations Index 2 exceeds per-magazine location count Apply the pltz_num wrap shown in Multi-Magazine Math
Alarm 12550 on EXECSTRING line NC software older than 6.4 Upgrade NCK or switch to file-write-only variant
Generated file appears empty WRITE error code 1, 2, or 13 (path/rights) Verify /_N_SPF_DIR is enabled and access level is high enough
Compile error in PROC header $PATH directive missing on first line Add ; $PATH=/_N_CUS_DIR on the %_N_WZ_SAVE_SPF line
Wear values not restored CASE statement missing indexes 12 and 13 Add GOTO LOS branches for those indexes
Offset applied to wrong T number Guard missing; tnum=0 case passes through Add IF tnum > 0 before any $TC_DP access
Snapshot contains duplicates Magazine numbering includes loaded and unloaded slots Filter or capture both, then diff on restore

Field-Proven Caveats

  • Magazine numbering origin. The cycle assumes magazine pockets run from 1 to N. On a build where the magazine starts numbering at 0, decrement all location indices by 1.
  • T numbers vs magazine locations. A T number does not map 1:1 to a magazine location. $TC_MPP6 returns the T number on that location regardless of whether the tool is loaded or spare.
  • Capture in stable state. Run the cycle in a state with no T command pending. A tool change in progress when WZ_SAVE fires can produce transient, inconsistent snapshots.
  • Stack depth. EXECSTRING and WRITE both consume interpreter stack. Keep nesting shallow (the cycle here is intentionally flat) to avoid rare NCK aborts.
  • Restore verification. After a restore, manually check at least one representative tool to confirm geometry propagated correctly. The restore is exact-equal, but cumulative wear acceleration logic that ran after the snapshot is not reapplied.
  • Multi-channel controllers. On a controller with two channels sharing the magazine, run WZ_SAVE from the channel currently idle for tool changes; capturing from a channel holding a tool-change block can yield out-of-order writes.

Tool Offset Background

The tool length offset is the difference along the spindle axis between a fixed machine reference (spindle nose or machine zero) and the cutting edge or tip of a tool. Without the stored offset, the controller cannot position the tool tip at the programmed Z coordinate because it does not know how far the cutting edge is from the spindle face. Tool length offsets are measured during setup, stored in the tool table ($TC_DP), and applied automatically on every T call. Backing them up to an executable restore file gives you a controller-resident "golden image" you can replay on demand after a tool-table loss or operator-induced reset, as described in this tool length offset reference.

For the full family of system variables and the per-machine parameter index map, consult the SINUMERIK 840D sl Programming and Lists Manual on the Siemens support portal, and the SINUMERIK product family page for firmware bundles and configuration notes.

FAQ

Which NC software version is required for the cycle to run?

NC software version 6.4 or higher is required because of the EXECSTRING command. Older versions return alarm 12550 on the EXECSTRING line. Check the version under Commissioning > Version on the HMI.

Why does the cycle fail with alarm 17030 on the second magazine?

Alarm 17030 means the second array index is out of range. Fix it by wrapping the location counter with pltz_num so it restarts at 1 when crossing into the next magazine, instead of counting up to (magazinplatz * magazinzahl).

How are wear values captured?

Wear values are read from $TC_DP12 (wear length 1), $TC_DP13 (wear length 2), and $TC_DP15 (wear radius) for each tool T. The CASE statement must list those indexes; otherwise the WRITE loop omits them.

Can the cycle capture data from more than 32 tools?

Yes. Increase magazinplatz and magazinzahl in the DEF block to match the actual magazine layout, and ensure the passive file system has enough free space for the generated lines.

Where can I find the list of all $TC_DP indexes?

The full list of tool data parameter indexes (1..25 standard, plus OEM extensions) is in the SINUMERIK Lists Manual under Tool data ($TC_DP*). The current revision is on the Siemens support portal under SINUMERIK 840D sl documentation.

Back to blog