Sinumerik 840D $A_IN/$A_OUT: Reading Fast I/O in NC Programs

David Krause14 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

1. Problem: W-Axis Clamp Interlock on a Tricept Robot

A Tricept parallel kinematic machine (PKM) integrates a Siemens SINUMERIK 840D sl controller for the three Cartesian axes plus one or more rotary axes. In the application described in the engineering request, a rotating work table is mounted on the W-axis. The clamping status of the table must be verified inside the NC part program before the kinematics are permitted to move — an unclamped W-axis commanded to rotate will drop the workpiece, stall the axis, or trigger a collision.

The PLC already detects the clamped state via a digital input wired to a clamp-pressure switch or proximity sensor. The task is to make that PLC input readable from inside the part program so the high-level NC code can branch on it:

; Pseudo-code intent
LOOP:
   IF W-axis is unclamped THEN GOTOB LOOP
ENDIF
; continue once clamped
G1 ...

The challenge is that standard PLC inputs cannot be addressed from the NC part program. They live in DB1 / DB2 / process images of the PLC, which are not visible to the NCK interpreter. The SINUMERIK 840D exposes a separate image of fast inputs and fast outputs through the system variables $A_IN[..] and $A_OUT[..], and a deliberate routing must be set up so the clamp input is mirrored into one of those fast inputs.

2. Why Direct I/O is Not Available in NC Part Programs

The NCK (numerical control kernel) and the PLC run as two independent tasks with separate process images. The part program is interpreted by the NCK; from its runtime environment, only a small, well-defined set of signals can be polled:

  • Fast NC inputs ($A_IN[1]…$A_IN[n]) — physically either onboard hardware inputs on connector X121 of the NCU, or PLC inputs mirrored into DB10 by the basic PLC program.
  • Fast NC outputs ($A_OUT[1]…$A_OUT[n]) — mirrored back to the PLC through DB10.
  • GUD / machine data / setting data that the PLC writes via FB2/FB5 read/write FBs.

Any attempt to read a PLC I address directly from a part program returns an interpreter error. The acceptable pattern is therefore to copy the PLC bit into a fast NCK input, then poll $A_IN[…] in the NC code.

3. Prerequisites

Item Requirement
Controller SINUMERIK 840D or 840D sl with NCU 710/720/730/735
Firmware NCK 4.4 SPx or later (recommended NCU 4.5+ for stable $A_IN semantics); older NCU 573.2/573.4 also supports it
PLC tool SIMATIC Manager STEP 7 V5.5 / TIA Portal V15+ with SINUMERIK 840D sl Toolbox
Basic program GUD version matched to NCK; FB1 with NCKomm = TRUE (covered below)
Spare fast input At least one free index in $A_IN[..]
Hardware Wiring access to clamp sensor (PNP, 24 V DC) and free pin on X121 — or free PLC byte for the DB10 mirror method

4. Method 1 — Map a PLC Input to a Fast Input via DB10

This is the most common approach on Tricept installations because the clamp sensor is already wired to the S7 I/O. The basic PLC program copies the PLC input into a bit of DB10, and the NCK sees that bit as a fast input.

4.1 DB10 layout in the SINUMERIK basic program

DB10 is the “PLC ↔ NCK data exchange” block. Its first few bytes are reserved for fast inputs/outputs and for NCK control/status words. The exact byte layout is defined in the DOConCD documentation; the relevant ranges for $A_IN/$A_OUT on a standard 840D sl are:

