STEP 7 V5.5 S7-300 Programming: FB vs FC Block Tutorial

David Krause16 min read
S7-300SiemensTutorial / 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

Overview

STEP 7 V5.5 is the canonical engineering environment for SIMATIC S7-300 and S7-400 PLCs, structured around five core program-organization units: Organization Blocks (OB), Functions (FC), Function Blocks (FB), Data Blocks (DB), and User-Defined Types (UDT). Engineers new to Siemens PLC development must internalize a single decision rule before writing their first network: does the routine need to remember values between calls, or is it a pure transformation of inputs into outputs? The answer picks FC or FB deterministically, and every other block choice in the project cascades from it.

This reference walks a first-time STEP 7 V5.5 user from project creation through hardware configuration, then deepens into the FB/FC selection logic that the most common beginner threads get wrong. It assumes the S7-300 platform, STEP 7 V5.5 SPx, and the SIMATIC Manager interface (not TIA Portal). For TIA Portal projects, the block architecture parallels but the editor is different.

Platform boundary: STEP 7 V5.5 targets S7-300/S7-400 and the classic WinCC Flexible runtime. S7-1200 and S7-1500 require TIA Portal and will not accept a V5.5 project file (.s7p/.s7f). The block numbering and standard library described here do not exist on the S7-1200/1500 platform.

Prerequisites

Before launching the SIMATIC Manager, verify the following:

  • PC Operating System: Windows XP SP3 / Windows 7 SP1 (32-bit) is the canonical platform. Windows 10 64-bit requires STEP 7 V5.5 SP2 or later plus the SIMATIC USB driver package. Windows 11 is not officially supported in V5.5.
  • STEP 7 V5.5 Installation Media: The DVD ships with the SIMATIC Manual Collection. After install, the local help can be opened from Start > Simatic > Documentation and includes the manual Working with STEP 7 (entry ID 45531551).
  • Authorization Disk: STEP 7 V5.5 requires a parallel-port, USB, or floating license. Without it the editor opens in demo mode for 14 days and refuses to download to PLC.
  • Target PLC Firmware: S7-300 CPUs with firmware V2.x or V3.x are valid targets. CPU 31x-2 DP/PN variants are the typical S7-300 development target.
  • PC Adapter or CP 5611/CP 5612 MPI/PROFIBUS Card: For online download/monitoring. A CP 5711 (USB) is the modern equivalent.
  • Working knowledge of ladder logic fundamentals: Bits, contacts, coils, timers, counters, and scan-cycle semantics.

Installing STEP 7 V5.5 and Project Setup

Insert the STEP 7 V5.5 DVD, run Setup.exe, and accept the default installation path C:\Program Files\Siemens\Automation\SIMATIC Manager. The installer registers the Automation License Manager service, copies the S7 block libraries, and writes the SIMATIC Manager shell extension. After installation, run SIMATIC Manager from Start > Simatic > SIMATIC Manager.

  1. Close any open projects.
  2. Select File > New Project Wizard...
  3. Choose CPU 314C-2 DP as the example target (substitute your actual CPU order number, e.g., 6ES7 314-6EH04-0AB0).
  4. Accept default OB1 in LAD/FBD/STL as the cyclic program.
  5. Confirm a name for the project. The wizard creates the S7 program container, the station, and an empty OB1.

The project tree in the right pane shows S7-300 Station > CPU 314C-2 DP > S7 Program > Blocks. Everything else — hardware, program logic, and online diagnostics — is reachable from this root.

Hardware Configuration for S7-300

Open SIMATIC 300 Station > Hardware and double-click Hardware. HW Config launches, the catalog appears on the right, and the rack appears on the left. Build the rack top-to-bottom by drag-and-drop:

  1. PS 307 2A (6ES7 307-1BA01-0AA0) into slot 1.
  2. CPU 314C-2 DP (6ES7 314-6CG03-0AB0) into slot 2. The integrated DI16/DO16/AI5/AO2 I/O is automatically attached.
  3. SM 321 DI16x24VDC (6ES7 321-1BH02-0AA0) into slot 4.
  4. SM 322 DO16x24VDC/0.5A (6ES7 322-1BH01-0AA0) into slot 5.

