How-to
Call FB41 and FB42 PID loops in OB35 with one DB per bank
Short answer
Call FB41 (continuous PID) or FB42 (step controller) once per loop from a cyclic interrupt OB such as OB35 at its default 100 ms, and set the block's CYCLE input to exactly that interval. Give every direct call its own instance DB, or wrap the calls in a parent FB with FB41 multi-instances so one DB carries a bank of loops.
On this page
FB41 and FB42 are the loadable PID controllers of the STEP 7 Standard Library for S7-300 and S7-400 programs, and a call that controls well comes down to three decisions: run each loop from a cyclic interrupt OB, with OB35 as the conventional home; set the block's CYCLE input to exactly the OB's configured interval; and attach one instance DB per call, or wrap the calls in a parent FB so a single DB carries a whole bank of loops. Calling either block from OB1 is the classic mistake: the OB1 cycle time wanders with program length, the algorithm loses its time base, and tuning stops meaning anything. The steps below cover the single-loop call, the parent-FB bank pattern, and the sizing arithmetic that decides between them.
Pick the block and the interrupt #
FB41 (CONT_C) is the continuous controller: one REAL output, LMN, meant for an analog final element such as a valve positioner, a damper drive or an analog setpoint on a drive. FB42 (CONT_S) is the step controller: a pair of binary outputs, LMN_UP and LMN_DN, that pulse a motorized actuator up and down where no analog positioner exists. The trade between one continuous output and a pulse pair on a motorized actuator is worked through for gas burner duty in an FB41-versus-FB42 comparison for burner applications. For a complete loop already wired that way, the S7-300 example driving a modulating burner motor shows the wiring and the tuning end to end.
Both blocks take a TIME input named CYCLE and expect a constant call rate. The S7-300 and S7-400 operating systems provide nine cyclic interrupt OBs, OB30 through OB38, started at equidistant intervals you set in the CPU properties in HW Config. OB35 is the conventional PID home, and its default interval suits most temperature, level and flow loops; move to another of the nine only when OB35 already carries timed work.
The Standard Library also includes integrated SFB twins of the same controllers; this page uses the loadable FBs. When a fault-tolerant S7-400H project comes up without SFB41 in the block catalog, the replacement engineers apply is the loadable FB41 CONT_C, as a guide to swapping SFB41 for FB41 CONT_C walks through.
Call a single loop from OB35 #
- In SIMATIC Manager, open the program's Blocks folder and insert a new Organization Block, OB35. Move to another cyclic OB only if OB35 already carries timed work.
- In HW Config, open the CPU properties and find the cyclic-interrupt settings: OB35's default time is 100 ms. Keep it or set it deliberately, and note the value, because CYCLE must equal it.
- Open OB35 in LAD or STL and add a network.
- Drag FB41 (CONT_C) from the Standard Library's PID Control Blocks folder into the network. The editor asks for an instance DB: assign an unused number, DB100 as an example, and let the editor generate the DB with FB41's full interface.
- Wire the inputs. SP_INT takes the setpoint and PV_IN the process variable, both REAL in one consistent range, percent being common; scale a raw analog word with the Standard Library's FC105 before it reaches PV_IN. MAN carries the operator's manual value, GAIN, TI and TD carry the tuning with GAIN 1.0 and TD 0.0 as neutral seeds, and LMN_HLM and LMN_LLM clamp the output at 100.0 and 0.0 for a full-range element. Set CYCLE to the OB's interval, T#100ms when OB35 keeps its default.
- Take LMN to the analog output through the Standard Library's FC106 UNSCALE, which converts the percent REAL into the integer the peripheral word wants, PAW 304 as an example address.
- Compile, download the OB, the FB and the instance DB, and return the CPU to RUN.
- Commission in manual first: stroke the final element through MAN, confirm it travels the right way and stops at both limits, and only then switch to automatic. A reversed actuator or a sign error in GAIN drives equipment to a stop at full speed.
Match CYCLE to the OB interval #
Every time-based component in the block, the integrator's accumulation and the derivative's rate alike, is scaled by the CYCLE you hand it. The mismatch arithmetic is unforgiving in both directions: a CYCLE of 1 s on a block that actually runs ten times per second makes the integrator add ten times as much per second as the tuning intends, so a TI of 20 s behaves like 2 s and the loop overshoots; CYCLE set shorter than the real interval slows the action by the same factor.
Keep the OB lean, the loop calls and their immediate scaling and nothing else, because an overrun or a higher-priority interrupt that delays the OB stretches the effective sample time past CYCLE and the same error appears. OB1 offers no fixed time at all, since its duration is whatever the whole program takes in a pass; the walkthrough of what the PLC scan cycle does in each pass breaks that down.
The same commitment exists on other platforms under other names: running Logix 5000 PID loops in a periodic task gives those controllers the fixed rate that a cyclic OB gives FB41.
Build a parent FB so one DB holds a bank #
For more than a handful of loops, declare the FB41 instances inside a parent FB as static multi-instances and call them in order. One instance DB per parent call then carries the entire bank, eight loops per DB instead of eight separate DBs.
- Create the parent FB in the Blocks folder, FB200 as an example number.
- In its declaration table, declare one static variable of type FB41 per loop in the bank, LOOP_1 through LOOP_8 for a bank of eight.
- In the body, give each declared instance its own call, wiring SP_INT, PV_IN, MAN and LMN to the parent's IN/OUT pins and giving every call the same CYCLE.
- Call the parent once from the same cyclic OB that would have carried the individual calls, and attach one instance DB to that call.
FUNCTION_BLOCK FB200 // example parent: a bank of 8 PID loops
VAR
LOOP_1 : FB41; // multi-instance 1
LOOP_2 : FB41;
LOOP_3 : FB41;
LOOP_4 : FB41;
LOOP_5 : FB41;
LOOP_6 : FB41;
LOOP_7 : FB41;
LOOP_8 : FB41;
END_VAR
BEGIN
// one call per instance; each wires SP_INT, PV_IN, MAN and LMN
// to the parent's pins, all sharing the same CYCLE constant
END_VAR
Anything not wired to the parent's pins has to be reached by qualified name, BANK_1_DB.LOOP_1.GAIN with BANK_1_DB as the parent's instance DB by way of example, and that format spreads through a program fast. Wire the pins instead.
The parent obeys the same rate rule as a direct call: it belongs in the cyclic OB, not OB1. Multi-instance changes where the loop data lives, never the rate at which the algorithm runs.
Size the OB and count the DBs #
Two numbers decide the loop count: the OB interval you configured, and one FB41 call's execution time, which the CPU's online diagnostics report per OB. Capacity is the first divided by the second.
Worked example, with example inputs, so measure your own CPU before trusting the result. Suppose OB35 fires every 100 ms and the diagnostics show one FB41 call at an example 0.8 ms. A full interval allows 100 / 0.8 = 125 calls; budget half the interval for the loops and half for the rest of OB35's work and the planning figure is 50 / 0.8 = 62, call it 60 loops. At commissioning, watch the reported maximum execution time for OB35: it must stay inside the interval with room to spare, because one late pass stretches every loop's sample time.
Instance data does not shrink with multi-instances, since every FB41 instance exists once however it is packaged. Read the compiled instance DB's length in SIMATIC Manager and multiply: at an example length of 600 bytes, 60 loops hold 60 × 600 = 36,000 bytes of instance data either way. What changes is the count: 60 DBs when every call carries its own, 60 / 8 = 7.5, so 8 bank DBs when the loops ride in a parent.
The decision for each case #
- Up to 16 loops: call FB41 or FB42 directly in the cyclic OB, one instance DB per call. The line is manageability, not a hardware limit: below it, every loop is browsable online under its own DB number and the block list stays legible.
- More than 16 loops: build the parent FB with banks of eight FB41 multi-instances and give each bank one DB. A 60-loop project then costs 8 bank DBs instead of 60 separate ones, downloads and backups go bank by bank, and every value the operator touches sits on a parent pin.
- On every loop, in every bank: CYCLE equals the OB's configured interval, and the two change together in the same download.
- When the project later moves to an S7-1500, the Standard PID Control family travels its own migration path; the walkthrough of a PID_CP block migration to an S7-1500 shows the shape of it.
Questions asked
What is the difference between FB41 and SFB41 on these CPUs?
SFB41 and SFB42 are the same PID controllers integrated in the operating system of the CPUs that carry them. FB41, FB42 and FB43 are loadable blocks from the STEP 7 Standard Library that run as ordinary user code in every S7-300 and S7-400 CPU. Where both exist they behave alike; the loadable set is the portable choice because it never depends on what the firmware integrates.
What happens if I change the OB interval and forget CYCLE?
Nothing fails at once, which is what makes this one dangerous: the loops keep running on the wrong time base. Integral action moves at the ratio between the stored CYCLE and the new interval: halve the interval without touching CYCLE and every loop integrates twice as fast, double it and the loops slow by half. Drift that appears right after a download of new hardware settings is usually this.
How do I see whether the cyclic OB is keeping up?
Go online and open the CPU's module information, which lists every OB with its current, minimum and maximum execution time. The maximum is the number that matters: it must stay below the configured interval with room to spare, because one late pass stretches the sample time of every PID call inside that OB. If the maximum creeps toward the interval, move loops to another cyclic OB or slow the OB down.
Can a loop read the measured cycle time instead of a fixed CYCLE?
In a cyclic interrupt OB you know the interval from the hardware configuration, so a constant CYCLE is exact and is the right choice. The measured value belongs to calls made from OB1, where the start information carries the previous cycle's duration as a system time that must be converted before it can serve as a scan time. Keep the loop in the cyclic OB and the constant wins.
Does the parent-FB pattern work for FB42 step controllers too?
Yes. Declare the bank's static variables as FB42 instead of FB41 and call them the same way from the same cyclic OB; the two pulse outputs become boolean pins on the parent and CYCLE follows the identical rule. Mixing is also fine, some banks continuous and some step, as long as every call still runs inside the one cyclic interrupt OB.