DB10 offset Direction NCK-side system variable
DB10.DBX0.0 … DBX0.7 PLC → NCK $A_IN[1]…$A_IN[8] (byte 0)
DB10.DBX1.0 … DBX1.7 PLC → NCK $A_IN[9]…$A_IN[16] (byte 1)
DB10.DBX4.0 … DBX4.7 PLC → NCK $A_IN[17]…$A_IN[24] (byte 4, optional)
DB10.DBX8.0 … DBX8.7 NCK → PLC $A_OUT[1]…$A_OUT[8] (byte 8)
DB10.DBX9.0 … DBX9.7 NCK → PLC $A_OUT[9]…$A_OUT[16] (byte 9)
DB10.DBX12.0 … DBX12.7 NCK → PLC $A_OUT[17]…$A_OUT[24] (byte 12, optional)
Note: The exact byte offset and the maximum index supported by $A_IN/$A_OUT depend on the machine data 10362 $MN_FASTIO_DIG_NUM_INPUTS / 10364 $MN_FASTIO_DIG_NUM_OUTPUTS / 10366 $MN_FASTIO_ANA_NUM_INPUTS / 10368 $MN_FASTIO_ANA_NUM_OUTPUTS. Always verify against the live machine data before binding program logic. See Siemens Industry Online Support → SINUMERIK 840D sl Lists (DOConCD) for your specific NCK version.

4.2 Mapping the clamp input

Assume the clamp-pressure switch is wired to PLC input I 32.5 (PNP, 24 V). In the basic PLC program, add the following STL segment (or its FBD/TIA equivalent) in OB1, just before the call of FB1 / FB2:

      A   I 32.5          ; clamp sensor physical input
      =   DB10.DBX0.4     ; maps into $A_IN[5]

After this assignment the NCK reads the bit transparently via $A_IN[5]. No additional NCK-side configuration is required for the mapping itself, but the basic-program flag NCKomm must be TRUE (see Section 8).

4.3 TIA Portal representation

In TIA Portal with the SINUMERIK 840D sl option package, DB10 is generated and managed as an “axis-of-communication” data block. A typical implementation in SCL inside a cyclic OB:

// Clamp status mirror: PLC input I32.5  →  $A_IN[5]
"DB10".Clamp_OK_Bit := "I32_ClampPressure_OK";
// Optional debounce
IF "Tag_Clamp_Debounce".Q THEN
    "DB10".Clamp_OK_Bit := "I32_ClampPressure_OK";
END_IF;

Where "DB10".Clamp_OK_Bit is a symbolic alias for DB10.DBX0.4. This same bit is exposed to NCK as $A_IN[5].

5. Method 2 — Wire the Sensor Directly to X121 Onboard Inputs

When no PLC byte is available, or when the signal must be polled by the NCK with the minimum possible latency (e.g., safety-critical applications), the clamp sensor can be wired directly to the fast inputs physically present on the NCU connector X121. These inputs are read by the NCK firmware without going through the PLC.

5.1 X121 pinout (NCU 710 / 720 / 730 / 735)

Pin Signal Function Fast I/O index
1 DI 0 Digital input 0 $A_IN[1]
2 DI 1 Digital input 1 $A_IN[2]
3 DI 2 Digital input 2 $A_IN[3]
4 DI 3 Digital input 3 $A_IN[4]
5 DI 4 Digital input 4 $A_IN[5]
6 DI 5 Digital input 5 $A_IN[6]
7 DI 6 Digital input 6 $A_IN[7]
8 DI 7 Digital input 7 $A_IN[8]
9 DO 0 Digital output 0 $A_OUT[1]
10 DO 1 Digital output 1 $A_OUT[2]
11 DO 2 Digital output 2 $A_OUT[3]
12 DO 3 Digital output 3 $A_OUT[4]
13 DO 4 Digital output 4 $A_OUT[5]
14 DO 5 Digital output 5 $A_OUT[6]
15 DO 6 Digital output 6 $A_OUT[7]
16 DO 7 Digital output 7 $A_OUT[8]
17 +24 V Sensor supply —
18 +24 V Sensor supply —
19 0 V Reference ground —
20 0 V Reference ground —
Pin numbering and signal-to-index mapping are consistent across the NCU 710/720/730/735 family. Always cross-check against the specific hardware manual shipped with your NCU because some sub-variants (e.g., NCU 730.3 PN) renumber the inputs after firmware 4.7. Refer to Siemens Industry Online Support → SINUMERIK 840D sl Equipment Manual NCU.

5.2 Wiring example

  1. Connect clamp-sensor signal (PNP, 24 V) to X121 pin 5 (DI 4).
  2. Connect sensor supply to X121 pin 17 or 18 (+24 V).
  3. Connect sensor ground to X121 pin 19 or 20 (0 V).
  4. From the part program, read $A_IN[5]. No PLC change required.

