Configuring PID Loops on S7-300 CPU 312: FB58 Memory & Tuning

David Krause13 min read
S7-300SiemensTechnical 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 Siemens SIMATIC S7-300 CPU 312 (MLFB 6ES7 312-1AD10-0AB0) is an entry-level compact CPU frequently deployed in small HVAC, building-services, and process-control retrofits. Engineers who try to implement multi-loop PID on this CPU encounter two distinct constraints that are not obvious from the catalog datasheet alone: (1) the 16 kB of integrated work memory limits the number of PID instances that can be resident simultaneously, and (2) the S7-300 family splits its PID blocks between the firmware (SFB 41/42/43, available only on CPU 314 and above) and the STEP 7 Standard Library (FB 41/42/43 and FB 58, which can be loaded onto any CPU with sufficient memory). This reference documents the correct block selection, memory budgeting, and self-tuning procedure for FB 58 (TCONT_CP) running on a CPU 312, using a five-zone air-conditioning application as the worked example.

Engineering note: Siemens does not market the CPU 312 as a "PID controller." The product is technically capable of executing closed-loop control blocks loaded from the Standard Library, but the work-memory headroom and the absence of firmware-resident SFB 41/42/43 mean practical loop counts are far lower than on a CPU 313, 314, or 315. Confirm feasibility with a memory-budget calculation before ordering hardware.

CPU 312 Hardware Identification

The catalog number 6ES7 312-1AD10-0AB0 identifies a CPU 312 with the following relevant characteristics for PID applications:

Parameter Value Relevance to PID
Work memory (integrated RAM) 16 kB Code + data for SFB/FB instances + IDBs
Load memory (MMC) 64 kB max (MMC required) Stores project; runtime execution still uses work memory
Bit instructions 0.2 µs Acceptable for OB35-based PID at 100 ms cycle
OB1 scan ~0.7 ms / 1 k instructions Defines maximum PID call rate
SFB 41/42/43 (firmware PID) Not available Must use FB 41/42/43 or FB 58 from library
Number of SFBs total (max) Limited; check CPU 31x manual Drives block-count limits for cyclic OB

Source: Siemens SIMATIC S7-300 CPU 31xC and CPU 31x operating instructions and the ST 70 catalog. Because the CPU 312 has only 16 kB of work memory, the entire PID program (block code + instance DBs + any analog scaling logic) must fit inside that envelope.

PID Block Library: SFB vs FB Selection

The STEP 7 Standard Library contains two parallel families of PID blocks. Choosing the wrong one is the single most common reason a CPU 312 PID program fails to build.

Block Type Function Where it lives CPU 312 usable?
SFB 41 / CONT_C System FB (firmware) Continuous PID CPU firmware No on CPU 312
SFB 42 / CONT_S System FB (firmware) Step controller with integral actuator CPU firmware No on CPU 312
SFB 43 / PULSEGEN System FB (firmware) Pulse generator for SFB 42 CPU firmware No on CPU 312
FB 41 / CONT_C Library FB Continuous PID (library copy) STEP 7 Standard Library Yes
FB 42 / CONT_S Library FB Step controller STEP 7 Standard Library Yes
FB 43 / PULSEGEN Library FB Pulse generator STEP 7 Standard Library Yes
FB 58 / TCONT_CP Library FB Temperature controller with self-tuner STEP 7 Standard Library / PID Control Yes (recommended for HVAC)
FB 59 / TCONT_S Library FB Temperature step controller STEP 7 Standard Library / PID Control Yes

The firmware-resident SFB 41/42/43 are integrated into the operating system of higher-tier CPUs only; the CPU 312 firmware does not expose them. Engineers who try to call SFB 41 from a CPU 312 program receive a "Block does not exist on CPU" or download error. The fix is to delete the SFB calls and replace them with the identically-numbered FB blocks copied from the Standard Library. The FB versions run from load memory and instance DBs the same way as SFBs but consume more work memory because the code is downloaded rather than firmware-resident.

Verification step: Open the STEP 7 program, right-click the program blocks container, and check whether the PID blocks are flagged "SFB" or "FB." Anything in the SFB column on a CPU 312 is a configuration error that must be corrected before commissioning.

Memory Budget Calculation

Memory sizing for PID on the CPU 312 uses the formula:

Work memory required ≈ (code footprint of FB × N) + (IDB size × N) + OB35 overhead + analog scaling + safety logic

