S7-317 PROFINET IO Cycle Time Monitoring Implementation Guide

David Krause18 min read
Industrial NetworkingSiemensTechnical 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

The S7-317 family (most commonly the CPU 317-2 PN/DP, order number 6ES7317-2EK14-0AB0 or 6ES7317-2FK14-0AB0) operates as a PROFINET IO Controller and exchanges cyclic process data with configured IO Devices at the configured update time. The PLC supervises each device through a watchdog that is typically three times the update time, but it does not expose a per-cycle timestamp or jitter figure for the incoming frames. Engineers who need to log the actual inter-arrival time of the slave's input frames — to detect degradation before a watchdog fault trips — must implement a custom measurement in the application program. The S7-317 IO base system provides station-failure and channel-diagnostic events only; intermediate degradation within the watchdog window is invisible to user code.

This reference covers three complementary techniques for measuring PROFINET IO cycle time on the S7-317:

  1. Toggle-bit echo pattern with IEC timers — the technique recommended in the original engineering discussion.
  2. Acyclic record read (SFB52 RDREC) of the PROFINET port-statistics record (index 0xE040 in the GSDML definition).
  3. PROFINET alarm evaluation via SFB54 RALRM in the diagnostic OB.

PROFINET IO Cycle Time Fundamentals

PROFINET IO exchanges cyclic data between Controller and Device on a time-deterministic, isochronous basis. The parameters that govern the exchange are configured in the device description (GSD file) and in the TIA Portal / STEP 7 hardware catalog:

Parameter Meaning Typical value
Send clock Base clock of the PROFINET port 1 ms
Update time Interval at which the IO Device refreshes its process data 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ms
Reduction ratio Update time = send clock × ratio 1, 2, 4, 8, 16, 32, 64, 128, 256, 512
Watchdog Maximum tolerated frame loss before station failure 3 × update time (default)
Reduction ratio (in) Input direction ratio Matches output direction

The configured update time is the nominal interval. Real inter-arrival times deviate by tens of microseconds depending on switch latency, line load, and IRT scheduling. The S7-317 internal IO cycle is triggered in OB61 (isochronous mode) or OB1 (free-running mode). Refer to the S7-300 CPU 31x PN/DP manual on the Siemens Industry Online Support portal for the OB assignment of your firmware version.

Why Native Diagnostics Do Not Expose Jitter

STEP 7 (TIA Portal) and the S7-300 system software expose PROFINET diagnostics through several mechanisms:

  • SSL (System State List) read by SFC51 RDSYSST, sublist W#16#0392 (PNIO state) and W#16#0B92 (PNIO diagnosis).
  • Diagnostic buffer entries written on station failure, station return, and channel fault.
  • IO Controller / IO Device diagnostic blocks in the device catalog (status and error bits).

These report fault conditions — station failure, channel fault, port link down — but not the per-cycle arrival time of frames that are still arriving within the watchdog. The IO Controller raises an event only when the watchdog expires; intermediate degradation is invisible to user code.

The S7-317 does not populate a per-cycle timestamp in the cyclic process image. The IO base system tags (e.g., %IW, %QW ranges) carry only the process values, not their arrival time. Any cycle-time measurement must be implemented at application level using a closed-loop technique (echo bit) or acyclic read of device statistics.

Watchdog vs Update Time Relationship

The default watchdog multiplier in PROFINET IO is 3, so for a 16 ms update time the device is allowed to miss up to two consecutive frames (32 ms gap) before the controller reports a station failure and OB86 fires. Engineers who want to be notified when a single frame is dropped, or when the gap exceeds 1.5× the update time, must measure it themselves.

Update time Default watchdog 1-frame gap 2-frame gap 3-frame gap (fault)
1 ms 3 ms 2 ms 3 ms 4 ms
2 ms 6 ms 4 ms 6 ms 8 ms
4 ms 12 ms 8 ms 12 ms 16 ms
8 ms 24 ms 16 ms 24 ms 32 ms
16 ms 48 ms 32 ms 48 ms 64 ms
32 ms 96 ms 64 ms 96 ms 128 ms
64 ms 192 ms 128 ms 192 ms 256 ms