Save and translate the configuration (Station > Save and Compile). The system data blocks (SDB) are generated under Blocks > System Data. Download the hardware to the CPU via PLC > Download with the CPU in STOP, then return the CPU to RUN.

Best practice: Never edit a project without first doing a clean Station > Check Consistency. A mismatched module order number (MLFB) on the rack versus the catalog silently fails the download with SF LED on the CPU and a diagnostic buffer entry "Parameter error in module".

Block Architecture: OB, FB, FC, DB, UDT

STEP 7 organizes logic into five block types, each with a strict role:

Block Purpose Retains state? Called by Number range
OB (Organization Block) System event entry point: scan, startup, error, interrupt No (per-event) Operating system Fixed (OB1, OB82, OB100, ...)
FC (Function) Pure subroutine: IN/OUT/IN_OUT/TEMP, returns one void result No OB, FB, FC 0–65535 (0–39 reserved)
FB (Function Block) Subroutine with dedicated memory (instance DB) Yes (in IDB) OB, FB, FC 0–65535 (0–39 reserved)
DB (Data Block) Data storage: shared (global) or instance (per FB call) N/A (data only) Logic accesses it directly 1–65535
UDT (User-Defined Type) Reusable data structure / template N/A Instantiated inside DB/FB 0–65535

The OB is the only block the CPU calls automatically. The cyclic main scan is OB1; startup is OB100 (warm restart), OB101 (hot restart), or OB102 (cold restart) depending on CPU family. Error events invoke OBs 80–87. OBs 10–17 are time-of-day interrupts, OBs 20–23 are delay interrupts, OBs 30–38 are cyclic interrupts, and OBs 40–47 are hardware interrupts. If a fault OB is missing, the CPU goes to STOP — a classic beginner crash when, e.g., OB82 (diagnostic interrupt) is absent and a module reports a diagnostic event.

Programming Languages: LAD, FBD, STL

STEP 7 V5.5 lets each block be edited in any of three languages, switched without re-compilation:

  • LAD (Ladder): Graphical contact/coil logic, dominant in North American discrete-control projects.
  • FBD (Function Block Diagram): Graphical AND/OR/box networks, common in European process-control projects.
  • STL (Statement List): Textual mnemonics (A, O, =, L, T, etc.), most compact and the only language with conditional block calls and indirect addressing.
Language gotcha: STL is case-sensitive in the editor and rejects any block title with a leading numeral. LAD and FBD are the only safe choices for code that will be re-opened by mixed-skill teams.

When to Use FC (Function) — Stateless Subroutines

An FC is a pure subroutine. It declares IN, OUT, IN_OUT, and TEMP variables in its interface, executes top-to-bottom when called, and discards all TEMP data on return. There is no associated instance DB. An FC cannot remember a value from one scan to the next unless the calling code passes the same variable back in on the next call.

Use an FC when:

  • The routine computes a result from inputs and returns it (math, scaling, conversion, string formatting, recipe selection, motion profile calculation).
  • The routine performs an action with no persistent state (e.g., send a message via AG_SEND, write a setpoint to a drive once per scan, log a batch event).
  • You need a single copy of the code shared by many callers without per-instance data.

Example — Scale a 0–27648 raw analog input to 0–100% engineering units:

FUNCTION FC100 : VOID
// Scale raw AI to engineering units, percent basis
VAR_INPUT
  i_raw  : INT;     // 0..27648 from %IW address
  i_lo   : REAL;    // 0.0
  i_hi   : REAL;    // 100.0
END_VAR
VAR_OUTPUT
  o_eu   : REAL;    // scaled result
END_VAR
BEGIN
  o_eu := INT_TO_REAL(i_raw) / 27648.0 * (i_hi - i_lo) + i_lo;
END_FUNCTION

The FC is called from OB1 with: CALL FC100 with the four formal parameters bound to actual addresses (e.g., i_raw := %IW128). The output o_eu must be assigned a destination tag in the calling block.

When to Use FB (Function Block) with Instance DB — Stateful Subroutines

