Calling Sinumerik 840D sl Subprograms During Axis Motion

David Krause12 min read
Motion ControlSiemensTechnical 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

1. Problem Overview

On a Sinumerik 840D sl controller running Operate v4.5 SP4, the engineer wants to launch a subprogram the instant a digital input becomes true while an axis is still traversing. The block from the original case looks like this:

WHEN ($A_IN[32]==1) AND ($AA_IM[Y1]>100) DO M80
G0 G90 Y1=400

The synchronous action WHEN ... DO fires while G0 is still moving Y1 toward 400 mm, so the auxiliary function must be interpreted as a subprogram call rather than as a hard-coded M word. A direct swap to CALC_Y1.spf in the action is rejected by the parser because synchronized actions in the NCK only accept a fixed set of keywords (axis names, M/S/T/H functions, GUD writes, and SET/CLR/DEF instructions). The subprogram name is not in that set.

This article documents the only sanctioned path on the 840D sl for that pattern: an Asynchrones Unterprogramm (ASUB / ASUP) bound to an M function via machine data, with the synchronous action calling the M word.

Terminology warning. Siemens uses ASUB in English manuals and ASUP in the German DocOnCD and many system variable names (for example $AC_ASUP). They are the same feature. The German word Asynchrones Unterprogramm literally means "asynchronous subprogram."

2. ASUB vs ASUP: Nomenclature

Siemens documentation is inconsistent across revisions. Use the mapping below to translate between German and English sources when reading manuals side by side:

German (DocOnCD) English (Programming Manual) Meaning
Asynchrones Unterprogramm (ASUP) Asynchronous Subprogram (ASUB) Subprogram started independently of the part program block flow
ASUP_START_MASK / ASUP_EDIT_MASK ASUB_START_MASK / ASUB_EDIT_MASK MD identifiers; English manuals spell them ASUB
SETINT / PRIO SETINT / PRIO Interrupt-driven ASUB trigger from the NCK
Warteschlange Queue ASUB execution queue when multiple triggers overlap

For the 840D sl with Operate v4.5 SP4 the active option code in the license file is the English string ASUB, and the licensed option is billed under catalog number 6FC5800-0AS00-0YB0 (always verify against the active license on the CF card under /card/sinumerik/license).

3. Synchronized Action (WHEN…DO) Primer

Synchronized actions are real-time condition/action pairs evaluated every IPO cycle. On the 840D sl the relevant syntax is:

WHEN <condition> DO <action>
WHEN ... DO M<n>     ; M function call (valid)
WHEN ... DO CALC_Y1   ; subprogram call (NOT valid in the action)

The parser accepts only the following tokens in the action of WHEN ... DO on a 840D sl NCU 710/720/730/732:

  • Axis names with motion (e.g. Y1=420) — only with implicit/quick couplings
  • M, S, T, H, D, F auxiliary functions
  • Assignments to GUD, LUD, R parameters and system variables (SET, CLR)
  • Pre-defined DEF instructions (DEF INT _n=5)

This is why a direct CALC_Y1 in the action line returns alarm 20150 "Action not permissible in synchronized action" or, depending on firmware, 20160 "Syntax error in synchronized action". The substitution must therefore happen at the M-function layer using machine data.

4. M Function Substitution via MD 10715 and MD 10716

Siemens provides two related machine data items that bind an M number to a cycle/subprogram name:

MD Name Type Meaning
10715 $MN_M_NO_FCT_CYCLE INT M number that is replaced by a subprogram call before interpreter execution
10716 $MN_M_NO_FCT_CYCLE_NAME STRING Name of the subprogram (extension .spf) that is launched when MD 10715 fires
10714 $MN_M_NO_FCT_EOP INT M number issued at end of program; related mechanism
10717 $MN_M_NO_FCT_CYCLE_MODE DWORD Bit 0: log axis positions; Bit 1: stop axes before subprogram; Bit 2: issue M0 internally; default 0

The original engineer observed that using MD 10715/10716 inside a WHEN ... DO produced an alarm because the default of MD 10717 expects the substituted M to be programmed in a part-program block — the substitution path was not designed for synchronized actions.

