Overview
Programmable Logic Controllers (PLCs) are deterministic microcomputers optimized for real-time industrial control. They replace hard-wired relay logic with software-resident ladder, function-block, and structured-text programs, and they form the data source layer for Supervisory Control and Data Acquisition (SCADA) systems. A SCADA station typically polls multiple PLCs and Remote Terminal Units (RTUs) over industrial fieldbuses, stores the data in a historian, and renders it on operator HMIs.
This tutorial covers the four foundational areas every new PLC/SCADA engineer must internalize before touching hardware:
- The PLC scan cycle and why it is fundamentally different from text-based languages like C or BASIC.
- PROFIBUS DP network topology, termination, and D-sub connector wiring.
- Siemens STEP 7 hardware configuration for the S7-300 CPU 313C-2 DP as a DP master.
- OPC server bridging between PROFIBUS devices and SCADA clients such as WinCC, Citect, or LabVIEW.
Prerequisites
- Working knowledge of at least one text-based language (C, BASIC, Pascal, or LabVIEW dataflow).
- Familiarity with binary logic, relay ladder diagrams, and Boolean algebra.
- A Windows PC capable of running Siemens STEP 7 V5.x or TIA Portal V16+ for project engineering.
- A PROFIBUS DP master interface card for the engineering station (PCI or PCMCIA) plus the vendor's communication server / DTM software.
- PROFIBUS DP cable (purple, type A, impedance 135-165 Ω, capacitance ≤ 30 pF/m) and 9-pin D-sub PROFIBUS connectors with integrated termination and PG socket.
- A Siemens S7-300 CPU 313C-2 DP (order code 6ES7 313-6CF03-0AB0 or equivalent) on a DIN rail with a PS 307 power supply and signal modules as required.
PLC vs Traditional Programming: The Execution Model
A PLC is not a desktop PC. It runs a single, repeating loop that reads physical inputs, evaluates user logic exactly once, and writes the resulting values to physical outputs. The cycle time is deterministic and bound by the program length, I/O count, and communication overhead. Typical S7-300 CPUs execute between 0.1 ms and 10 ms of bit logic per scan, depending on the instruction mix.
The implication is profound:
- No event-driven interrupts by default. A PLC will not react to a rising edge on a digital input unless you poll it inside the OB1 scan, attach a hardware interrupt OB (OB40-OB47), or configure a cyclic interrupt OB (OB30-OB38).
- Variables persist between scans. Unlike a C function, OB1 is not called and discarded; it is re-entered. Holding flags (Merker/M), data blocks (DB), and I/O images retain their values across scans.
- Race conditions are usually impossible by design. Because logic evaluates once per cycle in a fixed order, the input image is frozen at the start of the cycle and the output image is committed atomically at the end. This eliminates most races that plague threaded C code.
while(1) loops with sequential logic distributed across OB1, and treat every variable you would normally globalize as a named DB tag.The PLC Scan Cycle in Detail
The Siemens S7-300 executes the following fixed sequence every scan, defined in Siemens entry ID 109751784 (S7-300 CPU 31xC Technological Functions manual):
- Operating system startup. Cold restart, warm restart, or hot restart based on mode selector and CPU configuration.
- Process image update (PII / PIQ). All digital inputs are read into the Process Image Input (PII) area in bit memory; analog inputs are read into PII words. Outputs are written from the Process Image Output (PIQ) at the end of the cycle.
- User program execution (OB1 and subordinate blocks). The CPU evaluates the program in the order defined by the call hierarchy. Each call consumes deterministic time.
- Communication processing. PROFIBUS DP, MPI, and (if configured) Industrial Ethernet / PROFINET services run partly in parallel via the communication processor's firmware. Time-slice budget is configurable.
- Output write. PIQ values are committed to the physical outputs.
- Self-diagnostics and housekeeping. Watchdog, memory object bit tests, and OB82/OB85/OB86 fault calls are evaluated.
Minimum cycle time, maximum cycle time, and cycle time monitoring are set in HW Config → CPU Properties → Cycle/Clock Memory. Recommended starting values for an educational lab rig:
| Parameter | Recommended | Notes |
|---|---|---|
| OB1 cycle load limit | 20 % | Leaves headroom for cyclic interrupts (OB35) at 100 ms. |
| Cycle monitoring time | 150 ms (default 6000 ms) | Triggers OB80 / SF LED if exceeded. |
| Clock memory byte | MB100 | Provides 8 fixed-frequency flags (10 Hz, 5 Hz, 2 Hz, 1 Hz, 0.5 Hz, 0.2 Hz, 0.1 Hz). |
| Process image partition for OB35 | PIP 1 | Isolates time-critical I/O from main scan. |
SCADA Architecture Fundamentals
SCADA is the supervisory layer; the PLC remains the controller. According to the GE Vernova overview on PLC, HMI, and SCADA and the Inductive Automation "What is SCADA?" reference, a SCADA architecture contains the following elements:
The data flow is unidirectional at the field level (sensor → PLC → SCADA) and bidirectional at the supervisory level (operator command → PLC setpoint). Citect, mentioned in the SCADA tools lineage, is now maintained under the AVEVA Plant SCADA family and remains a popular choice for legacy installations.
Siemens S7-300 CPU 313C-2 DP Hardware Overview
The CPU 313C-2 DP combines a compact PLC with an integrated PROFIBUS DP master/slave port. Order codes in the 6ES7 313-6xxx family cover firmware versions V2.0 through V3.3. The integrated I/O of the 313C-2 DP includes:
| Resource | Quantity | Address Range (Default) |
|---|---|---|
| Digital inputs (DI24) | 24 (16 DI on board + 8 expandable) | I124.0 – I125.7 / I126.0 – I126.7 |
| Digital outputs (DO16) | 16 | Q124.0 – Q125.7 |
| Analog inputs (AI5) | 5 (4 voltage/resistance + 1 differential) | PIW 128 – PIW 138 |
| Analog outputs (AO2) | 2 | PQW 128 – PQW 132 |
| Counter inputs | 3 (24 V, up to 30 kHz) | Configured in HW Config |
| PROFIBUS DP port | 1 X2 (9-pin D-sub) | Node address 2 (default) |
| MPI/DP port | 1 X1 (configurable) | Node address 2 (default) |
| Bit memory (M) | 256 bytes | MB0 – MB255 |
| Work memory | 64 KB code + 64 KB data | — |
| Load memory | Micro Memory Card (MMC) up to 8 MB | Order code 6ES7 953-8LG00-0AA0 |
Always consult the official S7-300 CPU 31xC and CPU 31x operating instructions for the exact firmware variant you are commissioning. Wiring follows the front-connector pin assignment table printed on the inside of the door.
PROFIBUS DP Network Topology
PROFIBUS DP is a token-passing master/slave bus standardized in IEC 61158/61784. Maximum practical limits per segment:
| Parameter | Value | Notes |
|---|---|---|
| Nodes per segment | 32 (1 master + 31 slaves) | Repeaters extend this in steps of 32. |
| Baud rate vs segment length (type A cable) | ||
| 9.6 kbit/s | 1 200 m | — |
| 19.2 kbit/s | 1 200 m | — |
| 93.75 kbit/s | 1 200 m | — |
| 187.5 kbit/s | 1 000 m | — |
| 500 kbit/s | 400 m | — |
| 1.5 Mbit/s | 200 m | — |
| 3 / 6 / 12 Mbit/s | 100 m | Lab/instrumentation only. |
| Termination resistors | 220 Ω between A and B + 390 Ω pull-up to VP + 390 Ω pull-down to DGND | Activate at both physical ends only. |
Building the D-Sub PROFIBUS Connector with Termination
A standard 9-pin D-sub (DE-9) male connector is used on every PROFIBUS node. The PROFIBUS & PROFINET International (PI) connector pinout per IEC 61158 is:
| Pin | Signal | Function |
|---|---|---|
| 1 | SHIELD | Cable shield bonding |
| 2 | — | Reserved |
| 3 | B (RxD/TxD-P) | Red conductor |
| 4 | CNTR-P | Repeater direction control (TTL) |
| 5 | DGND | Data ground (0 V reference) |
| 6 | VP | +5 V termination supply |
| 7 | — | Reserved (24 V in some legacy cards) |
| 8 | A (RxD/TxD-N) | Green conductor |
| 9 | CNTR-N | Repeater direction control |
Termination is implemented inside the connector housing with a switch that engages the resistor network. For a home-built connector (e.g., Siemens 6GK1 500-0AB10 or compatible third-party), solder a 220 Ω resistor between pins 3 and 8, a 390 Ω between pin 6 and pin 3, and a 390 Ω between pin 8 and pin 5. Use a shielded twisted-pair cable with 135 Ω characteristic impedance.
- Strip the cable jacket to expose the shield braid for 360° bonding to the D-sub metal housing.
- Fold the shield back over the jacket; do not let strands touch the signal pins.
- Solder pin 3 (red) and pin 8 (green) keeping the pair twist as close to the connector as possible (≤ 13 mm).
- Solder pins 5 and 6 to the termination resistor divider.
- Tighten the strain relief and slide the slide switch to ON for the end-of-line nodes.
PROFIBUS DP Configuration in STEP 7 / TIA Portal
For a classic STEP 7 V5.5 project (still the standard for legacy S7-300 work), the configuration sequence is:
- Open SIMATIC Manager → File → New → Name the project.
- Insert → Station → SIMATIC 300 Station. Drag the CPU 313C-2 DP into slot 2.
- Open HW Config. Place the PS 307 in slot 1, the CPU in slot 2, and signal modules from slot 4 onward.
- Double-click the X2 PROFIBUS port on the CPU. Choose PROFIBUS as the type, set the address (default 2), and click Properties → New → PROFIBUS(1) with 1.5 Mbit/s and DP profile.
- Set the CPU's DP mode to DP Master; tick Test, Commissioning, Routing if you need PG access through the master.
- From the catalog, drag any DP slave (e.g., ET 200S, ET 200M, or a third-party slave GSD file) onto the DP(1) subnet. Assign it a unique PROFIBUS address (3-126).
- Map the slave's I/O into the process image by aligning byte addresses.
- Save and compile, then download HW Config to the CPU.
For new installations using TIA Portal V18+, the equivalent workflow is in the TIA Portal S7-300/400 Getting Started guide and the TIA Portal product page. The conceptual steps remain identical.
OPC Interface: Why LabVIEW and WinCC Cannot Talk Directly to PROFIBUS
OPC (OLE for Process Control) is the standardized interface between field-level hardware and supervisory applications. It was defined by the OPC Foundation and exists in three flavors relevant here:
| Spec | Year | Transport | Use Case |
|---|---|---|---|
| OPC DA 2.0 / 3.0 | 1998 / 2003 | COM/DCOM on Windows | Classic SCADA connectivity from a local PC. |
| OPC HDA | 2003 | COM/DCOM | Historical data read/write. |
| OPC UA 1.04+ | 2008+ | TCP binary or HTTPS, platform-independent | Modern, secure, cross-platform SCADA. |
Because LabVIEW and WinCC do not implement PROFIBUS DP slaves, the PROFIBUS master card on the PC (e.g., Applicom PC1500PFB) ships with an OPC server. The chain is:
PLC (DP slave) ↔ PROFIBUS cable ↔ PC PROFIBUS card ↔ Vendor OPC server ↔ OPC client (LabVIEW DSC, WinCC, Citect, Ignition)
The PLC does not need to "support" OPC. OPC runs on the SCADA PC; the PLC only exposes its I/O via PROFIBUS DP. The card vendor's communication server (e.g., Applicom Communication Server) configures which DP slaves participate, the baud rate, and the tag database. The OPC client then browses this database by item name.
OPC UA Toolkit that supports both DA 3.0 (legacy) and UA 1.04.Applicom PC1500PFB Card Integration Notes
The Applicom PC1500PFB is a PCI card from the Applicom family (now under HMS Industrial Networks) that provides a PROFIBUS DP master/slave interface for industrial PCs. The bundled Applicom Communication Server software configures the card and exposes its data to SCADA clients through an OPC server interface.
| Configuration Step | Action |
|---|---|
| 1. Install hardware | Power down, ground yourself, seat the card in a free PCI slot, attach the D-sub pigtail. |
| 2. Install driver | Run the setup from the Applicom Communication Server V2.9 CD; verify the device manager shows the card without yellow bang. |
| 3. Launch PCINIT | PCINIT initializes the card firmware and downloads the GSD database. A successful run reports the card's PROFIBUS address and firmware version. |
| 4. Configure master | Set the card's own node address (must differ from the S7-300 CPU 313C-2 DP address), baud rate (must match the slave), and slot assignments. |
| 5. Add slave (S7-300 CPU) | Import the Siemens GSD file siem808d.gsd if the card operates as a master, or alternatively set the CPU as master and the card as slave using siem8045.gsd. |
| 6. Test with PCILogger | Use the vendor's diagnostic utility to verify cyclic I/O exchange before connecting SCADA clients. |
| 7. Connect OPC server | Launch the bundled OPC server; browse from any OPC client (e.g., OPC Scout from Siemens) to verify tag visibility. |
If your engineering PC is older than Windows XP, see the OS compatibility notes below.
Windows 98 Compatibility Considerations
Applicom Communication Server V2.9 was originally released for Windows NT 4.0 / Windows 2000, and later refreshed for Windows XP. Running it on Windows 98 is not officially supported and presents specific risks:
| Issue | Impact on Win98 | Mitigation |
|---|---|---|
| DCOM security model | Win98 ships with an outdated DCOM 95 implementation that lacks proper authentication. OPC DA traffic is exposed on the LAN. | Apply the Win98 DCOM 1.3 patch from Microsoft; isolate the PC on a private subnet. |
| PCI Plug-and-Play | Many industrial PCI cards require ACPI BIOS features absent in late-1990s Windows 9x kernels. | Enable the standard PCI bus enumerator; manually assign IRQ if the card fails to enumerate. |
| Driver signing | Win98 does not enforce WHQL signing, but unsigned drivers can load unreliably. | Use the signed driver from the V2.9 CD; never use a beta driver. |
| Memory ceiling | Win98 caps user-mode virtual memory at ~512 MB; OPC tag databases above ~5 000 tags may refuse to allocate. | Limit tag count; archive older data to flat files. |
| USB and modern peripherals | LabVIEW 6.i was patched to Win98; later LabVIEW versions are not. | Run LabVIEW 6.1 + Datasocket; do not upgrade past LabVIEW 7.0 if Win98 must be retained. |
If feasible, migrate the engineering station to Windows XP Professional SP3 or a 32-bit Windows 7 install. Both remain supported by legacy Siemens and Applicom runtimes and provide a stable DCOM model.
LabVIEW Integration via OPC
The recommended LabVIEW topology is:
- The PROFIBUS card runs the vendor's communication server, which hosts an OPC DA 2.0 server.
- LabVIEW's
Datasocket Read/Datasocket WriteVIs (Functions Palette → Data Communication → Datasocket) connect toopc:\<machine>\Applicom.PC1500PFB\TagName. - For long-running dashboards, encapsulate reads inside a polled while-loop with a 100-250 ms delay.
- Map each PROFIBUS byte to a LabVIEW cluster element using
Boolean Array to NumberandNumber to Boolean Arrayprimitives.
Example pseudo-code for a 1-byte read/write loop:
while (stop button == FALSE) {
dsRead = dsOpen("opc://localhost/Applicom.PC1500PFB.S7_300.InputByte0", DSREAD, 250);
dsWrite = dsOpen("opc://localhost/Applicom.PC1500PFB.S7_300.OutputByte0", DSWRITE, 250);
if (dsRead.status == 0) {
BOOL arr[8];
ByteToBoolArray(dsRead.value, arr);
indicator[0..7] = arr;
}
dsWrite.value = BoolArrayToByte(control[0..7]);
Wait(ms=200);
}
Verification and Commissioning Checklist
- Power-on: PS 307 green LED steady; CPU SF/BF off, DC5V on, RUN not flashing.
- PROFIBUS LEDs on slaves: Steady green on BF; flashing green indicates parameterization without data exchange.
- Diagnostic buffer: In STEP 7, CPU → PLC → Diagnostic/Clock → Diagnostic Buffer; confirm no entries related to station failure (OB86) or peripheral access error (OB122).
- Cycle time: PLC → Monitor/Modify → check that measured OB1 cycle is below the configured monitoring time by at least 30 %.
- I/O loopback test: Wire a temporary jumper from DO0 to DI0 and verify in a VAT table that Q124.0 drives I124.0 within one scan.
- OPC tag browse: From OPC Scout, enumerate the Applicom server; read and write one tag end-to-end.
- SCADA HMI render: Confirm the tag appears in WinCC / Citect / LabVIEW with correct scaling and engineering units.
- Fault injection: Disconnect the PROFIBUS connector; verify the CPU logs OB86 and the SCADA surfaces a "Slave 3 lost" alarm.
Troubleshooting Matrix
| Symptom | Likely Root Cause | Corrective Action |
|---|---|---|
| BF (Bus Fault) LED flashing on CPU 313C-2 DP | No PROFIBUS partner, wrong baud rate, missing termination | Check baud rate match; verify terminators on the two physical end nodes only. |
| BF steady, SF off on slave | Slave not configured in master project | Add slave GSD and slot mapping in HW Config; recompile and download. |
| SF LED on CPU after download | Slot mismatch or wrong GSD revision | Right-click slave → Object Properties → confirm GSD revision matches the slave's firmware. |
| OPC server does not enumerate tags | PCINIT not run or DCOM permissions | Re-run PCINIT; configure DCOMCNFG permissions for the OPC server account. |
| LabVIEW reads always return error -2147024891 | E_ACCESSDENIED due to DCOM rights | Add the LabVIEW user to the OPC server's DCOM access list; restart LabVIEW. |
| Scan time spikes to > 500 ms intermittently | OPC polling exceeding the communication time-slice | Increase "Maximum communication load" in CPU properties, or slow OPC poll to 1 s. |
| OPC UA client cannot discover endpoint | Firewall blocks TCP 4840 | Open inbound TCP 4840 in Windows Firewall on the OPC UA server host. |
Field-Proven Engineering Tips
- Reserve the first two and last two PROFIBUS addresses (0, 1, 126, 127) for service tools and class-2 masters to avoid collisions with running slaves.
- Document the GSD revision and firmware version of every slave in the project header. GSD revisions are unforgiving; mismatches cause the master to refuse parameterization.
- Use fiber-optic PROFIBUS (OLM) when the cable run exceeds 100 m in an electrically noisy plant; copper cable is good for ≤ 1.2 km at 93.75 kbit/s only.
- When migrating from a working DP setup to PROFINET, the GSD file is replaced by a GSDML (XML) descriptor and the topology is reconfigured; the PLC program (OB1, DBs) is unchanged.
- For SCADA systems handling more than ~10 000 tags, design a tiered architecture: edge OPC aggregator → central historian → OPC UA client on operator stations.
Standards and Documentation References
- PROFIBUS technology page (PI - PROFIBUS & PROFINET International)
- OPC Foundation - What is OPC?
- Siemens S7-300 CPU 31xC operating instructions
- Siemens S7-300 technological functions manual
- Siemens TIA Portal product page
- Inductive Automation - What is SCADA?
- GE Vernova - Explaining PLC, HMI & SCADA
Frequently Asked Questions
What is the difference between a PLC scan cycle and a C program?
A PLC executes a fixed sequence of read-inputs, evaluate-OB1, write-outputs on every scan (typically 1-10 ms on an S7-300). A C program runs sequentially once from main() to exit, unless an RTOS scheduler is added. PLCs are designed for continuous, deterministic control; C programs are designed for algorithmic, event-driven work.
Can LabVIEW talk directly to PROFIBUS DP?
No. LabVIEW is an OPC client, not a PROFIBUS master. The PROFIBUS card (e.g., Applicom PC1500PFB) acts as the DP master and exposes tags through its bundled OPC server. LabVIEW's Datasocket VIs read those tags via the standard opc:\ URL scheme.
What baud rate should I use for a 200 m cable run?
According to the PROFIBUS PI cable length table, 200 m supports up to 1.5 Mbit/s with type A cable. For new installations, 1.5 Mbit/s is the practical maximum; for noisy industrial environments, drop to 500 kbit/s (400 m) or 187.5 kbit/s (1 000 m) to gain margin.
Does the PLC need to "support" OPC for SCADA communication?
No. The PLC only needs to expose its I/O on PROFIBUS DP. OPC runs entirely on the SCADA PC: the vendor's communication server bridges the DP card to the OPC DA/UA server, and the SCADA client (WinCC, Citect, LabVIEW DSC, Ignition) browses the tag database.
Is Windows 98 a viable platform for an Applicom PC1500PFB lab setup?
It can work for a small teaching demo but is not officially supported. Win98's outdated DCOM stack, missing ACPI features, and limited virtual memory create OPC and PCI enumeration issues. If migration is possible, Windows XP SP3 or a 32-bit Windows 7 install is recommended for both driver stability and OPC DA security.
How do I terminate a PROFIBUS segment correctly?
Place a 220 Ω resistor between pins 3 and 8 of the D-sub connector, plus 390 Ω pull-ups to pin 6 (VP, +5 V) and 390 Ω pull-downs to pin 5 (DGND). Enable this network only on the two physical end nodes of every segment and disable it on all intermediate nodes.