An FB adds a STAT section to its interface. STAT variables are stored in a paired Instance DB (IDB) that the FB writes to and reads from. The IDB is created automatically by STEP 7 the first time the FB is called with CALL FB100, DB100 (or, more commonly, with STEP 7 auto-generating the next free DB number).

Because STAT persists between calls, an FB is the correct choice for:

  • Motor starters, valve controllers, PID loops: start/stop latches, run-time accumulators, last-trip latches, integrator state.
  • Sequencers and state machines: current step, previous step, dwell counter.
  • Multi-instance applications: one master FB containing several calls to the same slave FB, each with its own IDB. The instance model of an FB is a C++-class object with a dedicated memory block.

Example — Edge-triggered latching motor starter with run-time accumulator:

FUNCTION_BLOCK FB200
VAR_INPUT
  i_start    : BOOL;   // momentary start pushbutton
  i_stop     : BOOL;   // NC stop pushbutton
  i_OL       : BOOL;   // overload contact, NC (TRUE = healthy)
END_VAR
VAR_OUTPUT
  o_run      : BOOL;   // contactor command
  o_fault    : BOOL;   // latched fault
END_VAR
VAR
  s_latched  : BOOL;   // STAT: hold-on latch
  s_rt_s     : REAL;   // STAT: run-time hours
  s_last     : BOOL;   // STAT: previous start edge
END_VAR
BEGIN
  // Detect rising edge of i_start
  IF i_start AND NOT s_last THEN
    s_latched := TRUE;
  END_IF;
  s_last := i_start;

  // Latch is reset by stop OR by overload dropping out
  IF i_stop OR NOT i_OL THEN
    s_latched := FALSE;
  END_IF;

  // Latch any OL dropout as a fault that requires manual reset
  IF NOT i_OL AND s_latched THEN
    o_fault := TRUE;
  END_IF;

  o_run := s_latched AND i_OL;
END_FUNCTION_BLOCK

The IDB that pairs with this FB (DB200, automatically created on first CALL FB200, DB200) holds the three STAT values. Different motor instances can use the same FB code but with separate IDBs (e.g., DB201 for pump 2, DB202 for pump 3) — exactly the object-oriented instance model.

FB vs FC Decision Matrix

Requirement Use FC Use FB with IDB
Pure transformation of inputs to outputs
Need to remember state between calls
No persistent latches, no timers needing retention
Multiple instances of the same logic with separate memory ✓ (each instance gets its own IDB)
Code shared by many callers with no per-instance data
Multi-instance nesting (one FB calls itself/others as sub-blocks) ✓ (multi-instance model)
Receives an address to operate on (pointer-like, ANY-POINTER) ✓ (preferred for VARIANT-style code)

The interface declarations also differ: FB supports STAT (retained in IDB across scans), while FC only has TEMP (scratchpad, lost on return). The presence of STAT is the structural giveaway that you are looking at an FB.

Standard Library Block Reference

STEP 7 V5.5 ships with libraries that should be used rather than re-invented. The most important ones, with the part of the standard library, are listed below:

Library / Block Type Function
FC1 AD_DERIV FC Derivative of real input
FC2 CU FC Counter up with preset and load inputs
FC3 D_ACT_DP FC Activate or deactivate a DP slave
FC5 AG_SEND / FC6 AG_RECV FC AS-OS send/receive over MPI/IE for HMI exchange
FC105 SCALE FC Scale INT 0–27648 to engineering REAL range (legacy but ubiquitous)
FC106 UNSCALE FC Inverse of FC105
FB41 CONT_C FB Continuous PID controller (legacy but extremely common in S7-300 code)
FB42 CONT_S FB Step controller with integral actuator (valve positioner)
FB43 PULSEGEN FB Pulse-width modulation output for heat/cool split-range
FB4 AG_SEND / FB5 AG_RECV FB Equivalent of FC5/FC6 with extended data (sends via CP)
FC20 EQ_C / FC21 EQ_B FC Equality compare for arrays/blocks (C/B variant for arrays vs blocks)
SFC0 SET_CLK / SFC1 READ_CLK SFC Set/read CPU real-time clock
SFC20 BLKMOV SFC Block-move memcpy for any data area
SFC22 CREAT_DB SFC Dynamically create a DB at runtime
SFC51 RDSYSST SFC Read system status list (SSL) for diagnostics
SFB0 OB_CYCL / SFB1 OB_PER SFB Background variants for system-side blocks