Field finding. MD 10715/10716 substitution runs at the interpreter, before the synchronized-action evaluator sees the block. Therefore, in a synchronous action WHEN ... DO M80 the M80 token is presented as a function call to the PLC, not as a subprogram call. The PLC can choose to acknowledge the M and trigger an ASUB, or it can replace M80 by writing a request to the NCK using FB9/FB10 (ASUB start from PLC).

5. The Asynchronous Subprogram (ASUB) Solution

The canonical 840D sl pattern for "launch a subprogram mid-motion" is to start an ASUB. There are three trigger sources:

  1. SETINT(n) inside the part program — interrupt-driven ASUB bound to a digital/NCK input.
  2. PLC request — FB9 / FB10 (PI service _N_ASUP) called from the PLC program.
  3. Synchronized action with M function — the M is sent to the PLC, which raises the ASUB via FB9/FB10.

For the case in the source (a synchronized action watching a digital input), the M-trigger path is the cleanest because it keeps the NCK logic identical to a normal M-function call and pushes only the asynchrony into the PLC, where it can be diagnosed with the standard cross-reference.

6. Required Options and Configuration

Confirm the following before commissioning:

Item Required value Where to check
ASUB option (6FC5800-0AS00-0YB0) Licensed Operate > Setup > License; or /card/sinumerik/license on the CF card
MD 11640 $MN_ASUP_ENABLE_MASK Bit 0 set (value ≥ 1) — enables ASUB start Operate > Startup > Machine Data
MD 20110 $MC_RESET_MODE_MASK Channel reset behavior; must not mask out interrupt programs Channel-specific MD
MD 20184 $MC_GCODE_RESET_MODE Reset behavior for modal G codes Channel-specific MD
PLC FB9 / FB10 Present in cyclic OB1 Cross-reference in STEP 7 / TIA Portal
PLC DB for ASUP request Background DB exists Symbol table in the PLC project

If MD 11640 bit 0 is 0, every ASUB start request from FB9/FB10 is rejected with alarm 4250 "ASUB not enabled". Set it to 1 and NCK reset.

7. Complete Working Example

Assume the engineer wants to run a calculation named CALC_Y1.SPF on channel 1 the moment input 32 rises AND Y1 has passed 100 mm. The axis Y1 must not stop.

7.1 Part program _N_MPF_DIR/_N_MAIN_MPF

; --- Main program ---
N10 G0 G90 Y1=0
N20 WHEN $A_IN[32]==1 AND $AA_IM[Y1]>100 DO M80
N30 G0 G90 Y1=400 F5000
N40 M30

7.2 Cycle directory setup

; CALC_Y1.SPF must live in the manufacturer cycle directory
; /card/sinumerik/cma or /card/sinumerik/oem or /card/sinumerik/user
; so that the NCK can resolve it without an explicit path
;
; --- File: _N_CALC_Y1_SPF ---
;$PATH=/_N_CMA_DIR
PROC CALC_Y1 SAVE
  ; axis remains moving; do NOT use G04 or M00
  R10 = $AA_IM[Y1]
  R11 = $AA_VACTM[Y1]
  ; .. user logic here ..
  ; e.g. compute a feed-override adjustment
  IF R11 > 8000
    $AC_OVR = 80      ; soft cap feed override at 80 %
  ENDIF
  RET

7.3 PLC side: trigger ASUB on M80

// SCL fragment - cyclic OB1
// M80 is the in-band marker; the ASUB name is "CALC_Y1"

IF "M_Fct_M80_Ack" AND NOT "M_Fct_M80_Prev" THEN
    "ASUP_DB".INTNO      := 1;            // interrupt slot
    "ASUP_DB".PRIO       := 100;          // higher = more urgent
    "ASUP_DB".LIFTFAST   := FALSE;
    "ASUP_DB".SET_MASK   := 'B0000';
    "ASUP_DB".CLEAR_MASK := 'B0000';
    "ASUP_DB".TYPE       := 'B0010';      // ASUP_START = 1, with PRIO
    "ASUP_DB".PATH       := '/_N_CMA_DIR/_N_CALC_Y1_SPF';
    "ASUP_DB".ADDR       := 'ASUP';
    FB10_DB(REQ := TRUE, INTNO := 1,
            LADDR := "ASUP_DB".LADDR,
            DB_No := "ASUP_DB".DB_NO);
    "ASUP_Triggered" := TRUE;
