How-to
Motorized valve ratio control: choosing FB41 or FB42
Short answer
Drive the valve with FB41 CONT_C when it takes a 4-20 mA positioner and FB42 CONT_S when open and close motor contacts run it. Scale all five flow words with FC105, compute the setpoint as Y times the sum of the four measured flows in m³/h, clamp it to the line capacity, and call the loop from a cyclic interrupt.

On this page
The block you call depends on the actuator, not on the process. When the wastewater valve takes a 4-20 mA or 0-10 V positioner, call FB41 CONT_C and write its output to an analog output channel. When the valve is motorized and driven by two OPEN and CLOSE contacts, call FB42 CONT_S instead: the motor's stroke is the integrator, so the block emits pulses to the contactors instead of a position value. The setpoint chain is identical either way — scale the five flow words with FC105, sum the four tank inflows, multiply by the HMI factor Y, clamp the result to the line's capacity — and on an S7-315 the whole job is five steps.
The build in five steps #
- Scale every flow transmitter with FC105 into REAL engineering units (m³/h), with BIPOLAR := FALSE on 0/4-20 mA channels.
- Sum the four inflow flows in floating point and multiply by Y.
- Clamp the product to the new line's physical capacity and screen the raw words for wirebreak.
- Call FB41 or FB42 from a cyclic interrupt such as OB35, with CYCLE equal to that interrupt's interval.
- Deliver the actuating signal: LMN or LMN_PER through FC106 into the analog output word, or QLMNUP and QLMNDN to the two contactors.
Pick the block from the actuator interface #
The ratio equation produces only a setpoint. A closed loop then drives the valve until the measured wastewater flow equals that setpoint; positioning the valve directly from the sum would be pure feedforward and would ignore supply pressure, valve characteristic and line resistance. Which block you copy out of the library is decided by one question: what does the actuator accept?
| FB41 CONT_C | FB42 CONT_S | |
|---|---|---|
| Actuator interface | positioner on 4-20 mA or 0-10 V | OPEN and CLOSE motor contacts |
| Block output | LMN in %, or LMN_PER as INT | QLMNUP / QLMNDN as BOOL pulses |
| Where integration happens | inside the block | in the valve motor's stroke |
| Timing entries | CYCLE | CYCLE, MTR_TM, PULSE_TM, BREAK_TM |
| Chatter and limit tools | LMN_HLM, LMN_LLM, DEADB_W | DEADB_W, BREAK_TM |
Both blocks ship in the STEP 7 Standard Library. In SIMATIC Manager open File > Open > Libraries > Standard Library > PID Control Blocks, copy the FB into your project's block folder, and the instance DB is created when you make the call.
Scale the five flow channels with FC105 #
Every transmitter word becomes engineering units before it enters the sum. Mixing raw INT words with different spans is the classic silent ratio error, so call FC105 once per channel — five calls in this job:
CALL "SCALE" // FC105
IN :=PIW256 // raw input word, example address
HI_LIM :=1.000000e+002 // 100.0 m3/h transmitter span
LO_LIM :=0.000000e+000
BIPOLAR :=FALSE // unipolar 4-20 mA
RET_VAL :=MW100
OUT :=DB10.DBD0 // FS1 as REAL, m3/h
- BIPOLAR := FALSE for 0-20 mA, 4-20 mA and 0-10 V channels; TRUE is only for the ±10 V and ±20 mA ranges.
- Configure the channel in HW Config as 4-20 mA when the transmitter is live-zero. The module then maps 4 mA to zero counts, so LO_LIM stays at the transmitter's zero and the software compensates nothing a second time.
- Evaluate RET_VAL on every call: a non-zero return means the input sat outside the nominal range and OUT was limited.
- A wirebreak or overrange shows 16#7FFF on the input word. Screen for it before the sum — one broken transmitter otherwise drives the setpoint to full scale.
The nominal count span behind this mapping, 0 to 27648 counts on a unipolar channel, is explained step by step in Why an S7-300 analog input reads 0 to 27648 counts.
Build and clamp the ratio setpoint #
L DB10.DBD 0 // FS1
L DB10.DBD 4 // FS2
+R
L DB10.DBD 8 // FS3
+R
L DB10.DBD12 // FS4
+R
T DB10.DBD16 // FS_TOTAL, m3/h
L DB10.DBD20 // Y from the HMI
*R
T DB10.DBD24 // SP_RAW, m3/h
L DB10.DBD24
L 3.000000e+001 // 30.0 m3/h, line capacity
>R
JCN ok
L 3.000000e+001
T DB10.DBD24 // clamped setpoint
ok: NOP 0
Four guards belong around that code:
- Limit Y in the PLC, not only at the panel. With Y operator-writable, an entry of 10.0 instead of 0.10 commands an unreachable setpoint and winds up the integrator. Example PLC limits: 0.0 to 1.0, with a tighter band of 0.05 to 0.50 at the HMI.
- Cut out at low total. When FS_TOTAL falls below about 10 % of the transmitter span — 10.0 m³/h on these 100.0 m³/h meters — force the setpoint to zero and close the valve; ratio control on noise just hunts the valve.
- Filter the sum with a first-order lag of 2 to 5 s before it becomes a setpoint, so flow noise does not pass straight into the loop.
- Rate-limit the setpoint while Y is being edited, so the valve ramps instead of stepping.
The same total-times-factor setpoint, applied to belt feeders rather than a valve, is programmed in How to program belt feeder ratio blending control on a PLC.
Call the loop from a cyclic interrupt #
Call the block you picked from a cyclic interrupt — OB35 in this example — so the sample time is deterministic, and set CYCLE equal to that interrupt's interval (T#100MS for a 100 ms OB35). The call pattern for both blocks, one instance DB per loop, is laid out in Call FB41 and FB42 PID loops in OB35 with one DB per bank.
FB41 CONT_C for a positioned valve #
CALL "CONT_C", DB41 // FB41 + instance DB
COM_RST :=M0.0 // pulse from OB100 clears the integral memory
MAN_ON :=DB10.DBX30.0 // TRUE = manual, LMN follows MAN
PVPER_ON :=FALSE // PV arrives as REAL on PV_IN
P_SEL :=TRUE
I_SEL :=TRUE
D_SEL :=FALSE // no derivative on a flow loop
CYCLE :=T#100MS // equals the OB35 interval
SP_INT :=DB10.DBD24 // ratio setpoint, m3/h
PV_IN :=DB10.DBD28 // FS_new from FC105, m3/h
MAN :=DB10.DBD32 // manual position, %
GAIN :=5.000000e-001 // example initial gain
TI :=T#10S
LMN_HLM :=1.000000e+002 // 100.0 %
LMN_LLM :=0.000000e+000
LMN :=DB10.DBD36 // output, %
LMN_PER :=MW110 // same output as INT counts
SP_INT and PV_IN must carry the same units — m³/h here — because the block normalizes both internally. The output clamp does double duty: at LMN_HLM or LMN_LLM the block freezes the integrator, which is what a seated valve needs. Write LMN_PER straight into the peripheral output word, or push the REAL LMN through FC106 when the valve span is not 0 to 100 %:
CALL "UNSCALE" // FC106
IN :=DB10.DBD36 // 0.0 .. 100.0 %
HI_LIM :=1.000000e+002
LO_LIM :=0.000000e+000
BIPOLAR :=FALSE
RET_VAL :=MW102
OUT :=PQW512 // counts out to the 4-20 mA positioner
The arithmetic that turns a REAL percent into output counts is worked through in Scale a PID real output to analog output counts.
FB42 CONT_S for a motorized valve #
With open/close contacts there is no position value to write: the actuator itself integrates, so FB42 switches pulse outputs instead.
CALL "CONT_S", DB42 // FB42 + instance DB
COM_RST :=M0.0
MAN_ON :=DB10.DBX30.0
CYCLE :=T#100MS
SP_INT :=DB10.DBD24 // same ratio setpoint, m3/h
PV_IN :=DB10.DBD28 // same measured flow, m3/h
GAIN :=5.000000e-001
TI :=T#10S
DEADB_W :=5.000000e-001 // 0.5 % of span, example
MTR_TM :=T#60S // nameplate full-stroke time, example
PULSE_TM :=T#200MS // above contactor pick-up, example
BREAK_TM :=T#1S // pause between opposing pulses, example
LMNR_HS :=I0.0 // OPEN end-limit switch, example address
LMNR_LS :=I0.1 // CLOSE end-limit switch, example address
QLMNUP :=Q0.0 // OPEN contactor
QLMNDN :=Q0.1 // CLOSE contactor
Set the timing entries from hardware, not from taste:
- MTR_TM: the nameplate running time for one full stroke, closed to open.
- PULSE_TM: above the contactor pick-up time, so every pulse actually latches.
- BREAK_TM: long enough that the motor never reverses against its own rotation.
- DEADB_W: the main tool against contactor chatter — no pulse is issued while the error sits inside the band.
LMNR_HS and LMNR_LS stop the pulsing at the seat. Do not mix the two schemes: FB41's analog LMN into a contactor coil does nothing, and FB42's pulses into a positioner input only rattle the valve between extremes.
Safety note: keep the end-limit switches and the motor overload protection hardwired in the contactor circuit. The block's limit-switch inputs supervise the software's idea of position; a welded contactor is a hardware problem no block call can stop.
Worked example from counts to valve command #
Assume the four inflow meters span 0.0 to 100.0 m³/h and the wastewater meter 0.0 to 30.0 m³/h, all 4-20 mA, so BIPOLAR := FALSE on all five FC105 calls. The FS_new channel reads 2304 counts, which FC105 maps linearly across its span: 2304 ÷ 27648 × 30.0 = 2.5 m³/h. The inflows read 18.0, 12.0, 15.0 and 5.0 m³/h, so FS_TOTAL = 18.0 + 12.0 + 15.0 + 5.0 = 50.0 m³/h. The operator has Y at 0.10, so SP_RAW = 50.0 × 0.10 = 5.0 m³/h, below the 30.0 m³/h clamp, and the setpoint stands at 5.0 m³/h. The instantaneous error is 5.0 - 2.5 = 2.5 m³/h.
FB41 branch: partway through recovery, LMN reads 40.0 %, so LMN_PER = 0.40 × 27648 = 11059 counts and the positioner receives 4 + (11059 ÷ 27648) × 16 mA = 10.4 mA. The integrator, TI at T#10S, keeps raising LMN until the measured flow reaches the setpoint and the error closes.
FB42 branch: the 2.5 m³/h error is 2.5 ÷ 30.0 = 8.3 % of the meter span, well above the 0.5 % deadband, so QLMNUP pulses OPEN. With MTR_TM at T#60S and PULSE_TM at T#200MS, each pulse advances the stroke 200 ms ÷ 60000 ms = 0.33 %, separated by BREAK_TM pauses of T#1S, until the measured flow reaches the setpoint and the pulses stop.
Decision for each case: the setpoint chain — scale, sum, multiply by Y, clamp — is identical, and the actuator interface alone picks the block. A valve that accepts a continuous command takes FB41 CONT_C with its output on an analog channel. A valve run by two OPEN/CLOSE contacts takes FB42 CONT_S with its pulses on two digital outputs.
Questions asked
What happens if BIPOLAR stays TRUE on a 4-20 mA flow channel?
FC105 reserves the lower half of its scale for the negative half of a differential signal, so a unipolar channel read with BIPOLAR := TRUE comes out wrong by half a span: 4 mA reports the midpoint, for example 15.0 m³/h on the 0.0 to 30.0 m³/h meter, and 20 mA reports full scale. Set BIPOLAR := FALSE so the counts map across the whole transmitter span.
What should MTR_TM be when the valve nameplate lists no stroke time?
Measure it. Run the valve from fully closed to fully open on a stopwatch and enter the time in TIME format, T#75S for a 75 second stroke for example. MTR_TM is how FB42 converts each output pulse into a position step, so re-measure it after any actuator, linkage or seating change; a wrong value makes the loop overtravel or creep without ever admitting it.
Why does my motorized valve hunt around the ratio setpoint?
The smallest step FB42 can make is one PULSE_TM run of the motor. With a 60 second stroke and 200 ms pulses that is about 0.33 % of travel, so a deadband smaller than that makes the controller chase its own granularity and the contactors chatter. Raise DEADB_W above the smallest achievable step and lengthen BREAK_TM until the hunting stops.
Can two wastewater valves share one ratio loop?
They can share the setpoint but not the loop. Compute the clamped setpoint once and feed it to two calls, each with its own instance DB, its own flow meter and its own valve; if the two lines differ in capacity, give each line its own factor and clamp. Never drive two calls from one instance DB, because the integral and status words would be overwritten twice per cycle.