SFCs (System Functions) and SFBs (System Function Blocks) are supplied by the operating system and live in the CPU firmware. Calling them is identical to calling user FCs/FBs. They cannot be re-compiled or viewed in source.

Numbering convention: Block numbers 0–39 are reserved in some libraries to prevent collision. Pick user FCs in the 100–999 range and FBs in the 200–999 range during early project design — it leaves room for vendor library blocks to be inserted without renumbering your calls.

Programming Workflow Example: Motor Control with FB and HMI UDT

A typical first project on an S7-300 has three motors, one analog sensor, and one HMI. The cleanest structure is:

  1. Define UDT100 for a motor with the data fields cmd_start BOOL, cmd_stop BOOL, status_run BOOL, fault BOOL, runtime_h REAL.
  2. Define FB200 as the motor control logic. STAT contains the latched run command and the runtime hours.
  3. In OB1, call CALL FB200, DB200 for motor 1, DB201 for motor 2, DB202 for motor 3. Each IDB stores its own runtime hours.
  4. Define DB100 as the global HMI data block. It contains three instances of UDT100 (Motor[1], Motor[2], Motor[3]) and a small alarm buffer.
  5. Use FC105 to scale the analog input into a 0–100% pressure value stored in DB100.PV_Pressure.
  6. Configure the HMI to read the symbolic names DB100.Motor[1].status_run (or, on a non-symbolic tag panel, the absolute address DB100.DBX8.0).

Symbolic programming is enabled per symbol table (S7 Program > Symbols). With it on, calls become readable: CALL "Motor_Ctrl" , "Motor_1_IDB".

Download, Online, and Monitoring

After saving and compiling the blocks, the project is downloaded to the CPU:

  1. Select S7 Program > Blocks in the project tree.
  2. Click PLC > Download. STEP 7 will prompt to select the target node (MPI address, PROFIBUS address, or IP for PROFINET CPUs).
  3. Confirm the CPU is in STOP, or accept the prompt to put it in STOP for the download.
  4. After download, switch the CPU to RUN via PLC > Operating Mode or the mode selector on the CPU front panel (key in the STOP position to defeat unauthorized RUN).

To watch a running block, open the block from the online project tree (View > Online or the eye icon in the toolbar). Use Debug > Monitor to see live signal state, or right-click a tag and select Modify to force a value. Forcing a BOOL/INT in the online monitor writes to the working memory and persists until a CPU STOP->RUN transition clears it — a common debugging pitfall when a "stuck" output is actually a forgotten force.

Force safety: Forcing bypasses the program logic and directly drives outputs. Always clear forces (Debug > Clear Force) before handing a project over to operations. Forcing is independent of password protection on FBs unless the FB has a KNOW_HOW_PROTECT attribute set in its properties.

Verification and Diagnostics

A new project should pass the following checklist before commissioning:

  1. Hardware consistency check passes (Station > Check Consistency) and the diagnostic buffer of the CPU is free of "Parameter error" and "Module removed" entries.
  2. Block consistency check passes (Program > Compile All). All FCs, FBs, and DBs are visible in the online view under Blocks; the downloaded program matches the offline project exactly.
  3. OB1 watch: open OB1 in online monitor. The current scan and OB1 execution flags should alternate. Cycle time, visible in PLC > Module Information > Scan Cycle Time, should be well below the configured maximum cycle time (default 150 ms for S7-300).
  4. FB instance DB test: in the online view, open the IDB paired with each motor FB. Toggle the start input in the monitor and verify the STAT s_latched becomes TRUE and stays TRUE after the input releases. Verify runtime hours increments in s_rt_s (a small per-scan increment driven by a clock OB or an OB1 counter is normal).
  5. FC stateless test: call the scaling FC with known raw inputs and confirm the output matches hand-calculated values. Verify that opening the FC and changing the input does not corrupt any tag outside the FC's OUT — the FC has no memory outside its own scratchpad.
  6. Standard library sanity: any call to FC105, FB41, SFC20, etc. must reference blocks that exist in the CPU firmware. The presence of the call alone is not enough; the firmware must support the SFC/SFB version.
  7. Diagnostic OBs present: if a hardware interrupt is used, OB40–OB47 must be present; if a DP diagnostic event is expected, OB82 must be present. Missing fault OBs cause CPU STOP on the first fault.