The onboard inputs are 24 V tolerant, optically isolated, and filtered by the NCK at the IPO clock (default 4 ms). For mechanical contact inputs, add a debounce in the NCK using machine data 10362 $MN_FASTIO_DIG_SHORT_CIRCUIT or, more commonly, debounce in software.

6. Syntax Reference: $A_IN and $A_OUT

Variable Direction Type Index range Meaning
$A_IN[n] PLC/HW → NCK BOOL 1 … $MN_FASTIO_DIG_NUM_INPUTS Logical state of fast input n
$A_OUT[n] NCK → PLC/HW BOOL 1 … $MN_FASTIO_DIG_NUM_OUTPUTS Logical state set by NCK on fast output n
$AC_MARKER[n] Bidirectional (NC-side) INT 1 … 32 Cyclic NCK marker, useful for NCK ↔ PLC handshakes

Reading a single fast input in the part program:

IF $A_IN[5] == 1 THEN
   ; clamp OK, proceed
ELSE
   GOTOB WAIT_CLAMP
ENDIF

Writing a fast output (e.g., to enable a clamp solenoid before un-clamping):

; pulse unclamp command
$A_OUT[3] = 1
G4 F0.5        ; dwell 0.5 s
$A_OUT[3] = 0
Important: Do not treat $A_OUT as a safety-rated signal. For functional-safety stops driven by hardware (e.g., STO via PROFIsafe), always use the safety PLC path; $A_OUT is suitable for non-safety sequencing such as clamp/unclamp commands, light curtains with PLC approval, or machine status lamps.

7. Part Program Example — W-Axis Clamp Wait Loop

Putting the two systems together, the Tricept part program becomes:

;------------------------------------------------------------
; ROTARY_TABLE_CLAMP.SPF
; Wait until W-axis clamp is reported clamped, then proceed.
; $A_IN[5] is mapped from PLC input I32.5 via DB10.DBX0.4
; or wired directly to X121 pin 5 (DI 4).
;------------------------------------------------------------

DEF INT _WAIT_COUNT = 0

WAIT_CLAMP:
   _WAIT_COUNT = _WAIT_COUNT + 1

   ; safety: 10 s timeout at IPO cycle ≈ 4 ms
   IF _WAIT_COUNT > 2500 THEN
      MSG("W-axis clamp not reached within 10 s")
      M0                       ; programmed stop for operator
      _WAIT_COUNT = 0
   ENDIF

   IF $A_IN[5] == 0 GOTOB WAIT_CLAMP

; clamp confirmed: energise spindle-clean air, etc.
$A_OUT[2] = 1   ; signal back to PLC: "clamp acknowledged"

; rotation of W-axis is now safe
G1 W90 F600

; ... continuing program
M30

7.1 State machine (SVG)

Start of program block WAIT_CLAMP $A_IN[5]==0 ? Timeout 10 s M0 + MSG $A_OUT[2]=1 $A_IN[5]==1 10 s $A_IN[5]==0 $A_IN[5]==1 continue G1 W90

8. Required NCKcomm Flag in FB1 (Basic Program)

The basic PLC program (FB1) owns the cyclic DB10 update. The internal flag NCKomm in FB1 must be TRUE; otherwise the PLC never writes the fast-input bytes and the NCK reads stale zeros. The flag is set by:

; In OB100 (restart) or FB1 static area
NCKomm := TRUE;     // SCL/TIA symbolic form

or, in classic STL on the basic program supplied with SINUMERIK:

      SET
      =   M_BC_Op.Comm.CommActive   ; legacy name
      ; In modern versions the flag name is "NCKcomm" in DB7 of the basic program
Without NCKomm = TRUE, $A_IN[..] always returns 0 regardless of the wiring. This is the single most common cause of “fast inputs not seen from NC” on first commissioning.

On a TIA Portal build, the equivalent flag lives in the data block generated by the SINUMERIK toolbox, typically named BasicProgramData, and is exposed as "BasicProgramData".NCKcomm. Set it during OB100 startup.