END_IF;

"M_Fct_M80_Prev" := "M_Fct_M80_Ack";

When M80 is recognized in the synchronous action, the NCK raises the M-output and sets M_Fct_M80_Ack. The PLC opens a window with FB10, which calls the PI service _N_ASUP. The NCK interrupts the current IPO cycle, stores all machine state, and starts CALC_Y1.SPF in a higher priority level. The original G0 Y1=400 continues to interpolate during the ASUB unless the ASUB itself issues a stop. By default the axes do not stop, which is what the engineer needs.

8. PLC-Based Calculation Alternative

If the calculation in CALC_Y1.SPF is a handful of arithmetic operations on real values, Siemens advises moving the math into the PLC. Reasons:

  • No ASUB license required.
  • No NCK state save/restore (the ASUB mechanism snapshots the interpreter).
  • No PLC/NCK round-trip latency for each function call.
  • Diagnostic visibility through STEP 7 / TIA Portal cross-reference.

Use the fast NCK interface (F-NCK) for high-rate values, or read $AA_IM, $AA_VACTM from the PLC once per IPO2 cycle (default 4 ms). A typical data path is:

// PLC reads current Y1 actual position
"Y1_ActualPos" := "NCK_Var".read("$AA_IM[Y1]", channel := 1, axis := 5);
IF "DI_32" AND ("Y1_ActualPos" > 100.0) THEN
   "Y1_FeedOverride" := LIMIT("Y1_ActualPos", 0, 120);  // PLC-side logic
END_IF;

9. Second-Channel Alternative

The second recommendation in the field report is to put the calculation in a second NC channel. On 840D sl a single NCU 710/720/730/732 can run up to 10 channels; channel 2 can be configured as a pure computation channel with no axes:

MD Value Effect
MD 20000 $MC_CHAN_NAME "CHAN2" Identifier visible in HMI
MD 20050 $MC_AXCONF_GEOAX_ASSIGN_TAB (0,0,0) Disable geometry axes
MD 20150 $MC_GCODE_RESET_VALUES 0 Reset G groups cleanly

Channel 1 writes the request via $NC variables that channel 2 watches. This isolates the calculation latency from the motion channel completely. It is heavier than a single ASUB but provides the cleanest separation of concerns for repeated, complex evaluations.

10. Alarm Diagnosis and Verification

Common faults and the corrective action when commissioning the pattern above:

Alarm Meaning Remedy
20150 "Action not permissible in synchronized action" Used a token that the synchronized-action parser does not accept Replace DO CALC_Y1 with DO M80 and trigger ASUB from PLC
20160 "Syntax error in synchronized action" Same root cause, different alarm variant on older firmware Same as above
4250 "ASUB not enabled" MD 11640 bit 0 = 0 Set bit 0 to 1, NCK reset
14820 "Channel %1 ASUB not possible: option missing" ASUB option not licensed Install license 6FC5800-0AS00-0YB0
14710 "Channel %1 ASUB start error: state not active" ASUB triggered before RESET completes Add IF not "NCK_ResetActive" guard in PLC
10061 "Channel %1 M function not in this channel" M not declared in the channel-specific MD list Extend $MC_M_NO_FCT_CYCLE in the relevant channel

Verification procedure after writing the part program and PLC code:

  1. Power on the controller, perform NCK reset, and confirm the Channel Status page shows ASUB=READY.
  2. Select the part program in Operate > Machining and start it in single-block mode.
  3. Raise input 32 by hand, watch the Diagnostics > Alarms page — no alarm should appear.
  4. Watch $AC_ASUP in the Service > Display System Data screen. The variable should read the name of the running ASUB while the calculation is active.
  5. Confirm that the Y1 actual position continues to advance in the Axis display during the ASUB. If it stalls, the ASUB has issued a stop (likely M0, G04, or an axis-coupled command); remove the offending statement from CALC_Y1.SPF.