Common Beginner Faults and Their Causes

Symptom Likely root cause Fix
CPU in STOP, SF LED on, diagnostic buffer: "OB not found" Fault OB missing (OB82, OB85, OB121, etc.) Add the relevant fault OB to the project and download
FC returns correct value in OB1 but corrupts elsewhere Reused TEMP conflict / FC called with mismatched parameter Make all actual parameters correct; check call site interface
FB "forgets" STAT values after CPU cycle FB called with wrong instance DB, or IDB overwritten by direct access Verify CALL uses the IDB; never write directly to the IDB from outside
Online monitor shows gray (unknown) for all tags Project not downloaded, or online view connected to wrong CPU Download; verify PLC target address in PLC > Accessible Nodes
Symbolic addresses red after editing the symbol table Symbol deleted or renamed; references broken Run Edit > Check Block Consistency; correct symbols
CPU 318/CPU 31x-2 PN rejects the program with "Firmware V2.x required" Block uses an instruction only on V3.x firmware Match block features to CPU firmware; check the CPU order number suffix

Moving From STEP 7 V5.5 to TIA Portal

Most S7-300/400 programs written in V5.5 are migrated via TIA Portal > Project > Migrate a STEP 7 V5.x project. The FB/FC/OB/DB structure ports cleanly because the block architecture is preserved. Symbolic addresses port, but the S7-300 specific SFCs in the Standard Library are not all bundled with the TIA Portal installation by default — install the SIMATIC S7-300/S7-400 Blocks package additively.

For new S7-300 work in 2024+, V5.5 remains the only fully-supported path; S7-1500 work must use TIA Portal V16+ and cannot consume V5.5 projects without a migration step.

Documentation References

The two primary Siemens references to keep open during development:

Should a beginner start with STEP 7 V5.5 or TIA Portal for an S7-300 project?

Use STEP 7 V5.5. TIA Portal can migrate a V5.5 project, but the V5.5 SIMATIC Manager remains the only first-class authoring tool for S7-300/S7-400 and has the largest library of example FB/FC code. If the eventual target is an S7-1500, learn V5.5 first to internalize OB/FB/FC/DB, then move to TIA Portal; the block architecture transfers directly.

What is the difference between FB and FC in STEP 7 in one sentence?

An FB has a paired instance DB (IDB) that retains its STAT variables between calls; an FC has only IN/OUT/IN_OUT/TEMP and forgets everything the instant it returns. Pick FB for stateful logic (motor starters, latches, PID), FC for pure transformations (scaling, math, string formatting).

How do I make a single FB drive two pumps with separate run-time counters?

Call the FB twice in OB1 with two different instance DBs: CALL FB200, DB200 for pump 1 and CALL FB200, DB201 for pump 2. The same FB code runs against two separate STAT memory areas, so each pump's latched state and run-time hours are independent.

My CPU goes to STOP the first time a hardware interrupt fires — why?

The matching fault OB is missing from the project. Hardware interrupts require OB40 through OB47; diagnostic interrupts require OB82. A CPU without the relevant OB is configured to STOP on the first occurrence. Add the OB (even an empty one) to the Blocks folder, download, and the CPU will handle the event without stopping.

Can I write directly to an instance DB from outside the FB?

Technically yes, but it is a design error. Direct writes from OB1 or another FB to a STAT location inside an IDB will be silently overwritten on the next scan when the FB runs. Treat the IDB as a private member of the FB and expose only OUT parameters or a separate shared DB to the rest of the program.

Back to blog