Overview: Spindle Tool State on Sinumerik 828D
The Sinumerik 828D stores every tool the controller knows about in a tool-management data block. Each tool occupies a location in a magazine. The spindle itself is treated as a virtual magazine with the fixed internal number 9998; the loader gripper, when fitted, occupies magazine 9999. After every tool change, the NC rewrites the spindle's location descriptor so that the active tool in the spindle is identifiable from any client that can read NC variables - including the integrated PLC.
The HMI pulls this state automatically and renders the active tool number on screen. A PLC that drives a hard-wired 7-segment indicator, a tower light, an operator-panel LED column, or a stand-alone DNC cell cannot subscribe to the HMI display; it must read the tool-management system variables through the BTSS variable service and convert the result into BCD for the indicator.
This reference documents the exact procedure used to expose the active spindle tool number to the integrated PLC of the 828D PPU. The procedure applies to both the milling and turning variants of the 828D, including 828D-based Tool Turning (TT) packages, as long as the tool-management option bit is enabled in the controller license.
Prerequisites
| Item | Requirement |
|---|---|
| Controller | Sinumerik 828D PPU (PPU24x / PPU26x / PPU28x) with tool-management option licensed |
| Software | Sinumerik Operate on the PPU and PLC Programming Tool 828D (S7-200 compatible) installed on the engineering PC |
| Access level | Manufacturer password (access level 1) for machine-data changes |
| Hardware path | Ethernet X130 (BTSS) reachable from the engineering PC, subnet 192.168.214.x |
| Display interface | 24 V PLC outputs wired to a BCD-input 7-segment display (Wachendorff, SIKONETZ, or generic BCD module) |
| Magazine configuration | At least one real magazine configured and the spindle assigned to magazine 9998 (default) |
| License | 6FC5800-0AS00-0YB0 (tool management) or equivalent option bit active |
The 828D PLC is an integrated SIMATIC S7-200 class controller. It uses 24 V DC inputs and outputs and exchanges data with the NC over the BTSS variable service, not over PROFIBUS/PROFINET PUT/GET like an S7-300/400. Plan PLC logic around this constraint.
Architecture: From Spindle to PLC to Display
Three logical blocks form the data path:
- NC tool-management database (non-volatile; mirrored in DRAM during run-time).
- BTSS variable service accessed from the PLC via FC21 / variable-selector interface.
- PLC string-to-BCD conversion and parallel output to the 7-segment indicator.
The PLC reads the NC variable by name, decodes the identifier, formats the number into BCD nibbles, and drives four output bytes (16 lines) to the indicator. With two digits this requires 8 outputs; with four digits it requires 16 outputs. Always reserve one extra output as a "spindle empty" status LED so the operator can distinguish a real T-zero from "no tool clamped".
System Variable Reference
| Variable | Meaning | Index 1 | Index 2 | Type |
|---|---|---|---|---|
| $TC_MPP6[m,l] | Tool number assigned to magazine location (m, l). Returns 0 when the location is empty. | Magazine number | Location number | INT |
| $TC_MPP1[m,l] | Magazine number the location belongs to (mostly for verification of location type). | Magazine number | Location number | INT |
| $TC_MPP2[m,l] | Location type. 1 = spindle, 2 = gripper, 3+ = magazine-specific. | Magazine number | Location number | INT |
| $TC_TP1[n] | Internal tool number (T-number) used by the NC. Matches the value returned by $TC_MPP6 when the location is loaded. | Internal T-no. n | - | INT |
| $TC_TP2[n] | Tool identifier (name) as displayed by the HMI. Numeric when MD52270 bit 7 is set; alphanumeric otherwise. | Internal T-no. n | - | STRING[32] |
| $TC_TP11[n] | Optional sub-group identifier. Not used in this procedure. | Internal T-no. n | - | STRING[4] |
| $AC_MSNUM | Active master spindle (1-based; 0 = none). Determines which spindle's tool is "active". | - | - | INT |
| $AC_MTHNUM | Active master toolholder (milling; 1-based; 0 = none). | - | - | INT |
| $AC_SPNUM | Active spindle. Can differ from the master after SETMS / spindle select. | - | - | INT |
The internal T-number space is integer-only and is set when the tool is first loaded into the magazine. $TC_TP2 is the HMI-visible identifier; its format depends on machine data. On HMI Advanced and Operate, the identifier is shown left-justified and may contain trailing blanks.
Magazine Numbering Convention
The 828D uses reserved magazine numbers for the spindle and loader:
| Magazine number | Designation | Location 1 default | Notes |
|---|---|---|---|
| 1 ... 9996 | Real magazine (chain, disk, rack) | Defined per magazine | Configured in MD52272 and per-magazine setup |
| 9997 | Buffer / internal (some applications) | Defined per magazine | Verify in the Lists manual for the firmware version in use |
| 9998 | Spindle (or tool holder on milling) | Spindle 1 location | Always present when tool management is active |
| 9999 | Gripper / loader finger | Gripper 1 location | Optional; present only when a gripper is configured |
For a single-spindle turning or milling centre, the active tool is read at $TC_MPP6[9998, 1]. Multi-spindle machines use additional locations of magazine 9998; the operator's active spindle is the one set with SETMS() in the NC program or with the master spindle setting in the HMI.
Reading the Spindle Location
The two-step lookup is mandatory. Skipping step 2 and using only $TC_MPP6 will not work for an alphanumeric identifier without bit 7.
- Read $TC_MPP6[9998, 1]. A return value of 0 means no tool is in the spindle.
- If the return value is non-zero, treat it as the internal T-number N. Read $TC_TP1[N] to verify that N matches the internal tool index, or read $TC_TP2[N] to obtain the identifier string.
- Convert the identifier to a numeric value as required by the display. With MD52270 bit 7 set, $TC_TP2[N] is a string representation of N itself.
The 828D PLC does not have a native STRING-to-INT block comparable to the S7-300 FC38. Implement a manual conversion using character-by-character ASCII subtraction (0x30 for digits '0' to '9') and bounds checking. The conversion is required because the NC side always returns the identifier as a STRING regardless of MD52270 - the MD only changes what string is stored, not the data type.
Configuring MD52270 Bit 7
MD52270 ($NM_TOOL_MANAGEMENT_MASK) controls tool-management behaviour. Per source guidance, set bit 7 of MD52270 so that the tool identifier matches the internal T-number. With this bit set, $TC_TP2[N] returns a string containing only decimal digits whose numeric value equals N.
Procedure to set the bit:
- On the PPU, press the menu key and navigate to Setup -> Machine Data.
- Filter by MD52270. The default name shown is $NM_TOOL_MANAGEMENT_MASK.
- Enter the value (default + 128 to set bit 7). Example: 0x80 = 128 decimal.
- Press the softkey "Activate MD" and confirm with the manufacturer password.
- NCK performs a warm restart. Tool list on the HMI must now show numbers instead of names.
Related machine data to review before commissioning:
| Machine data | Designation | Relevance |
|---|---|---|
| MD52270 | $NM_TOOL_MANAGEMENT_MASK | Bit 7: identifier equals internal T-no. |
| MD18080 | $MN_MM_TOOL_MANAGEMENT_MASK | Memory model for tool management |
| MD52271 | $NM_TOOL_MANAGEMENT_OPTIONS | Options such as tool life, wear |
| MD52272 | $NM_TOOL_MANAGEMENT_PROPERTIES | Properties of the tool-management system |
| MD52274 | $NM_TOOL_MAGAZINE_TYP | Magazine type per index |
| MD52214 | $NM_TOOL_LOAD_DEFAULT_MAG | Default magazine for loading |
Always verify the bit assignment of MD52270 against the official Sinumerik 828D Lists Manual for the firmware version running on the PPU. Bit numbering and meaning have changed across firmware releases.
PLC Implementation: Reading NC Variables
The 828D integrated PLC uses the BTSS variable service to read named NC variables. The standard block is FC21 ("read_var") or, in newer PLC libraries, the "NC-Var-Selector" wrapper that handles the request/response cycle.
A minimal PLC call sequence to read the spindle location and the identifier:
// FB-style call on the 828D PLC, OB1
CALL "read_var"
REQ := M10.0 // trigger on rising edge
NUMVAR := 2 // two variables per request
ADR1 := '$TC_MPP6[9998,1]'
RD1 := DB100.DBD0 // internal T-number, INT32
ADR2 := #adr_tc_tp2 // built dynamically (see below)
RD2 := DB100.DBD4 // STRING[32]
RETVAL := MW12 // FC21 return code
BUSY := M10.1
DONE := M10.2
ERROR := M10.3
The variable name format follows the OPC-style NC identifier: dollar sign, TC namespace, array brackets with magazine and location separated by a comma. The string is null-terminated ASCII. Because $TC_TP2 takes the internal T-number as the index, build the second address dynamically:
// Construct "$TC_TP2[N]" where N = internal T-number from step 1
// Use STRING concatenation in the 828D PLC user program.
L DB100.DBD0 // N from previous read
T #T_index_int
CALL "INT_TO_STRING"
IN := #T_index_int
OUT := DB110.DBX0.0 LEN 6 // e.g. "000003"
CALL "STRING_CONCAT"
IN1 := '$TC_TP2['
IN2 := DB110.DBX0.0
IN3 := ']'
OUT := #adr_tc_tp2
// Result for N=3: "$TC_TP2[3]"
Drive the FC21 call from a cyclic OB (typically OB1, with REQ pulsed by a timer at 200 ms). Polling faster than 100 ms adds load to the NC without improving display readability. The 828D NC limits the BTSS variable service to a few hundred requests per second across all clients combined.
String-to-BCD Conversion
The 828D PLC receives $TC_TP2 as a STRING whose first characters are decimal digits. A robust conversion must handle:
- Leading blanks (" 12" for tool 12 when identifier width is fixed).
- Trailing nulls and spaces.
- Negative sign for tools whose name is forced to start with "-" (rare).
- Non-numeric characters (a fault condition when MD52270 bit 7 is not set or has been overridden by an operator).
A defensible conversion routine in the 828D PLC STL style:
// Scan the identifier, skip leading blanks (0x20), collect digits,
// clamp to 0-9999, output BCD nibbles for 4-digit display.
FUNCTION "T_ID_TO_BCD" : VOID
VAR_INPUT
s_id : STRING[32]; // identifier string from NC
END_VAR
VAR_OUTPUT
bcd_lo : BYTE; // BCD of last two digits
bcd_hi : BYTE; // BCD of first two digits
valid : BOOL; // TRUE if all chars were digits
empty : BOOL; // TRUE if identifier is empty / blanks only
END_VAR
VAR_TEMP
i : INT;
ch : BYTE;
val : INT;
END_VAR
BEGIN
bcd_lo := 0; bcd_hi := 0; valid := TRUE; empty := TRUE; val := 0;
FOR i := 1 TO 32 DO
ch := s_id[i];
IF ch = 0 THEN EXIT; END_IF;
IF ch = 0x20 THEN CONTINUE; END_IF;
empty := FALSE;
IF (ch < 0x30) OR (ch > 0x39) THEN
valid := FALSE; EXIT;
END_IF;
val := (val * 10) + (ch - 0x30);
IF val > 9999 THEN valid := FALSE; EXIT; END_IF;
END_FOR;
// BCD pack
bcd_lo := (val MOD 10) + ((val / 10 MOD 10) * 16);
bcd_hi := ((val / 100) MOD 10) + ((val / 1000 MOD 10) * 16);
END_FUNCTION
The four BCD nibbles occupy two bytes and drive one or two BCD-input 7-segment display modules. Add a status byte that maps empty/valid/invalid to three indicator LEDs on the panel.
7-Segment Indicator Wiring
| PLC output byte | Bit | Display signal | BCD weight |
|---|---|---|---|
| QB20 | .0 | 8 (least sig bit of bcd_lo) | 1 |
| QB20 | .1 | 4 | 2 |
| QB20 | .2 | 2 | 4 |
| QB20 | .3 | 1 (most sig bit of bcd_lo) | 8 |
| QB21 | .0 | 8 (least sig bit of bcd_hi) | 10 |
| QB21 | .1 | 4 | 20 |
| QB21 | .2 | 2 | 40 |
| QB21 | .3 | 1 (most sig bit of bcd_hi) | 80 |
| QB21 | .4 | Empty LED | status |
| QB21 | .5 | Invalid LED | status |
| QB21 | .6 | Master spindle active LED | status |
| QB21 | .7 | reserved | - |
Use 24 V PLC outputs directly only if the indicator module accepts 24 V logic levels. For 5 V TTL inputs, add an interposing relay or a signal-conditioning block; do not drive 5 V TTL inputs directly from the 828D outputs as the noise margin on long cable runs can cause ghosting on the display.
Master Spindle and Master Toolholder
The "active tool in spindle" is only unambiguous after the master spindle (turning) or master toolholder (milling) has been set. By default the master spindle is spindle 1, but the part program can call SETMS(n) or the operator can change the master spindle from the HMI. To display the right tool on multi-spindle machines, also read the master spindle / master toolholder state.
Use $AC_MSNUM to compute the spindle-location index. For spindle 1 use $TC_MPP6[9998, 1]; for spindle 2 use $TC_MPP6[9998, 2]; and so on. The official Siemens support note on master spindle/toolholder handling is summarised in the following reference:
The practical rule for the PLC: set the desired spindle as master spindle (or toolholder as master toolholder) and, only if required, reset the master spindle / master toolholder afterwards. Polling $AC_MSNUM each cycle keeps the display synchronised with whichever spindle the program or operator has flagged as active.
On a single-spindle milling or turning centre, $AC_MSNUM is always 1 and the table simplifies to one location. On a multi-channel machine, the read must happen in the channel whose spindle carries the tool being displayed, since each channel has its own $AC_MSNUM.
Multi-Channel and Multi-Spindle Variants
On a 828D with two channels (for example a milling main spindle plus a turning sub-spindle), each channel owns its own magazine configuration. The PLC must address the BTSS request with the correct channel identifier. The BTSS string convention is:
// Channel 1 spindle:
// $TC_MPP6[9998,1] (default, no prefix)
// Channel 2 spindle:
// /Channel/2/State/$TC_MPP6[9998,1]
// Master toolholder on milling channel:
// $TC_MPP6[9998, $AC_MTHNUM ]
For milling centres with multiple tool holders (typically spindles 1 and 2 on a 5-axis machine), the master toolholder ($AC_MTHNUM) determines which holder's tool is "active". Read $AC_MTHNUM first and use it as the location index for magazine 9998.
Verification and Commissioning
- Power the PPU and connect via Sinumerik Operate. Confirm the tool list shows numeric identifiers (MD52270 bit 7 active). If names still appear, MD52270 has not been set or the change has not been activated.
- Load a known tool into the spindle with T="1" or via M06. Verify on the HMI that tool 1 appears in the spindle field.
- From the engineering PC, run the PLC variable test in the PLC Programming Tool 828D. Watch DB100.DBD0 - it must read 1.
- Trigger the BCD conversion by setting M10.0. The 7-segment indicator must show "01".
- Unload the spindle (T="0" or M06 with empty source). DB100.DBD0 must read 0 and the empty LED must light.
- Load a 3-digit identifier (e.g. T=125). The display must show "125" or the last three digits if only a 2-digit module is fitted; in that case the overflow nibble must clamp to "99" or trigger the invalid LED rather than wrap.
- Cycle the master spindle with SETMS(2) on a dual-spindle machine. The display must update to the location pointed to by $AC_MSNUM.
- Toggle the NCK reset and watch the watchdog. After restart, the indicator must settle to the current tool within two poll cycles (about 400 ms).
For production handover, document the MD change in the machine record and back up the configuration to the CF card so that a PPU replacement re-applies MD52270 bit 7.
Troubleshooting Matrix
| Symptom | Likely cause | Diagnostic | Remedy |
|---|---|---|---|
| Display always shows "00" or empty LED | $TC_MPP6 returning 0; spindle considered empty | Watch DB100.DBD0 in PLC programming tool | Verify magazine 9998 location 1 is bound to spindle in MD52272 |
| Display shows "FF" or invalid LED on | $TC_TP2 contains non-digit characters | Read $TC_TP2[N] directly from HMI diagnosis page | Set MD52270 bit 7 or change tool naming convention |
| Display flickers between two values | BTSS read timing too slow / queue too deep | Trace FC21 REQ and DONE; check for retry storms | Increase poll interval to 200-500 ms; reduce NUMVAR per request |
| Display shows wrong tool after SETMS | Hard-coded magazine 9998 location 1 | Watch $AC_MSNUM | Index location by $AC_MSNUM |
| Display shows correct number but tool list on HMI shows names | MD52270 bit 7 not active | Check MD52270 in the MD list | Set bit 7 = 1, NCK reset, verify on tool list |
| Display freezes after PLC stop-run | FC21 RETVAL not handled; old value latched | Check RETVAL on read_var | Add timeout watchdog; reset indicator on RETVAL <> 0 |
| Display lags by one tool change | BTSS update delayed by NC cycle | Compare with HMI spindle field timing | Acceptable in most cases; if not, switch to NCK interface byte $A_DBB |
| No response from FC21 at all | BTSS route blocked or wrong area | Ping X130; check subnet | Confirm 192.168.214 subnet for NC; correct routing table |
| Display shows a stale value after NCK restart | PLC initial value not blanked on cold start | Check OB100 startup | Zero QB20/QB21 and force empty LED in OB100 |
| Display shows last tool after M00 / program end | $TC_MPP6 not cleared on program end | Inspect tool-change cycle | Acceptable; toggle empty LED only when spindle physically empty |
Edge Cases and Field-Proven Caveats
- Memory reservation for tool management: MD18080 ($MN_MM_TOOL_MANAGEMENT_MASK) must include the relevant bits or the NCK rejects the request at start-up.
- The 828D PLC user program has limited working memory (typically 24 KB code + 8 KB data). Keep the conversion routine compact; the snippet above is intentionally small.
- The string returned by FC21 for $TC_TP2 is null-terminated at the first zero byte, but trailing blanks (0x20) may be retained depending on the NCK version. Handle both.
- On multi-channel machines, each channel has its own $TC_MPP6 view. Read from the channel whose spindle you want to display.
- If the application uses tool wear or multi-edges ($TC_TP8 / $TC_TP11), expand the conversion to expose those via additional 7-segment groups or supplementary panel lamps.
- The tool change cycle on the 828D is interruptible. While M06 is active, $TC_MPP6 can briefly read 0 or read the previous tool, depending on cycle phase. Either accept a brief flicker or latch the display only when the cycle is idle.
- Do not write to $TC_MPP6 from the PLC. The PLC is a read-only client for these variables; writes go through the tool change cycle.
Alternative: Direct PLC-NCK Interface Bytes
For high-update applications, the 828D exposes a mirrored copy of the tool location data through the PLC-NCK interface ($A_DBB / $A_DBW). The exact offsets depend on the firmware build and the slot assignment of the PLC basic program. Consult the PLC basic program documentation for the version in use. The BTSS method via FC21 remains the portable, version-independent choice and is preferred for first-time integration.
FAQ
What is the fixed magazine number for the spindle on a Sinumerik 828D?
The spindle is represented as magazine 9998. Location 1 is the spindle 1 tool slot for single-spindle machines. The gripper (if equipped) uses magazine 9999.
Which NC variable tells me the active tool in the spindle?
Read $TC_MPP6[9998, 1] first; a non-zero value is the internal T-number N. Then read $TC_TP2[N] for the displayed identifier. With MD52270 bit 7 set, $TC_TP2[N] is the decimal string of N itself.
Why must I set MD52270 bit 7 to use a numeric display?
The 828D PLC lacks native STRING-to-INT operations on the S7-200 class controller. Setting MD52270 bit 7 makes the identifier match the internal T-number, so a character-by-character ASCII scan of $TC_TP2 yields a number usable as BCD without needing numeric conversion libraries.
How do I display the active tool when the master spindle changes?
Read $AC_MSNUM each poll and use it as the index into magazine 9998 (location = $AC_MSNUM). On a single-spindle machine $AC_MSNUM is always 1. The Siemens support note on master spindle and master toolholder handling covers this for multi-spindle configurations.
Can I read the spindle tool number without FC21?
Yes. The 828D also exposes a mirrored location-data block in the PLC-NCK interface byte area. Read $A_DBB or $A_DBW at the documented offsets for the spindle location. This method is faster but requires the offsets for the specific firmware build; FC21 remains the portable choice.