11. Field-Proven Caveats

  • ASUBs share interpreter state with the calling part program. If CALC_Y1.SPF leaves a modal G code active (for example G91), the calling part program will see it after RET unless the SAVE attribute is used and the modal group mask is handled.
  • MD 10717 bit 1 forces a stop before the substituted subprogram. Leave it at 0 to keep the axis in motion.
  • Multiple ASUB triggers from the same synchronized action queue up; the NCK executes them in priority order (PRIO in FB10). Do not rely on strict FIFO.
  • On a NCU 710 the maximum simultaneous ASUB depth is 2; on NCU 720/730/732 it is 8. Exceed it and alarm 14760 "Channel %1 ASUB queue overflow" is raised.
  • The synchronized-action evaluation period is set in MD 10050 $MN_SYSCLOCK_CYCLE_TIME and MD 10060 $MN_POSCTRL_SYSCLOCK_CYCLE_TIME. Polling $A_IN[32] at IPO2 means up to 4 ms reaction latency, which is fine for feed-override adjustments but not for safety stops. For safety, use SETINT instead of WHEN ... DO.

12. Cross-Reference to Other Paths

Approach Latency License Axis motion preserved Best for
PLC-side calculation 1-2 PLC cycles (~10 ms) None extra Yes Simple math, override tuning
ASUB via FB9/FB10 2-4 IPO cycles ASUB option Yes (if MD 10717 bit 1 = 0) Multi-line logic with GUDs
Second channel Channel handshake latency Multi-channel option Yes Long, isolated calculations
SETINT-driven ASUB One IPO cycle ASUB option Yes Hard real-time interrupt

For the original case (single condition, simple calculation) the PLC-side alternative is usually the right answer; the ASUB is justified only when the calculation is too complex to live in the PLC or when it needs GUDs/LUDs from the NCK context.

13. Summary

A WHEN ... DO synchronized action on Sinumerik 840D sl can only call M, S, T, H, D, F functions or write variables; it cannot call a subprogram by name. The accepted path is to use DO M80, let the M80 be output to the PLC, and have the PLC start an ASUB via FB10. The ASUB requires license 6FC5800-0AS00-0YB0, MD 11640 bit 0 = 1, and the cycle file CALC_Y1.SPF placed in /_N_CMA_DIR or /_N_CST_DIR. With MD 10717 bit 1 = 0 the axis motion continues uninterrupted. For many real-world cases the engineer can drop the ASUB entirely and run the math in the PLC, accepting a small additional latency in exchange for zero new license cost and better diagnostic visibility.

What is the difference between ASUB and ASUP on Sinumerik 840D sl?

ASUB (English) and ASUP (German, Asynchrones Unterprogramm) are the same feature. The German DocOnCD uses ASUP while English manuals use ASUB. The licensed option code in Operate is the English string ASUB, catalog 6FC5800-0AS00-0YB0.

Why does WHEN ... DO CALC_Y1 fail with an alarm?

The synchronized-action parser on 840D sl only accepts axis names, M/S/T/H/D/F functions, and GUD/LUD/system-variable assignments. A subprogram name is not in the grammar, so alarm 20150 or 20160 is raised. Replace CALC_Y1 with an M function (e.g. M80) and start the subprogram as an ASUB from the PLC.

Do MD 10715 and MD 10716 let me bind an M to a subprogram inside a synchronized action?

No. MD 10715/10716 perform the M-to-subprogram substitution at the interpreter before the synchronized-action evaluator sees the block. The substitution path was designed for plain part-program blocks, not for M tokens issued from a WHEN ... DO action. Use the ASUB/FB10 path described in this article instead.

How do I keep the axis moving while the ASUB runs?

Leave MD 10717 $MN_M_NO_FCT_CYCLE_MODE bit 1 = 0 so the substituted M does not issue an internal stop. Do not place M0, G04, or any motion command in the ASUB. Verify on the Axis display that the actual position continues to advance during the ASUB.

Do I always need the ASUB option, or can I do the math in the PLC?

For most cases a PLC-side calculation is sufficient: read $AA_IM and $AA_VACTM from the NCK via the standard NC variable interface, perform the math in STEP 7 / TIA Portal, and write the result back (e.g. $AC_OVR). No ASUB option, no interpreter state save, and faster diagnostics. Reserve ASUB for logic that needs NCK context such as GUDs, LUDs, or modal G-code handling.

Back to blog