9. Verification Procedure

  1. Compile and download the updated FB1 / DB10 project to the PLC. PLC must go RUN with no diagnostic errors.
  2. Force the sensor (manually clamp the W-axis or simulate with a 24 V signal).
  3. Watch online: in STEP 7 / TIA, place DB10.DBX0.4 in a watch table and confirm the bit toggles when the sensor changes state.
  4. Cross-check from HMI: on the SINUMERIK HMI, navigate to Commissioning → Diagnostics → I/O → Digital I/O and inspect $A_IN[5]. It should reflect the same state.
  5. Run a probe program: WHILE TRUE ; MSG("$A_IN[5]=" << $A_IN[5]) ; G4 F1 ; ENDWHILE and observe the message line updates every second.
  6. Run the full clamp-wait cycle: with the axis physically unclamped, the program must remain in WAIT_CLAMP. Apply clamp and verify that G1 W90 executes within one IPO cycle of the bit rising.
  7. Negative test: disconnect the sensor wire and confirm the program latches on M0 after 10 s — i.e., the interlock is not bypassed by an open-circuit.

10. Troubleshooting Matrix

Symptom Probable cause Diagnostic Fix
$A_IN[5] always 0 even with sensor forced NCKomm flag in FB1 not TRUE Cross-reference FB1 static; check DB7.Comm Set NCKomm = TRUE in OB100 and re-download
$A_IN[5] always 0 — DB10 bit toggles correctly Wrong DB10 offset / wrong index Verify $MN_FASTIO_DIG_NUM_INPUTS Adjust offset or reduce index until consistent
NC alarm 4275 "Fast input not defined" Index higher than configured count Display $MN_FASTIO_DIG_NUM_INPUTS Increase via machine data or use a lower index
Bit toggles only after several seconds PLC task set to OB1 background, not OB35 / OB35 cyclic Watch PLC OB scan time Move DB10 mirror into OB35 fast task, or accept latency and widen timeouts
$A_IN works in NC but not in PLC program counter PLC trying to read NCK image instead of DB10 source Online watch the actual DB10 byte Read DB10 from PLC, not the NCK-side mirrored variable
Clamp acknowledged in code but axis still alarms PLC stop-1 / stop-2 logic reading a different bit Trace interface-signals in HMI Update PLC stop-conditions to the same DB10 bit used in NC
Direct X121 wiring — input never reads Sensor NPN instead of PNP, or 0 V reference floating Measure X121 pin to 0 V with meter Re-wire as PNP sourcing and confirm common 0 V
Part program enters infinite loop, no alarm Missing ENDIF or GOTOB outside block Cross-check control flow Restructure using a single labelled branch (see Section 7)

11. Extended Techniques and Edge Cases

11.1 Using $AC_MARKER for richer handshakes

When the application needs more than a single bit — for example, an integer status code such as "clamp state = 0 / 1 / 2 (open / clamped / fault)" — $A_IN[..] is no longer sufficient. Use $AC_MARKER[1..32] instead. These are cyclic NCK markers visible to the PLC through DB10 as words DBW58, DBW60, …. The PLC writes a code; the NC reads the integer:

; NC side
IF $AC_MARKER[1] == 2 THEN   ; PLC reports "clamp fault"
   MSG("W-axis clamp fault code 2 reported by PLC")
   M0
ENDIF

11.2 Reading a non-fast input via $NCK_READ_PIN (advanced)

Older NCK versions (≤ 4.3) and certain configurations expose the legacy system function $NCK_READ_PIN (SFB / SFC equivalent in the NCK context). This is rarely required on a modern 840D sl, but if you are maintaining a Tricept with NCU 573.2, it is documented in the SINUMERIK 840D sl Function Manual "Basic Functions" under "Fast I/O".

11.3 PROFIsafe interlocks must remain separate

The clamp interlock described here is a sequence interlock — it prevents the part program from running until clamping is confirmed. It is not a substitute for the safety chain (PROFIsafe STO, SBC, SLS, etc.) that physically removes torque from the W-axis drive. Always wire clamp-pressure safe-evaluation (e.g., via SIMATIC ET 200S F-CPU or SINUMERIK Safety Integrated) through the safety path, and use $A_IN[..] only as a non-safety confirmation signal.

