1. Problem Definition and Throughput Boundary
A typical 100 Hz acquisition task generates a continuous stream of process values from a small number of fast sensors (analog inputs, encoders, position controllers, weighing cells). For a payload in the range of 3.5 to 4 kB/s at 100 Hz, each individual sample set must fit inside a 10 ms window, and the sum of all write attempts must not exceed the available bandwidth on the link between the PLC and the database host.
The decision tree that follows assumes the architecture has not yet been frozen, so the engineer must answer three orthogonal questions before commissioning begins:
- Which S7-1500 CPU class and which firmware generation can deterministically execute a 10 ms time-of-day or cyclic interrupt?
- Which I/O topology keeps the scan-to-process-image time well below 10 ms (local I/O, PROFINET IRT, direct slot access with the
:Psuffix)? - Where should the value be timestamped and persisted — in the PLC as a row per cycle, in the PLC as a bulk blob, or in a PC application polling the PLC?
The guidance below prefers deterministic engineering trade-offs over "best-effort" recommendations. Wherever the source material is ambiguous (for example, the exact data type and word count per sample), the alternative interpretations are listed and the consequences are analyzed.
2. S7-1500 CPU Selection and Firmware Constraints
For a 100 Hz cycle, the S7-1500 family is the correct platform. S7-1200 CPUs have a configurable cycle time floor that is generally too coarse for hard real-time at 10 ms while simultaneously running communication, and they do not provide the same range of high-speed I/O modules. The S7-1500 also gives access to the LSql library and to time-stamping blocks (DTL, LTime) that go down to nanosecond resolution.
Use the following selection logic:
| CPU Class | Minimum OB3x period | Recommended when |
|---|---|---|
| CPU 1511 / 1513 (TF) | 1 ms | Small point count, < 8 fast channels, no IRT slave. |
| CPU 1515 / 1516 (TF) | 0.5 ms (F-TF), 1 ms (non-F) | Several fast analog groups, OPC UA server active. |
| CPU 1517 / 1518 (TF) | 0.1 ms (TF) | Many HS/HF modules, motion + logging in parallel. |
| CPU 1518-4 PN/DP (MFP) | 0.1 ms (TF) | C/C++ runtime used to bypass LSql string conversion. |
Set the PLC to the highest supported firmware in the engineering project, because LSql, the high-speed counter of the technological objects, and the :P direct I/O access all gained performance or capability with later firmware versions. Refer to the Siemens Industry Online Support pages for the precise firmware/KB matrix for your selected CPU.
3. Cyclic Time Interrupt (OB3x) and the 10 ms Time Slice
Configure a Time-of-Day Interrupt (OB10) or a Cyclic Interrupt (OB30..OB38) with a 10 ms period. The choice depends on whether the acquisition must be phase-locked to a wall clock or to a free-running 10 ms tick:
- OB10 (Time-of-Day): use when the customer requires a fixed start time on the absolute clock (for example, aligned with a shift boundary).
- OB30..OB38 (Cyclic): use when the acquisition must be free-running with a fixed period. OB30 = 1 ms, OB35 = 100 ms (default in TIA Portal). To obtain 10 ms, use OB33 and configure the phase offset in the OB properties dialog.
4. Direct I/O Access with the ":P" Suffix
When an OB reads the inputs, the default behavior is to read from the process image (PAA/PAB/PAE/PAW). That image is refreshed at the start of OB1 (or at the configured update cycle). To bypass the image and read the value of the I/O module at the very moment the OB executes, use the :P suffix on the I/O address:
// Direct read of channel 0 of AI 4xU/I HS in slot 4, channel word IW112
// L IW112 // reads the I/O image word
// L IW112:P // reads the physical input value of the I/O right now
Benefits at 100 Hz:
- Removes the jitter caused by the OB1 process image update offset.
- Reduces the latency between the analog-to-digital conversion and the OB3x read, which in turn reduces timestamp error on the PC side.
- Allows you to use input modules whose channel conversion time is shorter than the OB1 cycle (HS = High Speed, HF = High Feature).
Restrictions:
-
:Paccess is only valid on local I/O slots and on distributed I/O that supports isochronous read. - For PROFINET, the field bus must be set to IRT (Isochronous Real-Time) with the slot configured as isochronous. Otherwise the
:Pread still goes through the bus jitter window.
5. I/O Module Selection: HS vs. HF
Siemens uses two suffixes for analog modules in the ET 200SP / ET 200MP / S7-1500 range:
| Suffix | Meaning | Typical channels | Use when |
|---|---|---|---|
| HS | High Speed | 4 or 8 | Conversion time < 100 µs, oversampling possible, value update aligned to PN cycle. |
| HF | High Feature | 4 or 8 | High accuracy (16/24 bit), diagnostics, value update slower than HS. |
| ST | Standard | 4 or 8 | Thermocouple / RTD, slow channels, not suitable for 100 Hz generic acquisition. |
If a channel is on local I/O, the fastest stable update the OB will see is approximately 1 ms per channel, even on an HS module. This is the floor imposed by the backplane scan. If a single acquisition requires 4 channels, plan for at least 4 ms of analog conversion per OB execution. If that is too slow, migrate the fast channels to a PROFINET IRT island using an ET 200SP HF/HS head module and configure the slot as isochronous.
6. Network Architecture and Timestamp Strategy
The 100 Hz data must traverse the link from the PLC to the database host. There are two practical physical arrangements:
- Shared plant network: the PLC and the SQL PC are both connected to the same managed switch fabric as the rest of the plant. The packet from the PLC must compete with HMI traffic, peer-to-peer I/O, and external IT traffic.
- Point-to-point link: the PLC and the SQL PC are connected by a dedicated cable (or a small dedicated switch with QoS). No other device is on that segment.
The point-to-point arrangement is the engineering default for high-speed logging because it removes the collision window that would otherwise force you to use TCP retransmissions to guarantee delivery. Combined with a direct link, the 100 Hz TCP or UDP packets can be timestamped at the receiver with sub-millisecond accuracy relative to the PLC clock.
If the customer refuses a dedicated cable, use an S7-1500 with a separate gigabit PROFINET interface (X2) for the logging traffic, leaving the X1 interface for plant communication. The decision matrix looks like this:
| Throughput target | Required interface | Recommended topology |
|---|---|---|
| < 1 kB/s per direction | 100 Mbit/s PROFINET (X1 or X2) | Shared managed switch with VLAN + QoS. |
| 1 to 5 kB/s per direction | 1 Gbit/s PROFINET (X2 on 1515-2 PN or higher) | Point-to-point cable or dedicated small switch. |
| > 5 kB/s per direction | 1 Gbit/s + jumbo frames | Point-to-point cable only; do not share. |
7. Timestamp Strategy Inside the PLC
Do not rely on the SQL server's GETDATE() to give the acquisition instant. Use a 64-bit PLC timestamp and write it explicitly into the row:
// Read the system clock (UTC) as LTime (nanoseconds since 01.01.1970)
#tPLC := RD_SYS_T_LTIME; // 64-bit nanosecond timestamp
// Convert LTime to a 64-bit integer (DInt) or to a high-resolution DTL
// Store as: - INTEGER8 nanoseconds
// - INTEGER2 microseconds
// - INTEGER4 seconds since epoch (Unix time)
// Or compose a single 8-byte array and write it as VARBINARY
Use the IEC standard LTime (64-bit nanoseconds) for high precision. When LSql or OPC UA is used, this timestamp must be packed into a string or a byte array, which is the source of the throughput penalty discussed in the next section.
8. Data Transfer Strategies Compared
There are three realistic data-transfer strategies. The choice is dictated by the data volume, the tolerance for timestamp jitter, and the available PC-side software.
| Strategy | Payload per cycle | Timestamp accuracy | PC software required | Drawback |
|---|---|---|---|---|
| A. Per-cycle row, PLC writes directly to SQL via LSql | Small (one row per 10 ms) | Network jitter + SQL server time, poor | None (LSql is built into the PLC) | LSql converts values to string; payload inflates ~3x; not efficient above ~1 kB/s. |
| B. Per-cycle row, PC application polls the PLC and inserts into SQL | Small to medium | Receiver-side, ~ms | Custom .NET, Python, or Node-RED | Polling cadence must be tuned; no native LSql; PC application must be a Windows service. |
| C. Buffered blob, PC application reads a block and inserts in batch | Large (1 s to 10 s of rows in one write) | PLC-side LTime, best | PC application that un-blobs | PC application must unpack the binary; higher engineering cost; SQL needs an un-blobbing view or staging table. |
For the 3.5 to 4 kB/s envelope, Strategy A (LSql) is theoretically possible but inefficient. LSql uses SQL text queries, so the wire payload is at least three times the raw binary payload once values are converted to ASCII. Strategy B (PC polls, writes one row at a time) keeps the timestamp on the receiver and is straightforward to debug. Strategy C (PC reads a buffer every 1-2 s and inserts 100 to 200 rows at once) is the best engineering compromise because it shifts the timestamp source back to the PLC clock and keeps the SQL insert load at one transaction per second.
9. LSql Library: Where It Works and Where It Hurts
The LSql library is part of the standard TIA Portal installation and provides function blocks that build SQL statements inside the PLC and send them via the integrated PROFINET interface. Typical blocks include LSql_Connect, LSql_Execute, LSql_Fetch, and LSql_Disconnect. The library is documented under the "Siemens SIMATIC S7-1500 / ET 200SP" library set on the Siemens Industry Online Support portal.
LSql characteristics relevant at 100 Hz:
- String conversion: every numeric value is converted to a string before the SQL statement is sent. A single float (4 bytes) becomes up to 14 bytes on the wire, plus delimiters.
-
One statement per call: you cannot send a batched INSERT in one call. You call
LSql_Execute100 times per second, which loads the connection with 100 round trips. - Synchronous over TCON: the connection is TCP-based and the block waits for an acknowledgment from the server, which means that any SQL server latency directly adds to the OB3x execution time.
LSql_Execute from inside OB3x is possible only if the SQL server replies in < 8 ms. This is rarely achievable on a loaded plant server. Either move the LSql call to a lower-priority cyclic OB (for example, OB1 with a 100 ms divisor) and use a PLC-side buffer, or switch to a PC application that polls the PLC and writes to SQL.10. PC-Side Stack: InfluxDB + Grafana + Node-RED
When the customer only needs a "SQL database", an honest conversation must take place about what they will do with the rows afterwards. If the rows are intended for trending, dashboards, or alarming, a time-series stack is technically superior to a relational SQL server. The well-trodden combination in industrial PC environments is:
| Component | Role | Why it fits 100 Hz logging |
|---|---|---|
| Node-RED | Data broker on the IPC | Native S7 / OPC UA nodes, runs as Windows service, handles back-pressure. |
| InfluxDB | Time-series storage | Line protocol accepts one sample per line; indexing by time and tag; no schema design needed. |
| Grafana | Dashboarding | Native connector to InfluxDB; live panels update at 1 Hz or faster; alerting supported. |
| SQLite | Optional local buffer | Grafana's default DB; works for low-volume SQLite-based dashboards when the customer insists on a "SQL file". |
This stack is mentioned in the source as a proven combination that "just works" for PLC-to-PC logging. It removes the LSql string conversion overhead because Node-RED reads from the PLC via native S7 / OPC UA / Modbus TCP nodes and pushes the parsed values into InfluxDB's line protocol, which is text but very compact. A typical line of 8 values, each as a 32-bit float, occupies around 200 bytes in line-protocol form, including the timestamp, which keeps the wire load well below the 4 kB/s envelope even with per-cycle inserts.
11. Throughput Calculation Worksheet
To size the link, compute the wire payload of the chosen strategy. The formulas below assume one timestamp (LTime) and N 32-bit float values per cycle. The 100 Hz cycle gives 100 cycles per second.
// Strategy A: LSql text-based INSERT
// Wire payload per row = N * (max 14 chars + 2 delimiters) + 32 overhead
// Total per second = 100 * Wire payload
// Example: N = 8, payload = 8 * 16 + 32 = 160 bytes/row -> 16 kB/s
// Strategy C: Binary blob, 100 rows per bulk write
// Wire payload per blob = 100 * (8 bytes timestamp + N * 4 bytes value)
// Total per second = payload / write_period
// Example: N = 8, write every 1 s, payload = 100 * 40 = 4 kB/s
The 3.5 to 4 kB/s target stated by the customer is consistent with Strategy C at N = 8 values per sample and a 1 second bulk interval. If the customer ever requests a higher N, the bulk interval must be reduced or the link upgraded to gigabit.
12. Sample Implementation Skeleton (TIA Portal)
The skeleton below shows the cyclic OB reading eight fast inputs with direct access, packing the values and a 64-bit timestamp into a byte array, and exposing that array for a PC application to read via OPC UA or a PUT/GET connection.
// In OB33 (10 ms cyclic)
#tPLC := RD_SYS_T_LTIME; // 64-bit LTime
// Direct read of 8 input words from local I/O slot 4
#iw0 := IW112:P; // Channel 0
#iw1 := IW114:P; // Channel 1
#iw2 := IW116:P; // Channel 2
#iw3 := IW118:P; // Channel 3
#iw4 := IW120:P; // Channel 4
#iw5 := IW122:P; // Channel 5
#iw6 := IW124:P; // Channel 6
#iw7 := IW126:P; // Channel 7
// Pack into a 40-byte frame: 8 bytes timestamp + 8 * 4 bytes float
#dbLogging.t[1] := DWORD(#tPLC AND 16#FFFFFFFF);
#dbLogging.t[5] := DWORD(SHR(#tPLC, 32));
// Convert each INT to REAL and pack
#dbLogging.v[1] := REAL(LREAL(#iw0) / 27648.0); // normalized to 0..1
// ...repeat for the other 7 channels...
// Set a "new sample" boolean and increment a counter for sanity
#dbLogging.bNew := TRUE;
#dbLogging.cnt := #dbLogging.cnt + 1;
On the PC side, an OPC UA client or a Node-RED S7 node subscribes to dbLogging, reads the 40-byte frame on the rising edge of bNew, and posts it to InfluxDB or to the SQL staging table. The timestamp in the row is #tPLC, not the time the row was written.
13. Commissioning Procedure
- Wire the network. Connect the PLC's X2 port to the IPC's NIC using a CAT 6A cross-over or a dedicated small switch. Disable spanning tree on the port pair if a switch is used.
- Configure the CPU time. Synchronize the PLC to an NTP server (or to the IPC via NTP). Verify that the LTime value remains within 10 ms of the IPC clock.
- Configure OB33. Set the period to 10 ms and the phase offset to 0. Compile and download. Monitor the OB3x execution time in the online diagnostic view; the maximum must remain below 6 ms with margin.
- Enable the input modules. For each AI module in the configuration, set the integration time to the fastest available value and the diagnostic interrupt to "none" (to avoid extra load on OB82).
-
Force a square wave on a test channel and verify that the
dbLogging.v[*]values toggle at 100 Hz by counting thecntfield on the watch table. - Configure the OPC UA server on the CPU with the new data block published under a custom namespace.
- Set up Node-RED. Install the S7 node, configure the OPC UA subscription, and add a debug node. Confirm that 100 messages per second are arriving.
-
Configure InfluxDB. Create a database
plc_100hzand a retention policy of 90 days. Add an InfluxDB write node in Node-RED, point it atmeasurement=fast_datawith the eight values as fields and the timestamp as the line time. - Build a Grafana dashboard with eight time-series panels and a refresh rate of 1 s. Verify visually that the square wave is plotted.
- Run a 24-hour soak test with a counter that must be exactly 8 640 000 at the end. If the counter is low, an OB3x instance was missed; investigate the OB priority and the process image update configuration.
14. Verification Checklist
| Item | Pass criterion | How to verify |
|---|---|---|
| OB33 period | 10 ms ± 0.1 ms | Watch table with RD_SYS_T deltas. |
| OB33 execution time | < 6 ms (worst case) | Online & diagnostics → cycle time. |
| Sample counter | 8 640 000 per day | Watch table at start and end of shift. |
| Timestamp drift | < 50 ms vs. IPC NTP time | Compare LTime with NTP-corrected PC clock. |
| Link utilization | < 5 % of gigabit bandwidth | Switch port counter or iperf cross-check. |
| SQL / InfluxDB latency | 95th percentile write < 50 ms | Enable slow-query log or InfluxDB HTTP latency stat. |
| Database growth | Matches the 3.5 to 4 kB/s target within 10 % | Compare file size after 24 h with predicted growth. |
15. Troubleshooting Matrix
| Symptom | Most likely cause | Remedy |
|---|---|---|
| OB3x counter lags behind wall clock | OB period too short for execution time | Increase period to 20 ms, or move LSql call to OB1. |
| Sample values look "stuck" on one channel | OB1 process image is being read instead of physical I/O | Use the :P suffix on every read. |
| Timestamps on the SQL side are out of order | Multiple packets arrived on different threads | Serialize the SQL inserts with a single connection or buffer in the PC app. |
| SQL server CPU goes to 100 % | One INSERT per 10 ms with full ACID logging | Batch inserts; switch to delayed durability; or move to InfluxDB. |
| Grafana shows gaps | Node-RED queue overflow when PC is busy | Increase the Node-RED queue size, or lower the acquisition to 50 Hz. |
| CPU diagnostic buffer reports "OB3x overrun" | OB3x period or priority misconfigured | Drop OB3x priority below OB1 only if determinism is not required, or shorten the OB body. |
16. Frequently Asked Questions
Can an S7-1200 do 100 Hz acquisition to SQL?
For very small payloads (single integer, no buffering) an S7-1200 can in principle, but it lacks the LSql library, the LTime nanosecond timestamp, and the high-speed analog modules of the S7-1500. Use the S7-1500 for any production 100 Hz logging task.
Is the LSql library fast enough for 100 Hz?
Only for very small payloads and only if the SQL server answers in less than ~8 ms. The text-based INSERT inflates the wire payload roughly three times and forces 100 round trips per second. For 3.5 to 4 kB/s of binary data, use a PC application that polls the PLC and batches the inserts.
Do I have to use the :P suffix on every read?
Yes, for inputs that are read inside the cyclic OB. The :P suffix bypasses the process image and reads the physical input at the moment the OB executes, removing the OB1 update jitter. It is the single most effective way to reduce timestamp scatter on the PC side.
Should I use a separate point-to-point cable for the SQL host?
For 3.5 to 4 kB/s it is strongly recommended. The point-to-point cable eliminates plant-network collisions, removes TCP retransmissions caused by HMI broadcasts, and keeps the SQL timestamps within a few milliseconds of the PLC clock.
Is InfluxDB acceptable as a "SQL database" for the customer?
InfluxDB is not a relational SQL database, but it speaks SQL-like query languages (InfluxQL, Flux) and Grafana can query it directly. If the customer's downstream tooling (Power BI, Excel) requires true SQL, mirror the InfluxDB line protocol to a staging table in SQL Server or PostgreSQL on a 1 s tick.