Field-measured values for FB 41 (CONT_C) on the CPU 312:

Component Footprint per loop Notes
FB 41 code in work memory ≈ 1.5 kB Includes static data of the FB
IDB (instance data block) ≈ 0.4–0.6 kB Depends on number of configured parameters retained
Total per loop ≈ 2.0 kB Conservative working value
OB35 + cyclic scaffolding ≈ 1–2 kB Includes call wrapper and parameter wiring
Analog input scaling (FC 105 etc.) per channel ≈ 0.1 kB Multiply by active AI count

Applying the rule of thumb to a 16 kB work-memory budget:

N_max ≈ (16 kB − OB35/scaling overhead) / 2 kB per loop

With 4 kB reserved for OB35, alarm OB, and analog scaling, the practical ceiling is:

N_max ≈ (16 − 4) / 2 ≈ 6 loops

Siemens field guidance places the realistic production maximum at 4 to 5 PID loops in parallel on a CPU 312 once additional logic (alarms, bumpless transfer, manual stations, diagnostic blocks) is added. Exceeding the budget generates SF (system fault) errors at download or OB1 priority-class errors at runtime, depending on the memory region overflowed.

How to Verify on a Live Project

  1. Open the STEP 7 project, right-click the S7 program and select Object Properties.
  2. Open Resource > Memory in the online view to see live work-memory consumption.
  3. Build a dummy OB35 containing N copies of FB 41 with a single instance DB each.
  4. Download the project and read the "Used work memory" value.
  5. Increment N and re-download until the next call exceeds the budget; the last successful N is your hardware ceiling.

FB 58 TCONT_CP Architecture

FB 58 (TCONT_CP) is the temperature-specific PID block in the PID Control section of the STEP 7 Standard Library. It bundles a continuous PID core, a pulse generator for digital heating/cooling outputs, and a self-tuner that performs process identification followed by controller design during a startup phase. The block is the recommended choice for HVAC zone control, plastic-extrusion zones, and similar multi-loop thermal applications.

Parameter (input) Type Purpose
SP_NT REAL Effective setpoint (°C); raised above ambient during tuning
PV REAL Process value (scaled °C from analog input)
DEADB_W REAL Deadband width
GAIN REAL Proportional gain
TI TIME Integral time
TD TIME Derivative time
TUN_ON BOOL Activates the self-tuner permanently
TUN_ST BOOL Start impulse for the self-tuner (rising edge)
MAN_ON BOOL Manual mode enable
MAN REAL Manual manipulated variable
Parameter (output) Type Purpose
LMN REAL Continuous manipulated variable (analog output %)
LMN_P / LMN_I / LMN_D REAL P, I, D components of LMN (diagnostics)
PHASE INT Current phase of the self-tuner (0 = idle)
STATUS INT Status word; 0 indicates no fault and no active phase change
QLMN_H / QLMN_L BOOL Digital pulse outputs for heating / cooling

Auto-Tuning Procedure: TUN_ON and TUN_ST

The self-tuner in FB 58 is invoked by setting the input parameters TUN_ON = TRUE and then triggering a rising edge on TUN_ST. If the PHASE and STATUS outputs remain at zero, the most common root causes are: (a) the setpoint in SP_NT is not far enough above the current process value, (b) the process value is not updated inside the calling OB, or (c) FB 58 was copied into the project without its associated instance DB (the block requires DB 58 in the same program).

Step-by-Step Commissioning Sequence

  1. Copy FB 58 and the associated DB 58 from the STEP 7 example project into the user program; do not generate a new instance DB — use the one shipped with the FB.
  2. Wire the analog input (e.g. PT100 via SM 331) through FC 105 to FB 58 input PV.
  3. Set initial conservative PID values: GAIN = 1.0, TI = T#30s, TD = T#0s.
  4. Set TUN_ON = TRUE in the static logic.
  5. Set the new SP_NT to 10–15 °C above the measured ambient; do not trigger TUN_ST first, because the tuner checks the step size before it will start.
  6. Apply a single rising edge to TUN_ST from the HMI or a one-shot in the user program.
  7. Monitor PHASE; values 1–7 indicate active identification stages, value 0 + STATUS ≠ 0 indicates a fault (see diagnostic table below).
  8. When PHASE returns to 0 and STATUS = 0, FB 58 has written tuned values for GAIN, TI, and TD into the instance DB. Clear TUN_ON if no further re-tuning is desired.