11.4 Latency budget

Default IPO cycle on a Tricept is 4 ms. The PLC basic-program update of DB10 runs on the configured OB35 / OB1 background. End-to-end latency from sensor-edge to $A_IN value is therefore typically:

Path Latency (typical) Latency (worst case)
PLC digital input → DB10 byte → NCK ($A_IN) 5–10 ms ~25 ms if PLC OB is OB1
X121 onboard → NCK ($A_IN) < 1 IPO cycle 4 ms

For a 10-second wait window like the one in Section 7, either path is more than adequate. For time-critical decisions (< 50 ms), prefer X121 onboard.

11.5 Machine data recap

Machine data Meaning Typical default (840D sl)
10362 $MN_FASTIO_DIG_NUM_INPUTS Number of fast digital inputs 8 (extendable to 16 / 24)
10364 $MN_FASTIO_DIG_NUM_OUTPUTS Number of fast digital outputs 8
10366 $MN_FASTIO_ANA_NUM_INPUTS Number of fast analog inputs 0
10368 $MN_FASTIO_ANA_NUM_OUTPUTS Number of fast analog outputs 0
10380 $MN_FASTIO_DIG_SHORT_CIRCUIT Debounce / short-circuit handling for digital fast I/O 0
10050 $MN_SYSCLOCK_CYCLE_TIME IPO/system clock cycle time 0.004 s (4 ms)

12. Field Commissioning Notes

  1. Document the mapping. Add a comment on every DB10 byte assignment: DB10.DBX0.4 → $A_IN[5] ← "W-axis clamp pressure OK" ← I32.5. Future maintenance will thank you.
  2. Backup the project before download. A bad FB1 can lock the PLC into stop; you will need the backup to recover without a service visit.
  3. Test with a real unclamp. Many clamp-pressure switches report "OK" on no-pressure at the contact; verify the failure mode is reported as 0 and not 1.
  4. Add the alarm to your alarm list (HMI menu Commissioning → Alarm/Messages → User alarms) so the operator sees a meaningful text instead of a plain M0 stop.
  5. Cross-check the safety PLC. Confirm that PROFIsafe / SINUMERIK Safety Integrated is unaffected by the new mapping. Safety logic must read its own input module, not DB10.
  6. Use NCK start-up archive after commissioning so the FB1/DB10 changes survive a CF card replacement.

Why can't I read a regular PLC input like I32.5 directly from the NC part program?

The NCK and PLC run as independent tasks with separate process images. The NCK interpreter only has visibility into its own system variables ($A_IN, $A_OUT, $AC_MARKER, GUD, machine data). The PLC must mirror the desired bit into DB10 first; the NCK then exposes it through $A_IN[n].

What is the difference between wiring to X121 and routing through DB10?

X121 onboard inputs are read by the NCK hardware path with sub-IPO-cycle latency and do not require any PLC code. The DB10 mirror method uses the PLC basic program (FB1) to copy any PLC input into a fast-input byte; it is more flexible but adds 5–25 ms latency and requires NCKomm = TRUE in FB1.

$A_IN[5] always reads 0 even though the input is wired correctly. What should I check first?

Verify three things in order: (1) the basic-program flag NCKomm in FB1 / DB7 is TRUE; (2) the PLC assignment actually writes to the correct DB10 bit (use an online watch table); (3) the index 5 is within $MN_FASTIO_DIG_NUM_INPUTS — if that machine data is 4, you must use indices 1–4 only.

Can $A_OUT be used for safety functions?

No. $A_OUT is a non-safety NCK output and is suitable only for sequencing (clamp/unclamp solenoids, status lamps, handshakes). Functional safety must use PROFIsafe / Safety Integrated via dedicated safe I/O modules.

Which SINUMERIK manual documents $A_IN / $A_OUT and DB10?

The complete reference is in the SINUMERIK 840D sl Programming Manual (basics and advanced) and the SINUMERIK 840D sl Function Manual "Basic Functions" — both are distributed via the DOConCD / Siemens Industry Online Support portal under article search "fast I/O" and "DB10".

Back to blog