SINUMERIK 840D System Variables Reference for Cycles and HMI

David Krause13 min read
HMI / SCADASiemensTechnical Reference
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

Sinumerik 840D/840D sl/828D expose a structured set of system variables that can be read from NC cycles, from the PLC, and from custom HMI applications. Engineers writing user cycles, customizing the operator interface through the Expanding User Interface (EUI) framework, or building HMI Operate dialogs frequently need to capture the current program name and path, the active MSG string, the current feed override, and the current spindle override. The Siemens documentation uses the umbrella term system variables (German: Systemvariablen) and groups them into NC-specific ($P_… / $AC_… / $AA_…), channel, axis, and tool variables, plus an HMI/OPI variable table that is mirrored through the controller's MPI/PROFIBUS/PROFINET interface.

The naming convention is strict:

  • $P_… – state information that is valid at the time of interpretation in the current block (e.g. $P_PROG, $P_PROGPATH).
  • $AC_… – accumulated channel-specific runtime data (e.g. $AC_PATHN, $AC_FGROUP).
  • $AA_… – axis-actual values that can be read from any channel (e.g. $AA_IM[X]).
  • $VC_… – preprocessor variables (only in NC programs, not in cycles).

For HMI access, the same data is exposed through the OPI (Operator Panel Interface) variable list. The mapping between NC variable and OPI variable is documented in the SINUMERIK 840D sl List Manual (system variables).

The exact variable set depends on the system software version. Major releases 02.06, 02.07, 04.04, 04.05, 04.07, 04.08, 06.20 introduce and deprecate variables. Always match the system variable manual to the version reported under Diagnostics > Version on the operator panel.

Prerequisites

  • Valid access to the controller: NCU 710.3B/720.3B/730.3B (840D sl), NCU 561/571 (840D), PCU/TCU (HMI Advanced) or PCU50.5 + TCU/HT8 (Operate).
  • System software version: identified in Menu Select > Diagnosis > Service > Version. Typical values seen in the field: NCU V02.06 + HF 04 with HMI V07.06.01.00 (Operate), or older HMI Advanced combinations.
  • Protection level: most system variables are readable in protection level 7 (key switch position 0). Some are write-protected and require the manufacturer or user password.
  • Documentation set: Programming Manual (PG), System Variables Manual (BV), Tool Management Manual, and for HMI Expanding the User Interface or Run MyScreens.

Current Program Name and Path

The two variables the source question asked about are $P_PROG and $P_PROGPATH. The first returns just the program name as a STRING, the second returns the full directory path.

$P_PROG – Active Program Name

  • Type: STRING[32]
  • Index: $P_PROG[0] = main program, $P_PROG[1] = subroutine call stack frame 1, …
  • Read access: NC cycle, synchronized action, HMI.
  • Scope: channel-specific; updated at the start of each block.

$P_PROGPATH – Active Program Path

  • Type: STRING[160]
  • Read access: NC cycle, HMI.
  • Scope: returns the path from the active drive root, e.g. //MPF.DIR/MPF.DIR/MYPROG.MPF. Inside a user cycle (CUS.DIR), it will resolve to the cycle directory unless the cycle is called with a subprogram call chain – in that case $P_PROGPATH still reflects the call context, not the original MPF location.

Capturing the True Caller Path

For a user cycle that needs to know where the program calling it was stored, traverse the call stack manually:

DEF INT _STACK_IDX
DEF STRING[32] _CALLER

FOR _STACK_IDX = 1 TO 12
  IF $P_PROG[_STACK_IDX] <> ""
    _CALLER = $P_PROG[_STACK_IDX]
  ENDIF
ENDFOR

Combined with $P_PROGPATH at each frame you can reconstruct the original MPFC/SPF location. The supplementary path info lives in $P_PART (parts counter) and $P_DIAM_STAT (diameter programming state) which are sometimes needed to fully qualify the active context.

Variable Returns Update Point Use Case
$P_PROG[0] Main program name Block start Display, log entry
$P_PROG[1..] Subroutine frame names Block start Traceback in user cycles
$P_PROGPATH Full path Block start Cycle context, MPFC lookup
$P_DIAM_STAT 0=radial, 1=diametral Block start Feed conversion

Reading the Currently Displayed MSG

Reading the MSG line content from an NC cycle is the most constrained case in the source question: the MSG string is held in the operator panel and is not part of the NC variable table.

Approach 1: Capture at Issue Time

Save the MSG into a GUD or LUD variable as the MSG is written, so a later cycle can read it back:

DEF NCK INT _MYGUD_CHAN = 1
DEF NCK STRING[160] _LAST_MSG