Process requirement (SP_NT jump): The self-tuner uses a step-response identification method that requires an observable process reaction. If the setpoint step is too small, the controller cannot separate process dynamics from measurement noise and the tuner leaves PHASE and STATUS at zero. The required setpoint jump is typically 10–15 °C above the ambient for HVAC applications, scaled appropriately for other process units.

SP_NT Setpoint Jump Requirement

FB 58 needs a measurable excitation to identify the process. The SP_NT parameter is the effective setpoint seen by the closed loop; the setpoint step is the difference Δw = SP_NT − PV(t=0). Siemens guidance for the TCONT_CP family requires Δw to be large enough to drive the process out of its noise band within one sample interval of the calling OB (typically OB35 at 100 ms). For HVAC air zones, the practical minimum is 10–15 °C above ambient; for water-loop temperature control, 5–10 °C is usually sufficient.

Application Minimum Δw Recommended Δw
Air-zone (HVAC) heating 10 °C 15 °C
Water-loop supply 5 °C 10 °C
Furnace / oven 50 °C 100 °C (if safe to do so)
Extruder zone 20 °C 30 °C

The 10–15 °C value is application engineering practice, not a hard-coded FB 58 limit. The tuner simply requires that the resulting process-value deviation exceed the analog-input noise floor by at least 5× to achieve an identifiable step response. If the setpoint step is below this, FB 58 stays in PHASE = 0 with a non-zero STATUS indicating "insufficient excitation."

HVAC Zone Application: Five Air-Conditioning Zones

The reference application uses a CPU 312 to control five independent air-conditioning zones, each with a supply-air temperature sensor (PT100 or 0–10 V transmitter) and a modulating chilled-water valve (4–20 mA) driven by an SM 332 analog output. Memory and execution budgets for this configuration:

Resource Per-loop cost × 5 loops Total
FB 58 code (work memory) ≈ 1.6 kB × 5 8.0 kB
IDB 58 (per zone) ≈ 0.5 kB × 5 2.5 kB
OB35 cyclic wrapper ≈ 1.5 kB 1.5 kB
FC 105 analog scaling × 5 AI + 5 AO ≈ 0.2 kB × 10 2.0 kB
Alarm and diagnostic OBs ≈ 1.0 kB 1.0 kB
Total work memory ≈ 15.0 kB / 16 kB available

The five-zone configuration fits inside the 16 kB budget with less than 1 kB of headroom. Field practice is to drop the project onto the CPU early in the engineering phase, read the live work-memory usage, and confirm that the 5th loop does not push the project past the available memory. If the result is borderline, three options exist:

  1. Reduce the number of HMI-tag-visible parameters to keep IDB 58 smaller (use S7-300 "Only store in load memory" for non-diagnostic tags).
  2. Consolidate the OB35 wrapper into a single multi-instance call (saves ~0.5 kB).
  3. Upgrade to a CPU 313 (32 kB work memory) or CPU 314 (48–96 kB depending on variant), which removes the budget constraint.

Diagnostic Outputs: PHASE and STATUS

When PHASE = 0 and STATUS = 0 after a rising edge on TUN_ST, the self-tuner has not started. The most common root causes and their verification are:

Symptom Likely cause Verification Fix
PHASE=0, STATUS=0 indefinitely SP_NT step too small for ambient Watch SP_NT − PV in VAT; must exceed 10 °C for HVAC Increase SP_NT setpoint jump
PHASE=0, STATUS=0, PV frozen Analog input not refreshed Inspect raw AI word; verify FC 105 called in same OB Move FC 105 call before FB 58 in OB35
PHASE=0, STATUS=0, TUN_ON=FALSE TUN_ON not held TRUE Force TUN_ON in VAT Hold TUN_ON = TRUE in logic or HMI
PHASE=1, STATUS=0, no progress Process too slow to react within identification window Log PV over 5 minutes; verify rising trend Increase SP_NT step or shorten OB35 cycle time
STATUS ≠ 0 after PHASE returns to 0 Tuner completed with non-fatal warning Decode STATUS per FB 58 help Re-run with larger step; document per zone
SF LED on CPU Work memory overflow Online > Module Information > Memory Remove a PID loop or upgrade CPU