To detect a 1-frame gap at 16 ms update time, the application program must timestamp incoming IO with sub-millisecond resolution. The S7-300 system clock (1 ms tick) is sufficient; the millisecond counter is read with TIME_TCK() in SCL or with SFC64 TIME_TCK in STL.

Implementation Method 1 — Toggle-Bit Echo Pattern

The technique referenced in the original engineering thread uses a single bit sent from the PLC to the device, echoed back unchanged, and sampled by the PLC. A correctly operating device produces an edge on the echo at every update interval; missed or duplicated frames appear as either a missing edge or two edges within one PLC cycle. The toggle pattern is the most direct method to detect dropped frames that are still within the watchdog window.

Wiring the toggle bit

  1. Allocate one output bit on the S7-317 that maps to the first free output byte of the IO Device (e.g., "ToggleOut" AT %Q0.0).
  2. Allocate the corresponding input bit on the same byte (e.g., "ToggleIn" AT %I0.0) so that the device wires input n directly to output n. Many PROFINET IO Devices have freely assignable digital I/O — pick a channel that supports a single-bit mapping. For details on adding a device and assigning channels, see Adding a PROFINET IO Device in the TIA Portal manual collection.
  3. In OB1, toggle "ToggleOut" every controller cycle. Use a rising-edge detector on "ToggleIn" to capture the timestamp.

SCL implementation (S7-300, SCL from STEP 7 V5.x or TIA Portal)

// FB_CycleMonitor — SCL for S7-317 (CPU 317-2 PN/DP)
FUNCTION_BLOCK FB_CycleMonitor
VAR
    ToggleOut   : BOOL;   // sent to IO device
    ToggleIn    : BOOL;   // echoed from IO device
    EdgePrev    : BOOL;
    tEdgeLast   : TIME;   // last edge timestamp (ms)
    tEdgeNow    : TIME;   // current edge timestamp (ms)
    DeltaT      : TIME;   // inter-arrival time (ms)
    tMin        : TIME;   // minimum observed (ms)
    tMax        : TIME;   // maximum observed (ms)
    tSum        : DINT;   // accumulator (ms)
    nSamples    : DINT;   // sample count
    tAvg        : TIME;   // rolling average (ms)
    WarnHigh    : BOOL;   // true if DeltaT > threshold