; --- issued from HMI or cycle ---
MSG("TOOL CHANGE IN 5 SECONDS")
_MY_GUD_CHAN = $P_CHANNO
_LAST_MSG = "TOOL CHANGE IN 5 SECONDS"

Persist the string through a Global User Data (GUD) in the _N_GUD_DEF module. GUDs survive program reset and are accessible from every cycle in the channel, including OEM cycles compiled in C++.

Approach 2: HMI/OPI Variable Read

From a HMI Operate or Run MyScreens application, read /Channel/Message/msgBuffer[n] via the OPI interface. The variable msgBuffer contains a queue of pending messages. The OPI equivalents of common NC strings include:

  • /Channel/State/infoText – current info text
  • /Channel/Message/msgBuffer[0..9] – last 10 message lines
  • /Channel/State/actBlock – current block display string

These are not available inside a synchronous NC cycle, so an HMI-side capture is the only option if you cannot modify the MSG issuing code.

The HMI Operate message system uses the cycle stack differently than HMI Advanced (840D). On HMI Advanced the variable /_N_MPF_DIR/_N_msgBuffer was readable through the OPI but the buffer size and offsets changed between 02.06 and 04.05. Always verify against the system software version in use.

Current Feed Override (%)

Feed override is exposed by several variables, each giving a different aspect of the override state. The two most useful are $AC_FOO (current feed-rate override) and $AC_PATHN (current path feed).

Override Variables

Variable Type Range Meaning
$AC_FOO REAL 0.0 – 200.0 Current feed-rate override in %
$AC_PATHN REAL – Current path feed (mm/min or inch/min)
$AC_FGROUP INT 0 – 8 Number of axes in the feedrate group
$AA_FGROUP[AXn] INT 0 – 1 Axis member of FGROUP
$AC_FCTOL[AXn] REAL – Feed rate tolerance window

Reading the Override from a Cycle

DEF REAL _OVR

_OVR = $AC_FOO         ; 100.0 means 100 % override
IF _OVR < 1.0
  ; rapid-jog mode, feed is non-modal
  GOTOF _END
ENDIF

; Use _OVR to scale programmed F
MSG("Effective F = " << $AC_PATHN << " mm/min, Override = " << _OVR << " %")

_END:

Edge Cases

  • Dry run: $AC_DRYRUN is 1 when DRY-RUN toggle is active; the override value is replaced with the dry-run feed set in machine data SD 42110.
  • Single block: $AC_SBL reports SBL state; some cycles suppress feed during single-block execution.
  • Rapid override: $AC_ROVF is the rapid-traverse override, separate from $AC_FOO.

Current Spindle Override (%)

Spindle override follows a parallel structure to feed override. The variables are channel-specific and apply to the master spindle (SETMS) unless indexed.

$AC_SVC[n]
Variable Type Range Meaning
$AC_SVC REAL 0.0 – 200.0 Current spindle override in % (master spindle)
REAL 0.0 – 200.0 Override of spindle n (1-based)
$VC_S REAL – Programmed spindle speed (preprocessor)
$AC_S REAL – Active spindle speed setpoint (incl. override)
$AA_S REAL – Actual spindle speed

Reading the Spindle Override

DEF REAL _SPIND_OVR
DEF INT _SPIND_NR

_SPIND_NR = $AC_MSNUM          ; master spindle number
_SPIND_OVR = $AC_SVC[_SPIND_NR]

IF _SPIND_OVR > 0.0
  MSG("Master spindle no. " << _SPIND_NR << ", Override = " << _SPIND_OVR << " %")
ENDIF

PLC-Side Equivalent

On the PLC, the spindle override and feed override are also mirrored to data blocks. The S7-1500/ET200SP-based PLCs in 840D sl expose:

  • DB21..DB30.DBB6 – feed override byte (0–200 %, gray-coded on HMI Advanced, binary on Operate)
  • DB21..DB30.DBB7 – rapid-traverse override byte
  • DB31..DB61.DBB3 – spindle override byte

The correspondence between the NC variable and the PLC byte is documented in the SINUMERIK 840D sl List Manual (interface signals NCK / PLC). For 840D (HMI Advanced) the same addresses apply but the encoding differs for the older HMI types.

On 828D and 840D sl with system software 04.07 SP3 and later, the override range was extended from 0–120 % to 0–200 %. Older HMI Advanced panels still treat values above 120 % as invalid and clamp to 120. Capture values into a REAL GUD to avoid the implicit integer truncation.

Storing the Values into STRING Variables

The source question explicitly asked to save the four data points into STRING variables. Sinumerik supports the standard NC functions for type conversion through built-in functions and the STRING operator <<:

Feed Override as String

DEF STRING[64] _OVR_STR

_OVR_STR = "FEED OVR = " << $AC_FOO << " %"
; _OVR_STR now holds e.g. "FEED OVR = 100 %"

Spindle Override as String

DEF STRING[64] _SP_STR

_SP_STR = "SP OVR = " << $AC_SVC[1] << " %"

Program Path and MSG as String

DEF STRING[160] _PROG_STR
DEF STRING[160] _MSG_STR

_PROG_STR = $P_PROGPATH                          ; direct STRING assignment
_MSG_STR  = $P_PART                              ; parts counter converted

; combined log line
DEF STRING[512] _LOG

_LOG = _PROG_STR << " | FOVR=" << $AC_FOO << " % | SOVR=" << $AC_SVC[1] << " %"

For the currently displayed MSG, the same direct assignment is not possible because the NC does not expose the HMI message queue as a STRING variable. The recommended pattern is to write the MSG into a GUD STRING at the same time the operator panel is updated, e.g. by an OEM MSG frame or a custom HMI dialog that mirrors the string.

HMI Advanced vs Operate – Variable Access Differences

The 840D line includes three distinct generations whose variable surfaces differ:

Aspect 840D (HMI Advanced) 840D sl (Operate) 828D (Operate)
NCU NCU 561 / 571 NCU 710.3B / 720.3B / 730.3B Integrated PPU 28x.x
HMI PCU 50.3 (WinXP/WinNT) PCU 50.5 (Linux/Sinumerik Operate) PPU-integrated
System SW 2.6 / 2.7 4.4 / 4.5 / 4.7 / 4.8 / 6.x 4.4 / 4.5 / 4.7 / 4.8 / 6.x
$P_PROG availability Yes (string len 32) Yes (string len 32) Yes (string len 32)
$P_PROGPATH Yes Yes (length 160 in 4.5+) Yes
MSG buffer (OPI) /_N_MPF_DIR/_N_msgBuffer (16 lines) /Channel/Message/msgBuffer[0..9] Same as 840D sl
EUI / Run MyScreens EUI (C/C++) Run MyScreens (XML/C) Run MyScreens
Override range 0–120 % 0–200 % (from 04.07) 0–200 % (from 04.07)

The most consequential difference for engineers porting cycles between 840D (Advanced) and 840D sl (Operate) is the OPI message buffer path. On HMI Advanced, the buffer is a single 16-line block addressed by index offsets; on Operate, the buffer is a structured variable set accessed through the standard OPI var() call.

Software Version Compatibility

The system variable set has been stable for the variables the source asks about, but minor differences exist:

Variable 02.06 02.07 04.04 04.05 04.07+ 06.20+
$P_PROG[0] ✓ ✓ ✓ ✓ ✓ ✓
$P_PROGPATH Len 80 Len 80 Len 80 Len 160 Len 160 Len 160
$AC_FOO 0–120 0–120 0–120 0–120 0–200 0–200
$AC_SVC 0–120 0–120 0–120 0–120 0–200 0–200
msgBuffer (OPI) Old path Old path New path New path New path New path

The full version matrix for any given variable is in the List Manual (BV) chapter "Availability of system variables". Cross-check the version reported in Diagnostics > Service > Version against the manual edition listed on the title page.

Verification Procedure

  1. On the operator panel, navigate to Menu Select > Diagnosis > Service > Version and record the NCU, PLC, HMI, and Operate build numbers. Example: NCU 720.3B PN V04.07 SP3 HF 04, HMI Operate V07.07.04.00.
  2. Open the matching List Manual (BV) and confirm that $P_PROG, $P_PROGPATH, $AC_FOO, $AC_SVC exist in the version's index.
  3. Create a small GUD in _N_GUD_DEF to hold the four STRINGs: DEF NCK STRING[64] MY_FOVR; DEF NCK STRING[64] MY_SOVR; DEF NCK STRING[64] MY_PROG; DEF NCK STRING[160] MY_PATH. Save and activate with NCK-Restart.
  4. From a hand-written test cycle in the CUS.DIR directory, write the four values to the GUD strings and call MSG("DIAG: " << MY_PROG << " FOVR=" << MY_FOVR).
  5. On the HMI side, open Diagnosis > Service > Variables, enter $P_PROG[0], $AC_FOO, and $AC_SVC in the variable watch. Confirm the values match the cycle output.
  6. Change the feed override potentiometer on the operator panel and confirm $AC_FOO updates within 200 ms (the HMI cycle time). Repeat for the spindle override potentiometer.

Troubleshooting Matrix