Alternatives for Larger PID Counts

If the application requires more than five PID loops, the CPU 312 is the wrong hardware. Evaluate the following alternatives, in order of increasing capability:

CPU Work memory Practical PID loop count (FB 58) Notes
CPU 312 (6ES7 312-1AD10-0AB0) 16 kB 4–5 Reference subject of this document
CPU 312C (compact) 32 kB 10–12 Integrated I/O, onboard PID possible
CPU 313 (6ES7 313-1AD03-0AB0) 32 kB 10–12 No firmware SFB 41/42/43
CPU 313C 32 kB 12–15 Compact version with I/O
CPU 314 (6ES7 314-1AE04-0AB0) 48 kB 20 First CPU with firmware SFB 41/42/43
CPU 314C 48 kB 22 Compact version with I/O
CPU 315-2 DP 64–128 kB 40+ Standard choice for medium PID plants

Loop counts above are derived from the same 2 kB per loop working figure, with 4 kB reserved for non-PID overhead. They are conservative; actual usable counts depend on instance DB configuration, HMI tag count, and any safety/messaging blocks. Always confirm with a live memory test before committing hardware.

Commissioning Checklist for FB 58 on CPU 312

  1. Verify CPU 312 MLFB is 6ES7 312-1AD10-0AB0 (or compatible variant) and MMC is inserted.
  2. Confirm FB 58 (not SFB 41/42/43) is being used; FB 58 and DB 58 are copied from the STEP 7 example program.
  3. Calculate memory budget; target 4–5 PID loops maximum; document remaining headroom.
  4. Wire AI → FC 105 → FB 58.PV in OB35 at 100 ms (or 200 ms if process is slow).
  5. Set conservative initial PID values and run in manual first to verify scaling direction.
  6. Switch to auto, raise SP_NT by 10–15 °C above measured PV, then apply rising edge to TUN_ST.
  7. Monitor PHASE and STATUS; verify tuner completes (returns to 0) within expected identification time.
  8. Record tuned GAIN, TI, TD in DB 58 and back up the project.
  9. Capture the online work-memory reading; archive in the project folder for future expansion planning.

FAQ

How many PID loops can a Siemens S7-300 CPU 312 run in parallel?

A CPU 312 with 16 kB of integrated work memory can realistically run 4–5 FB 58 (TCONT_CP) temperature loops in parallel once OB35, analog scaling (FC 105), and instance DBs are accounted for. Six is technically possible in the 16 kB budget, but leaves no headroom for alarm, diagnostic, or safety logic and is not recommended for production systems.

Can a CPU 312 use the firmware SFB 41/42/43 PID blocks?

No. SFB 41 (CONT_C), SFB 42 (CONT_S), and SFB 43 (PULSEGEN) are firmware-resident blocks available only on higher-tier S7-300 CPUs (CPU 314 and above). On a CPU 312 you must use the identically-named FB 41/42/43 or FB 58 (TCONT_CP) from the STEP 7 Standard Library. The FB versions consume more work memory because the code is downloaded to the MMC rather than executed from firmware.

Why does FB 58 PHASE and STATUS stay at 0 after triggering TUN_ST?

The three most common causes are: (1) the setpoint jump SP_NT − PV is too small (raise SP_NT 10–15 °C above ambient for HVAC), (2) the analog input is not being refreshed inside the calling OB, or (3) FB 58 was copied without its associated instance DB 58. Verify the step size with a VAT watch on SP_NT and PV, and confirm FC 105 is called before FB 58 in OB35.

What setpoint jump does FB 58 need to start the self-tuner?

FB 58 needs an observable step response, which for HVAC air zones translates to a setpoint of 10–15 °C above the measured ambient. For water-loop applications 5–10 °C is typically sufficient, and for furnaces/ovens 50–100 °C may be required. The exact minimum is determined by the requirement that the resulting process deviation exceed the analog-input noise floor by roughly 5×.

Should I upgrade the CPU if I need more than 5 PID loops?

Yes. A CPU 312 is at or beyond its memory budget at five FB 58 loops. The smallest practical step up is a CPU 313 or 312C (32 kB work memory), which supports 10–12 loops. A CPU 314 (48 kB) adds firmware-resident SFB 41/42/43 and supports ~20 loops. Always confirm the chosen CPU with a live memory test on the actual project before final hardware selection.

Back to blog