END_VAR
BEGIN
    // 1. Toggle output every OB1 cycle
    ToggleOut := NOT ToggleOut;

    // 2. Edge detection on incoming echo
    tEdgeNow := TIME_TCK();
    IF ToggleIn AND NOT EdgePrev THEN
        DeltaT    := tEdgeNow - tEdgeLast;
        tEdgeLast := tEdgeNow;

        // 3. Update statistics
        IF DeltaT < tMin OR nSamples = 0 THEN tMin := DeltaT; END_IF;
        IF DeltaT > tMax                   THEN tMax := DeltaT; END_IF;
        tSum     := tSum + DINT_TO_TIME(DeltaT);
        nSamples := nSamples + 1;
        tAvg     := DINT_TO_TIME(tSum / nSamples);
    END_IF;
    EdgePrev := ToggleIn;

    // 4. Warn if gap > 1.5 x update time (e.g. 24 ms for 16 ms update)
    WarnHigh := (DeltaT > T#24ms);
END_FUNCTION_BLOCK

Ladder equivalent (OB1, network 1)

Network 1 — Toggle output
    A   "OB1_FirstScan"          // first scan bit
    R   "ToggleOut"              // initialise
    AN  "ToggleOut"
    S   "ToggleOut"
    A   "ToggleOut"
    R   "ToggleOut"

Network 2 — Edge detect and timestamp
    A   "ToggleIn"
    FP  "EdgeMemory"             // rising edge memory bit
    JCN END
    CALL SFC64                    // TIME_TCK
         RET_VAL := "TICK_MS"     // ms counter
    L   "TICK_MS"
    T   "tEdgeNow"
    L   "tEdgeNow"
    L   "tEdgeLast"
    -D
    T   "DeltaT"
    L   "tEdgeNow"
    T   "tEdgeLast"
END:  NOP 0

Network 3 — Update min/max/avg
    L   "DeltaT"
    L   "tMax"
    >I                            // signed integer compare
    JC  UMAX
    L   "tMax"
    T   "tMaxNew"
    JU  CHKMIN
UMAX:L   "DeltaT"
    T   "tMaxNew"
CHKMIN:
    L   "DeltaT"
    L   "tMin"
    <I
    JC  UMIN
    L   "tMin"
    T   "tMinNew"
    JU  AVG
UMIN:L   "DeltaT"
    T   "tMinNew"

Tuning guidelines

  • Threshold. The "warn" threshold should be set between the update time and the watchdog. With 16 ms update and 48 ms watchdog, set the threshold to 24–32 ms (1.5× to 2× update time) so that single-frame drops are flagged without flooding the alarm log.
  • Rolling buffer. Wrap the statistics in a circular buffer of 1024 samples to avoid 32-bit DINT overflow on the accumulator and to provide a rolling average over the most recent N samples rather than the entire run time.
  • Isochronous mode. For isochronous operation, move FB_CycleMonitor into OB61 and use OB61_DATE_TIME for the timestamp to obtain 1 µs resolution of the send clock.
  • OB1 cycle budget. The SCL code adds approximately 50 µs of OB1 execution time per monitor instance. For projects with many devices, prefer the acyclic-record method below to avoid impacting the OB1 cycle time.

Implementation Method 2 — Acyclic Record Read (SFB52 RDREC)

The PROFINET specification (IEC 61784-2) defines a per-port statistic record that the controller can read acyclically. The S7-300 family exposes the read through SFB52 RDREC; the dual-port S7-317 returns counters for frames sent, frames received, CRC errors, and discards per port. The acyclic read/write mechanism on Siemens PLCs is described in Acyclic PROFINET communication with Siemens PLC — note that PROFINET IO supports data lengths via the acyclic read/write record services up to 64 KB per request.

Call sequence

// Call once per second from OB35 (cyclic interrupt, 1 s)
CALL SFB52, DB52
    REQ    := TRUE                  // start read on first scan
    ID     := W#16#0100             // hardware ID of the IO Device (from HW Config)
    INDEX  := 225                   // 0x00E1 decimal — see note below
    MLEN   := 32                    // 32 bytes is sufficient for one port block
    VALID  := #valid                // 1 = record received without error
    BUSY   := #busy                 // 1 = read in progress
    ERROR  := #err                  // 1 = error occurred
    STATUS := #status               // error / status word
    RECORD := P#DB53.DBX0.0 BYTE 32 // destination buffer
The actual record index exposed by a specific IO Device depends on the device's GSDML file. The PROFINET specification defines a family of PD (Process Data) records — 0xE040 (PD Port Data Real) and 0xE041 (PD Port Data Check) are the most common — but the device vendor may map them to different logical indexes. For a default Siemens IO Device the equivalent index is 0x00E1 (225 decimal) when read from the IO controller; for third-party devices consult the GSDML documentation. For background on the device-side data layout, refer to the Delta Motion PROFINET IO integration note which explains the same update-time model from the device's perspective.

Interpretation of the port data real record

The PD Port Data Real record contains, per port and per direction, the following fields (the exact layout is defined in the GSDML or PROFINET specification):

Offset Field Meaning
0 FrameDiscardCount Frames discarded by the device port (e.g., wrong VLAN, queue full)
4 FrameErrorCount Frames with CRC or alignment error
8 Reserved
12 FrameSentCount Frames transmitted (32-bit counter)
16 FrameReceivedCount Frames received (32-bit counter)

By polling the counter block every second, the application program computes the per-second throughput. A sustained drop in FrameReceivedCount relative to the configured update rate indicates that the device is not refreshing at the expected cadence. For a 1 ms update time the expected rate is 1000 frames/s; for 16 ms the rate is 62.5 frames/s. A deviation of more than 5% over 10 s is a strong indicator of frame loss before the watchdog.

Implementation Method 3 — PROFINET Alarm Evaluation (SFB54 RALRM)

PROFINET IO devices raise channel diagnostics, manufacturer diagnostics, and process alarms. The S7-300 receives these asynchronously, and the OB82 (IO Device diagnostic), OB83 (insert/remove), OB86 (rack failure), and OB122 (I/O access error) handlers receive the alarm notification. SFB54 RALRM can be called from the alarm OB to read the full alarm record (ALARM_DATA), which contains the slot, channel, error type, and the associated diagnostic data.

// In OB82 (IO Device diagnostic alarm)
CALL SFB54, DB54
    MODE     := 1                    // 1 = read incoming alarm
    F_ID     := #IO_HW_ID            // hardware identifier of the device
    MLEN     := 200                  // max length of AINFO
    NEW      := #alarm_active        // 1 = a new alarm is present
    STATUS   := #status              // status / error word
    ID       := #slot                // slot number from alarm
    LEN      := #len                 // actual length of AINFO
    TINFO    := P#DB55.DBX0.0 BYTE 200  // task information (OB start info)
    AINFO    := P#DB56.DBX0.0 BYTE 200  // alarm information (record data)

The AINFO buffer starts with a USI (User Structure Identifier) field; when the USI is 0x8000 the remainder is the PROFINET channel-diagnosis structure containing channel number, error type, and direction. When the alarm type is channel diagnosis (USI 0x8000) and the channel error type indicates a transient condition (e.g., 0x0000 "data exchange still OK"), the application program can log a soft warning. Sustained channel diagnosis with the same slot, or a station-failure event, triggers OB86 and the watchdog trip.

Hardware Configuration in TIA Portal / STEP 7

To add the IO Device in TIA Portal:

  1. In Devices & Networks, drag the IO Device from the hardware catalog onto the PROFINET subnet of the S7-317.
  2. Open the device properties → PROFINET interface → Update time and confirm the value. For a 16 ms update time, set reduction ratio = 16 with a 1 ms send clock.
  3. Set Watchdog = 3 (default) or modify per the project specification.
  4. Assign the toggle output byte to the first free slot of the device (e.g., slot 1, subslot 1, output byte 0).
  5. Note the Hardware Identifier of the device (visible under Properties → System constants). This is the F_ID input to SFB52 and SFB54.

For STEP 7 V5.x (SIMATIC Manager), the same configuration is done in HW Config. The S7-300 CPU 31x PN/DP manual on the Siemens Industry Online Support portal gives the exact menu path and the system constants naming convention.

SFC51 SSL Reads for PROFINET State

The S7-300 system status lists (SSL) provide aggregated PROFINET diagnostics without acyclic record reads. The relevant sublists are:

SSL ID Content Length
W#16#0392 PROFINET IO status (one entry per IO Device) Variable
W#16#0B92 PROFINET IO diagnosis (one entry per faulty channel) Variable
W#16#0F92 PROFINET IO expected / actual mismatch Variable
CALL SFC51, DB51
    REQ     := TRUE
    SSL_ID  := W#16#0392
    INDEX   := 0                     // 0 = first call (full list)
    RET_VAL := #retVal
    BUSY    := #busy
    SSL_RECORD := P#DB57.DBX0.0 BYTE 512

SSL W#16#0392 reports the state of each IO Device (0 = OK, 1 = faulty, 2 = disabled, 3 = not configured). The record does not contain per-cycle timestamps; for jitter measurement it must be combined with the toggle-bit or acyclic-record technique.

SFB52 RDREC Status Code Reference

STATUS Meaning Action
16#0000 Read complete, no error Process RECORD buffer
16#7000 First call with REQ = 0 No read in progress; no action
16#7001 / 16#7002 Read in progress (busy) Wait for completion
16#80A0 Negative ack from device — index invalid Check GSDML for allowed indexes
16#80A1 Negative ack from device — access denied or length error Increase MLEN to device's expected length
16#80A2 Firmware error on device Update device firmware
16#80A3 Access to non-existing slot / subslot Verify hardware identifier in HW Config
16#80A7 IO Device busy Retry after delay
16#80AA Feature not supported by device Drop the diagnostic request
16#80C0 / 16#80C1 / 16#80C2 / 16#80C3 / 16#80C4 / 16#80C5 General / negative / resource / no storage / invalid / length read error Inspect device-specific diagnostics

Verification and Commissioning

After loading the program, perform the following checks:

  1. Watch the toggle bit in the VAT online view. With 16 ms update time, "ToggleIn" should toggle every OB1 cycle (typically 1–2 OB1 cycles per PROFINET frame, depending on OB1 cycle time and update time).
  2. Read "tMin", "tMax", and "tAvg" over 5 minutes. The average should equal the update time within 1 ms. The max should be at most one OB1 cycle longer than the average.
  3. Disconnect the PROFINET cable for 1 s, then reconnect. "tMax" should equal the disconnect duration; OB86 should fire on disconnect and OB82 (or OB86 with return) on reconnect.
  4. Compare FrameReceivedCount from the acyclic record with the expected rate (e.g., 62.5 frames/s at 16 ms update, 1000 frames/s at 1 ms). A 5% deviation over 10 s indicates loss of frames.
  5. Trigger a controlled EMC disturbance (e.g., energise a nearby motor contactor) and confirm the diagnostic records show transient CRC errors but no station failure.

Troubleshooting Matrix

Symptom Probable cause Diagnostic step Action
"ToggleIn" stays constant Wrong byte assignment, cable fault, device in standby Check online IO assignment, link LED, device display Re-wire, verify GSDML slot map, replace cable
"tMax" spikes to 30–50 ms at 16 ms update OB1 cycle too long; isochronous mode not used Check OB1 cycle time in VAT; check RT/IRT configuration Move monitor to OB61 or shorten OB1; switch to IRT
OB86 fires repeatedly with no other errors Watchdog exceeded; faulty device; EMC problem Read diagnostic buffer; check error LED; check shielding Reduce update time, replace cable, check grounding
RDREC returns STATUS = 16#80A0 Index not supported by device Check GSDML allowed index list Use 0xE040 / 0xF00C / 0x8000 as documented
RDREC returns STATUS = 16#80A1 Length too small Compare MLEN to expected record size Set MLEN to 200 or the device's specified length
tMin and tMax equal each other Edge detector wired to inverted bit Add explicit edge memory in VAT Use FP (rising) / FN (falling) instructions
nSamples never increments Input bit not refreshed; process image not updated Force "ToggleIn" and watch response Check OB1 process image update configuration (PIP)
Toggle updates irregularly with OB1 ≥ update time OB1 cycle is longer than the update time; toggle missed Measure OB1 with RUNTIME block Move monitor to a faster OB or reduce OB1 workload

Application Notes and Caveats

  • Time resolution. TIME_TCK returns a 1 ms counter on S7-300. Sub-millisecond jitter cannot be resolved without the isochronous OB61 timestamp (1 µs) or a hardware counter.
  • Measurement overhead. The SCL code adds approximately 50 µs of OB1 execution time per monitor instance. With many devices, prefer the acyclic-record method to avoid impacting the OB1 cycle.
  • IRT vs RT. In IRT (isochronous real-time) mode, the cycle time is locked to the send clock; jitter below 1 µs is typical. The toggle-bit method is unnecessary for jitter detection in IRT — use the S7-317 system clock synchronisation block instead.
  • CPU 317-2 PN/DP port count. The integrated PROFINET interface is a 2-port switch. For more than two physical devices, an external PROFINET switch is required.
  • Process image update. The toggle bit input is read from the process image. If the OB1 PIP (Process Image Update) is disabled for the relevant slot, the toggle will appear stale. Confirm PIP is enabled in HW Config for the slot containing the toggle bit.
  • OB86 + OB82 priorities. OB82 is local to the CPU and runs in priority class 26 by default; OB86 is priority class 26 as well. Avoid long-running code in these OBs — they preempt OB1 and can cause toggle-bit measurement to miss edges.
  • Acyclic record traffic. PROFINET acyclic records share the same physical port as cyclic frames. Polling the port-statistics record more than once per 100 ms can crowd out cyclic frames on a heavily loaded subnet. Recommended: poll once per second from a cyclic interrupt OB.

Alternative Controllers and Migration Notes

The techniques above transfer directly to other S7-300 / S7-400 / ET 200S CPUs that expose a PROFINET interface:

CPU PROFINET interface Notes
CPU 315-2 PN/DP (6ES7315-2EH14) 2-port switch Same SFB52/SFB54 support; lower RAM for acyclic buffers
CPU 317-2 PN/DP (6ES7317-2EK14 / 2FK14) 2-port switch This reference target
CPU 319-3 PN/DP (6ES7319-3FL00) 2-port switch + DP master More PROFINET slots; SFC51 sublists identical
ET 200S IM151-8 PN/DP 2-port switch as IO Device Device-side; toggle-bit available only if configured as controller in PROFINET CBA mode
S7-1200 / S7-1500 2-port switch (S7-1200) / 2- or 3-port (S7-1500) Use RDREC / RALRM instructions in TIA Portal; same status codes apply

FAQ

Can the S7-317 natively report the per-cycle inter-arrival time of a PROFINET IO device?

No. The S7-317 IO base system reports only station failure (after the watchdog expires), channel diagnostics, and port link state. The cyclic process image carries process values without arrival timestamps. Use the toggle-bit method, SFB52 RDREC on record 0xE040, or SFB54 RALRM to capture degradation before the watchdog trips.

How do I detect a single missed frame at 16 ms update time?

Set the warning threshold to 24 ms (1.5 × update time) in the cycle-monitor FB. A gap greater than 24 ms means at least one frame was dropped or delayed, while a gap greater than 48 ms (3 × update time) will trip the watchdog and OB86.

Which PROFINET record indexes does SFB52 RDREC support on the S7-317?

The S7-317 passes the request through to the IO Device. The supported indexes are determined by the device's GSDML file. The most common are 0x8000 (I&M0), 0xE040 (PD Port Data Real), and 0xF00C (PD Real). If the device rejects the request, SFB52 returns STATUS = 16#80A0 (index invalid) or 16#80A1 (access denied or length error).

Is isochronous mode required for accurate cycle-time measurement?

Isochronous mode (IRT, OB61) provides 1 µs resolution via OB61_DATE_TIME and locks the cycle to the send clock. For statistical monitoring (min/max/avg) of a 16 ms update time, 1 ms resolution from TIME_TCK() is sufficient and avoids the configuration overhead of IRT mode.

What is the difference between RDREC, RALRM, and the diagnostic buffer?

RDREC (SFB52) reads a specific data record (e.g., statistics) on demand. RALRM (SFB54) reads the latest asynchronous alarm raised by the device. The diagnostic buffer is the system-wide log of completed events (e.g., station failure). Use RDREC for periodic counters, RALRM in the alarm OB for real-time events, and the diagnostic buffer for post-mortem analysis.

Does the S7-317 work as a PROFINET IO Device for a third-party controller?

Yes. The CPU 317-2 PN/DP can be configured as an IO Device (S7-300 as Smart Device) in TIA Portal. In that role it consumes the toggle-bit pattern from the third-party controller and the same SFB52/SFB54 calls apply for its own acyclic read/write. The update time is configured in the higher-level controller's GSDML for the S7-300 Smart Device.
Back to blog