Symptom Likely Cause Corrective Action
$P_PROGPATH returns CUS.DIR inside a user cycle Variable resolves at cycle interpretation, not at the calling block Walk $P_PROG[1..n] stack or read OPI /Channel/Program/path
MSG string not readable from NC cycle MSG is held in HMI, not in NC Mirror MSG into a GUD STRING at issue time
$AC_FOO stuck at 0 Rapid-jog mode active ($AC_JOG=1) Test in MDI/auto mode, not in jog
$AC_SVC[1] returns 0 with multiple spindles Master spindle is spindle 2 after SETMS(2) Index with $AC_MSNUM instead of hard-coding 1
Override string truncates at 120 % Old system SW 2.6/2.7/4.4/4.5 or HMI Advanced Update HMI/Operate, or clamp values to 120 % for display
PLC byte DB21.DBB6 differs from $AC_FOO Encoder mismatch (binary vs gray code) on HMI Advanced Check machine data MD9024 and PLC FB1 configuration
$P_PART missing in 4.4 Older BV release; renamed to $AC_PART in 4.5+ Use the version-appropriate variable name

Edge Cases and Field-Proven Caveats

  • Channel switching: $P_PROG, $AC_FOO and $AC_SVC are channel-specific. A read from another channel returns the other channel's value. Always reference $P_CHANNO in your log string.
  • RESET state: after M30 / M0 / reset, $P_PROG retains the program name, but $AC_FOO and $AC_SVC keep their last set values. They are not zeroed on reset.
  • Preprocessor vs main run: $VC_… variables return the value planned by the preprocessor, which can lead the actual value at the block start. Use $AC_… for real-time values in cycles.
  • Concurrent programs: the channel can host a gantry or a concurrent pair. Use $AC_PATHN with caution and prefer $AA_FGROUP if the cycle operates on a single axis.
  • Write access: $P_PROG is read-only. $AC_FOO and $AC_SVC are read-only from the NC; they are written by the HMI or PLC.
  • NC cycle vs OEM cycle: a cycle compiled in C (OEM) and a cycle written in NC code share the same variable table; the C-API function GetVar() in the CPL interface uses the same names as the NC language.

Documentation Reference Points

The authoritative manuals on the Siemens Industry Online Support portal are:

For the older 840D with HMI Advanced, the Expanding the User Interface manual documents EUI patterns and the legacy OPI message buffer location.

Field Commissioning Checklist

  1. Identify the controller generation and the HMI generation. Map them to the matching BV manual edition.
  2. Confirm the GUD module is in _N_GUD_DEF and contains STRING variables large enough to hold 512 characters of composite output.
  3. Test the cycle in MDI with a known program path. Use MSG("") to clear stale messages before each test.
  4. Verify on the HMI Operate Service Overview > Variables screen that $P_PROG, $AC_FOO and $AC_SVC show the expected values.
  5. Test the full override range (0 %, 50 %, 100 %, 120 %, 200 %) on each spindle and on each channel.
  6. Log out of the cycle, power cycle the NCU, and re-test to confirm persistence of GUD values.

Which system variable gives the current program name on a SINUMERIK 840D?

Use $P_PROG[0] for the main program name as a STRING[32]. The full path is available through $P_PROGPATH (STRING[160] in system software 4.5 and later, STRING[80] in 4.4 and earlier). Both are channel-specific and read-only from the NC.

Can I read the currently displayed MSG string from an NC cycle?

No. The MSG line is held in the operator panel and is not exposed as an NC system variable. The recommended pattern is to mirror the MSG into a GUD STRING at issue time, or to read the OPI variable /Channel/Message/msgBuffer[n] from a HMI Operate or Run MyScreens application.

Which system variable reports the current feed-rate override in %?

Use $AC_FOO, which returns a REAL in the range 0.0 to 200.0. The upper limit is 120.0 in system software 2.6, 2.7, 4.4 and 4.5, and 200.0 from 4.7 SP3 onward. For rapid-traverse override, use $AC_ROVF.

Which system variable reports the current spindle override in %?

Use $AC_SVC for the master spindle or $AC_SVC[n] to address a specific spindle by number. The master spindle number is $AC_MSNUM. The same range restriction (120 % on older software, 200 % from 4.7 SP3) applies.

Why does $P_PROGPATH return the cycle directory (CUS.DIR) instead of the calling program path?

The variable resolves at the point of interpretation, which for a user cycle is the cycle file itself. To recover the original caller, walk the program stack $P_PROG[1..n] for subroutine names, and read the OPI /Channel/Program/path from the HMI side for the absolute location of the active program.

Back to blog