Implementing Fuzzy Logic Controller on S7-300 STEP 7 STL

David Krause25 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

Fuzzy Logic Controller on S7-300: STEP 7 STL/LAD Implementation Reference

Implementing a fuzzy logic (FL) controller on a SIMATIC S7-300 PLC under STEP 7 V5.x without the discontinued SIMATIC S7 Fuzzy Control product (Siemens support entry 66639) is feasible using only standard STL, LAD, FBD, or CFC. This technical reference documents the engineering path: fuzzification with triangular and trapezoidal membership functions, rule-base inference (Mamdani and zero-order Sugeno), three defuzzification strategies (COG, MOM, COA), and a hybrid Fuzzy-PID pattern that combines linguistic rule knowledge with a linear PID core. The accompanying SIMATIC S7 Fuzzy Control manual (PDF attachment 1135654) remains the canonical reference for the inference architecture that must be re-implemented in plain STEP 7 code. Field context for the underlying theory is summarized in the Wikipedia entry on fuzzy control systems. A comparative implementation case study is "Fuzzy Controller based on PLC S7-1200: Application to a Servomotor" (IEEE Xplore), with a ResearchGate mirror. A plant-side perspective is recorded in the SiePortal thread on fuzzy logic controllers.

1. Fuzzy Logic Control on S7-300: Engineering Scope

Fuzzy logic control replaces the fixed gain structure of a PID with a rule base that maps linguistic input conditions to linguistic output actions. The controller takes crisp inputs (typically error e, change of error de, and optionally integral of error or measured disturbance), fuzzifies them through overlapping membership functions (MFs), evaluates a parallel rule set, and defuzzifies the aggregated output back to a crisp manipulated variable. On an S7-300, this loop must fit inside the OB1 cycle (or a faster OB35 cyclic interrupt at 100 ms default) and consume a deterministic slice of CPU time so that the controlled plant is not destabilized by inference jitter.

Three implementation tiers are practical for an S7-300/STEP 7 environment:

  1. Tier 1 - Original SIMATIC Fuzzy Control package: The discontinued product entry 66639 provided a CFC block library with a configuration tool. Sites with maintained licenses can still use it; sites without licenses must migrate to Tier 2 or Tier 3.
  2. Tier 2 - Standard-language re-implementation: STL, LAD, FBD, or SCL code in one or more FCs/FBs that emulates the same inference structure. No special license required. This is the focus of this article.
  3. Tier 3 - External inference with PLC as I/O: Run the fuzzy engine on a PC (MATLAB/Simulink, Python scikit-fuzzy, or a dedicated industrial PC) and exchange setpoint/control values with the S7-300 over OPC UA or S7 communication. Useful for prototyping or when the S7-300 cycle budget cannot absorb the inference cost.

2. When Fuzzy Outperforms PID: Application Selection

Fuzzy control is not a generic PID replacement. It is justified when one or more of the following hold:

  • The plant is highly nonlinear and a single set of PID gains cannot span the operating envelope (pH neutralization, batch temperature with exotherm, level control in a tapered tank).
  • Operator knowledge is qualitative ("if temperature is high and rising, cut steam hard") and that knowledge can be encoded as rules faster than it can be expressed as gain scheduling.
  • Setpoint trajectories cross multiple operating regimes and bumpless transfer between PID tunings is difficult to maintain.
  • Multiple interacting inputs (e.g., error, rate, acceleration, plus a measured disturbance) would push a PID toward a multi-degree-of-freedom structure that is harder to commission than an FL rule base of the same dimensionality.

Conversely, for a linear single-input/single-output plant with a constant operating point, a well-tuned PID with feed-forward is lower risk, lower scan time, and easier to validate. The engineering decision is application-specific; the FL-versus-PID trade-off is well covered in the fuzzy control system literature. The S7-1200 servomotor case study demonstrates one practical FL-only application, while the SiePortal thread records an experienced controls engineer's caution that a servomotor in particular demands rigorous closed-loop control and that naive FL can be worse than a tuned PID.

Engineering note: Encode the PID as the baseline. Add FL only where the PID demonstrably underperforms on the validated plant model. The hybrid Fuzzy-PID pattern in Section 9 gives a clean migration path.
FL vs PID decision matrix for a typical PLC deployment
Criterion Prefer PID Prefer FL or hybrid
Plant linearity Linear, time-invariant Nonlinear, multi-regime, sign-change in gain
Operator expertise available Quantitative (process engineer with model) Qualitative (operators with rule-of-thumb knowledge)
Number of measurable inputs to the controller 1 (SISO) or 1 + 1 disturbance 2 or more correlated inputs
Validation effort budget Standard step-response suite Multi-point matrix test
PLC scan budget ≤ 1 ms typical 5-20 ms typical for 49-rule Mamdani
Safety integrity level SIL 1-3 with proven PID Requires full FMEA; non-linearity complicates SIL assessment

3. SIMATIC Fuzzy Control Package: Status, Migration, and Prerequisites

Siemens offered a dedicated fuzzy control software product identified in the support database as product entry 66639. The product manual is archived as PDF attachment 1135654 (Fuzzy_e.pdf). The package integrated with STEP 7 V5.x and provided CFC function blocks for membership function definition, rule base editing, min-max (Mamdani) inference, and centroid defuzzification, with online monitoring of membership activations and rule firings.

The product is no longer commercially available as a new license, but legacy installations continue to use it. For new projects on S7-300, two paths are viable:

  1. Re-implement the same block architecture in STL/LAD/FBD using the manual as the design specification. This is the preferred path when cycle-time determinism matters.
  2. Move the inference to a PC-based engine and use the S7-300 as a fast I/O and PID layer. This is preferred when the rule base exceeds a few hundred rules or when the rule base changes frequently.
Hardware and software prerequisites for a STEP 7 re-implementation
Item Specification Notes
S7-300 CPU 314, 315, 315-2 PN/DP, 317, 319 CPU 312/313 typically insufficient work memory for rule bases > 50 rules. Confirm against your MLFB's work-memory data sheet.
Work memory ≥ 256 KB for the user program if the rule base is implemented in a single DB Size the rule DB at 12 + (N × 16) bytes minimum for a Sugeno rule base with REAL members; multiply by ~3 for Mamdani with output MFs.
Firmware CPU 3xx firmware compatible with STEP 7 V5.5 SPx (verify against your CPU's MLFB) STEP 7 V5.5 supports S7-300 CPUs down to firmware V2.x; the re-implementation does not require any specific firmware beyond the OB35 / OB1 cycle support.
STEP 7 V5.5 + SPx (last SP is the official maintenance pack for the V5.5 line) Optional add-ons: S7-SCL for compacting the rule base, S7-PLCSIM for off-target testing, S7-CFC for graphical layout.
Plant model MATLAB/Simulink with appropriate toolbox for the controlled process Used to pre-tune the FL off-line and to perform Hardware-in-the-Loop validation against the S7-300.
Communication PROFIBUS DP or Industrial Ethernet for HIL S7-PLCSIM can act as a soft-PLC for the first validation pass; the S7-300 is then connected against the Simulink model via OPC or the S7 protocol.
Safety note: This article documents a software reference implementation. The resulting controller must be validated against the target plant's safety integrity level (SIL per IEC 61511 or ISO 13849 for machinery) before deployment. Fuzzy controllers are non-linear and require a full FMEA, not just step-response validation.

4. Fuzzy Inference Architecture on an S7-300

The standard inference pipeline is:

  1. Fuzzification: convert crisp inputs e, de (and optionally d2e) to membership degrees in [0.0, 1.0].
  2. Rule evaluation: for each rule, combine the antecedent membership degrees (typically AND = min, OR = max) to obtain a rule firing strength αi.
  3. Implication: clamp the consequent membership function to αi (Mamdani) or scale a singleton value by αi (Sugeno).
  4. Aggregation: combine the outputs of all rules (union = max for Mamdani, weighted sum for Sugeno).
  5. Defuzzification: convert the aggregated fuzzy output to a crisp manipulated variable u.
Crisp inputse, de, d2e FuzzificationMF lookup Rule basemin / max Aggregationmax / sum Implicationmin / product DefuzzificationCOG / MOM Crisp outputu

On an S7-300, the entire pipeline must execute within the OB1 or OB35 cycle. For a CPU 315-2 PN/DP at default OB35 (100 ms), a 49-rule Mamdani controller with 7 MFs per input and 7 MFs per output typically consumes 8-15 ms of CPU time. Beyond ~200 rules or ~5 inputs, the cycle-budget pressure forces a move to a S7-400 or a PC-based engine. The actual cycle consumption is best measured on the target CPU using S7-PLCSIM with a recorded scan, or by inserting a runtime measurement in OB1 around the FC call.

5. Membership Function Implementation in STL

A triangular membership function with corners (a, 0), (b, 1), (c, 0) and a trapezoidal MF with corners (a, 0), (b, 1), (c, 1), (d, 0) are the workhorses of fuzzy PLC code. Both reduce to a small number of comparisons and multiplies.

5.1 Triangular MF (REAL inputs/outputs)

// FC100 - Triangular membership function
// Inputs:  IN  (REAL) - crisp input
//          A, B, C (REAL) - triangle corners (A <= B <= C)
// Output:  RET_VAL (REAL) - membership degree in [0.0, 1.0]
FUNCTION FC100 : REAL
VAR_INPUT
  IN : REAL;
  A  : REAL;
  B  : REAL;
  C  : REAL;
END_VAR
VAR_TEMP
  T : REAL;
END_VAR
BEGIN
  IF IN <= A OR IN >= C THEN
    FC100 := 0.0;
    RETURN;
  END_IF;
  IF IN <= B THEN
    T := (IN - A) / (B - A);
  ELSE
    T := (C - IN) / (C - B);
  END_IF;
  FC100 := T;
END_FUNCTION

5.2 Trapezoidal MF

// FC101 - Trapezoidal membership function
// Inputs:  IN, A, B, C, D (REAL) - A<=B<=C<=D
// Output:  RET_VAL (REAL) - membership degree
FUNCTION FC101 : REAL
VAR_INPUT
  IN : REAL;
  A  : REAL;
  B  : REAL;
  C  : REAL;
  D  : REAL;
END_VAR
BEGIN
  IF IN <= A OR IN >= D THEN
    FC101 := 0.0;
    RETURN;
  END_IF;
  IF IN >= B AND IN <= C THEN
    FC101 := 1.0;
    RETURN;
  END_IF;
  IF IN < B THEN
    FC101 := (IN - A) / (B - A);
  ELSE
    FC101 := (D - IN) / (D - C);
  END_IF;
END_FUNCTION

5.3 Singleton MF (Sugeno output)

A singleton MF returns 1.0 at the singleton point and 0.0 everywhere else. For a zero-order Sugeno output, the singleton value xi itself is the consequent; the rule firing strength αi scales the contribution directly, so a singleton MF does not need to be evaluated as a function - it is a constant stored in the rule record.

Default 7-term linguistic set (NL, NM, NS, ZE, PS, PM, PL) for an input normalized to [-1.0, +1.0]
Linguistic label Shape a b c d
NL (Negative Large) Trapezoid -2.0 -2.0 -1.0 -0.5
NM (Negative Medium) Triangle -1.0 -0.5 0.0 -
NS (Negative Small) Triangle -0.5 0.0 0.5 -
ZE (Zero) Triangle -0.25 0.0 0.25 -
PS (Positive Small) Triangle -0.5 0.0 0.5 -
PM (Positive Medium) Triangle 0.0 0.5 1.0 -
PL (Positive Large) Trapezoid 0.5 1.0 2.0 2.0

These corner values are a starting point only; tune them against the MATLAB/Simulink plant model and the desired closed-loop response. The triangular MFs sit on the linear segments; the trapezoidal MFs saturate the output at the input range bounds. The overlap between adjacent MFs should typically be 25-50% of the MF width; less overlap produces crisp but discontinuous inference, more overlap produces smooth but sluggish inference.

0 0.5 1.0 crisp input (normalized to [-2, +2]) membership degree NL NM NS ZE PS PM PL

6. Rule Base Encoding and Sugeno Inference Loops

Encode each rule as a record in a data block. For a 2-input / 1-output system with 49 rules (7 × 7), a Sugeno rule record holds the antecedent MF indices for each input and the singleton output value for the consequent.

// UDT10 - Sugeno rule record
TYPE UDT10
STRUCT
  AnteE     : INT;     // index of MF for error (0..6)
  AnteDE    : INT;     // index of MF for d(error)/dt (0..6)
  SingVal   : REAL;    // singleton output value
  Enabled   : BOOL;    // soft-disable flag for commissioning
END_STRUCT
END_TYPE

// DB100 - Sugeno rule base, 49 rules
DATA_BLOCK DB100
STRUCT
  Rule : ARRAY[1..49] OF UDT10;
END_STRUCT
BEGIN
  // (rule data initialised in the data view; not in source)
END_DATA_BLOCK

The inference loop iterates over the rule array, fetches the membership degree of the antecedent for each rule, combines them with the AND operator (minimum), and accumulates the weighted sum. For a zero-order Sugeno controller the crisp output is:

u = Σi=1..Ni · ci) / Σi=1..N αi

where ci is the singleton value of rule i and αi is the rule's firing strength. The denominator guard prevents a divide-by-zero in the degenerate case when no rule is active.

6.1 STL implementation of the Sugeno inference loop

// FC110 - Sugeno inference
// Inputs:  E, DE (REAL)
// Outputs: U (REAL)
FUNCTION FC110 : REAL
VAR_INPUT
  E   : REAL;
  DE  : REAL;
END_VAR
VAR_OUTPUT
  U   : REAL;
END_VAR
VAR_TEMP
  i        : DINT;
  AlphaE   : REAL;
  AlphaDE  : REAL;
  Alpha    : REAL;
  AlphaSum : REAL;
  WSum     : REAL;
END_VAR
BEGIN
  AlphaSum := 0.0;
  WSum     := 0.0;
  FOR i := 1 TO 49 DO
    IF NOT "DB100".Rule[i].Enabled THEN
      CONTINUE;
    END_IF;
    AlphaE  := FuzzTri( E,
                         "DB_CFG".E_MF["DB100".Rule[i].AnteE].A,
                         "DB_CFG".E_MF["DB100".Rule[i].AnteE].B,
                         "DB_CFG".E_MF["DB100".Rule[i].AnteE].C );
    AlphaDE := FuzzTri( DE,
                         "DB_CFG".DE_MF["DB100".Rule[i].AnteDE].A,
                         "DB_CFG".DE_MF["DB100".Rule[i].AnteDE].B,
                         "DB_CFG".DE_MF["DB100".Rule[i].AnteDE].C );
    IF AlphaE < AlphaDE THEN
      Alpha := AlphaE;
    ELSE
      Alpha := AlphaDE;
    END_IF;
    AlphaSum := AlphaSum + Alpha;
    WSum     := WSum + Alpha * "DB100".Rule[i].SingVal;
  END_FOR;
  IF AlphaSum > 0.0 THEN
    U := WSum / AlphaSum;
  ELSE
    U := 0.0;     // no rule fired: safe fallback
  END_IF;
  FC110 := U;
END_FUNCTION

This is a faithful STL translation of the inference pattern documented in the SIMATIC S7 Fuzzy Control manual. For CPU work-memory constrained sites, the rule array can be split across multiple DBs; the FOR loop bounds then change.

6.2 Rule base tuning procedure

  1. Initialise all 49 rule singletons to 0.0.
  2. For the diagonal rules (NM-NM, NS-NS, ZE-ZE, PS-PS, PM-PM), set the singleton to the corresponding output label value (e.g., NM singleton = -0.5 for a normalized output).
  3. Fill the off-diagonal rules with the average of the two diagonal outputs that share the same error or rate label, weighted by the row/column membership dominance.
  4. Run the step-response test in the Simulink model. Adjust the PL/NL singletons first to control the rise time, then adjust the PM/NM singletons to control the overshoot, then adjust the PS/NS singletons to control the steady-state error.
  5. Transfer the tuned rule base to the S7-300 DB and re-run the same test vectors against S7-PLCSIM. Compare the trajectory to the Simulink reference; the OB35 quantization error of 1 sample (≤ 100 ms) should be the only visible difference.

7. Defuzzification Strategies: COG, MOM, COA, Sugeno Weighted Average

For a Mamdani controller with output MFs, the aggregated output is a discrete sampled fuzzy set; the defuzzifier extracts a single representative value. Three common strategies differ in compute cost and behavior.

Strategy Formula Compute cost on S7-300 Behavior
Center of Gravity (COG) u = Σ (μ·x) / Σ μ High (must scan aggregated set) Smooth, conventional choice
Mean of Maximum (MOM) u = mean of x where μ = max(μ) Low Fast, may be discontinuous
Center of Area (COA) u = centroid of the area under μ(x) High Close to COG, slightly faster on triangular outputs
Weighted Average (Sugeno) u = Σ (α·c) / Σ α Low (closed form) Used in Sugeno; no MF scan required

7.1 STL skeleton for COG defuzzification

// FC120 - Center of Gravity over a sampled fuzzy set
// Input:  N - number of samples
//         pDom - pointer to domain array (x values)
//         pMu  - pointer to aggregated mu array
// Output: U (REAL)
FUNCTION FC120 : REAL
VAR_INPUT
  N    : INT;
  pDom : POINTER TO REAL;
  pMu  : POINTER TO REAL;
END_VAR
VAR_OUTPUT
  U : REAL;
END_VAR
VAR_TEMP
  i      : DINT;
  SumMu  : REAL;
  SumMuX : REAL;
END_VAR
BEGIN
  SumMu  := 0.0;
  SumMuX := 0.0;
  FOR i := 0 TO N - 1 DO
    SumMu  := SumMu + pMu^[i];
    SumMuX := SumMuX + pMu^[i] * pDom^[i];
  END_FOR;
  IF SumMu > 0.0 THEN
    U := SumMuX / SumMu;
  ELSE
    U := 0.0;
  END_IF;
  FC120 := U;
END_FUNCTION

The aggregation step that feeds this block is a per-sample max over all rule outputs. With 49 rules and 51 samples per output MF, the total work is ~2,500 max operations plus 51 multiplies and 102 adds - well within the OB35 budget on a CPU 315. For Mamdani controllers above 100 rules, consider switching to the Sugeno weighted-average formulation in Section 6 to drop the COG scan entirely.

8. LAD, FBD, CFC, and SCL Implementation Alternatives

STL is the most compact for inference code, but three patterns are sometimes required by site coding standards.

8.1 LAD-based fuzzification with comparator networks

Ladder does not have native MIN/MAX functions, but compare-coil networks (A>=, A<=, AN>=, AN<=) plus a multiply block can realize triangular MFs. Each MF consumes one comparator rung. The trade-off is FB length: a 7-MF input needs 7 rungs per input, two inputs need 14 rungs, plus a separate min-network for the AND of the antecedents. LAD is best restricted to the comparator and adder parts of the controller; the rule base should be moved into a parameter DB regardless of the language choice.

8.2 FBD as a graphical rule editor

FBD is well-suited to the rule base because each rule becomes a block with two MUL inputs (one per antecedent), one MIN gate (the AND), and one output to a MAX aggregator. The resulting diagram is essentially the rule base, executable as drawn. For sites that already use CFC for continuous control, this is the lowest-friction option. The FBD diagram scales to roughly 25-30 rules before the editor becomes unwieldy; beyond that, move the rule base to a parameter DB and keep the FBD as a single inference-block.

8.3 SCL for the heavy lifting

S7-SCL compiles to STL but expresses loops and IF-THEN-ELSE in Pascal-like syntax. The FC110 example above is a one-to-one SCL translation. The Fuzzification / Defuzzification block pair is best implemented in SCL; the rule base is then a parameter-only DB edited in the standard STEP 7 data view. SCL is the recommended language for sites that are new to the S7-300 platform and that have SCL licensed.

8.4 CFC for the highest level of abstraction

CFC compiles to STL but lets the engineer drop pre-built blocks on a sheet. For a fuzzy re-implementation, the practical CFC layout is:

  1. Sheet 1 - Fuzzification: one FuzzTri FC instance per input MF, output REALs to a connector bus.
  2. Sheet 2 - Rule base: one custom FB per rule with MIN inputs, MAX output to the aggregation bus.
  3. Sheet 3 - Aggregation / Defuzzification: a single block that does MAX over all rules then COG over the sampled set.
  4. Sheet 4 - I/O and cycle-time gating: read analog inputs, scale to engineering units, write the manipulated variable to the analog output, and call everything from OB35.

The CFC compiler manages the run-time order automatically; the engineer must verify (via the CFC "Run Sequence" menu) that the rule base sheet executes after the fuzzification sheet and before the defuzzification sheet within the same OB35 cycle.

9. Hybrid Fuzzy-PID Controller Pattern

The most defensible production deployment of FL on a PLC is as a supervisor over a PID core. The PID handles the linear regime; the FL overrides when the plant enters a non-linear regime or when the operator's rules encode a known safe behavior that the PID cannot reproduce.

Setpoint / PV PID coreFB41 Fuzzy supervisorFC110 Gain schedulerFC130 Selector / overrideFC140 u_manipulated (REAL, %MD)

Two supervisor modes are common:

  1. Gain scheduling: The fuzzy output scales the PID gains (Kp, Tn, Tv) per cycle. The PID is always in the loop; the FL acts as an adaptive tuner. This is the lowest-risk mode because the closed loop is provably linear at every operating point and the standard PID stability analysis applies within a neighborhood.
  2. Override / selector: The fuzzy output is an alternative manipulated variable that takes over when a rule fires strongly. The selector block (max, min, or weighted blend) chooses between PID and FL. Use a bumpless-transfer algorithm (track the FL output when the PID is in control, and vice versa) to avoid output steps on mode transitions.
Hybrid Fuzzy-PID signal flow
Block Function STEP 7 construct
PID core Standard PID with INT_HOLD input FB41 (CONT_C) or FB58 (CONT_S) for the S7-300
Fuzzy supervisor Computes gain correction or override signal FC110 + parameter DB100
Gain scheduler Applies Kp_factor, Tn_factor, Tv_factor to FB41 inputs FC130 - simple MUL blocks
Selector / override Weighted blend or MIN/MAX of PID and FL outputs FC140 - selectable mode
Bumpless transfer Tracks the unused controller output FC150 - one integrator per branch
Engineering note: When the FL overrides the PID, the anti-windup logic of the PID must be re-evaluated. A FL output that sits at a saturation limit for an extended period will force the integral term of an un-bumpless PID to wind up, causing a large overshoot when control returns. Drive the FB41 INT_HOLD input to 1 (integral hold) when the selector routes control to the FL branch, and back to 0 when control returns to the PID branch.

10. Commissioning with a MATLAB/Simulink Plant Model

Hardware-in-the-Loop (HIL) commissioning is the safest way to bring a fuzzy controller on an S7-300 into service. The plant is replaced by the Simulink model during the qualification phase, then swapped for the real process once the controller is verified.

  1. Build the plant model in Simulink using the first-principles or identified dynamics of the real process. Validate the model against historical step-response data from the real plant if available.
  2. Run the reference simulation first: with the FL on the PC, the same MATLAB model should produce a stable response to a step setpoint change, a load disturbance, and a setpoint ramp.
  3. Port the rule base and MF corners to the S7-300 DBs. Use the same corner values; do not retune in isolation.
  4. Connect S7-PLCSIM to the Simulink model over OPC UA (S7-PLCSIM exposes a server) and replay the same test vectors. The SiePortal discussion highlights the risk of running an FL on a real servo without rigorous closed-loop validation - the model is the validation tool.
  5. Compare trajectories: the S7-300 cycle jitter must not exceed 5% of the OB35 period. If it does, move the inference to a S7-400 or a CPU 319, or reduce the rule count.
  6. Connect the real S7-300 to the Simulink model over PROFIBUS or Industrial Ethernet with a soft-PROFIBUS or PROFINET interface on the PC side. Replay the same test vectors one more time to validate the I/O path.
  7. Cut over to the real plant in a controlled step: start with the controller in manual, switch to auto with the operator watching the trend, and step the setpoint through a safe range before applying the production setpoint profile.
Tip: Keep the Simulink model active as a "shadow plant" running in parallel with the real plant for the first 30 days of production. Any deviation between the shadow model and the real plant is a flag for either model drift (re-identify) or controller drift (re-tune the FL).

11. Performance Verification and Tuning

Three test vectors are minimum for a fuzzy controller on a process plant:

  1. Setpoint step: a 10% step in the setpoint with the plant at the mid-range operating point. Measure rise time, overshoot, settling time (2% band), and steady-state error.
  2. Load disturbance: a 10% step in the disturbance variable at the same operating point. Measure the peak deviation and the recovery time.
  3. Setpoint ramp through non-linear regime: a ramp from low to high operating point that crosses at least one non-linearity (e.g., a tapered tank, a saturation, a sign change in the process gain). Verify that the controller does not oscillate at the non-linearity.
Typical performance envelope for a well-tuned FL on a S7-300
Metric Acceptable Investigate if
Rise time (10-90%) < 60% of the dominant plant time constant > 100% (rule base too conservative)
Overshoot < 5% for setpoint, < 15% for disturbance > 20% (output MFs too aggressive in the high-error region)
Settling time (2%) < 3 × plant time constant > 5 × (rule base inconsistent, check for empty regions)
Steady-state error < 1% of setpoint span > 2% (output MFs do not include a zero-output singleton)
OB35 jitter < 5% of the OB35 period > 10% (reduce rule count, move to faster OB, or move to a higher CPU)

11.1 OB35 budget allocation

CPU time budget for a 49-rule Sugeno controller on a S7-300 at OB35 (100 ms)
Stage Typical time (CPU 315-2 PN/DP) Notes
Analog input read + scaling 1-2 ms PEW read + FC105 scale
Fuzzification (14 MFs) 1-3 ms FC100 / FC101 calls
Rule loop (49 rules) 3-6 ms Dominant cost; FuzzTri lookup per rule
Defuzzification (Sugeno) < 1 ms Closed-form weighted average
PID branch (FB41) and selector 1-2 ms Three-term PID with anti-windup
Analog output write + scaling 1-2 ms FC106 unscale + PAW write
Total 8-15 ms of 100 ms Headroom for OB1 traffic and interrupts

If the cycle consumption exceeds 50% of the OB35 period on a consistent basis, switch the inference to a higher-numbered OB (e.g., OB32 at 500 ms, or OB38 at 10 ms if the plant is fast) and validate that the OB priority assignment does not starve OB1 of the communication services.

12. Diagnostic Matrix and Common Faults

Symptom Likely cause Diagnostic step Remedy
Output stuck at 0.0 No rule fires (denominator = 0) Monitor AlphaSum online; expect > 0 for all reachable (e, de) pairs Add a "default" rule with a wide MF that always covers the working region
Output chatters between two values Two rules with non-overlapping output MFs both fire alternately Plot rule firings vs. error Re-shape the output MFs so the union of all consequents is a single connected region
Overshoot on every setpoint change Output MFs for high error drive the manipulated variable to a saturating value Inspect the corners of the PL output MF Cap the PL singleton to the plant's linear range
OB35 cycle time alarm Inference loop exceeds the OB35 period Use S7-PLCSIM or the CPU's diagnostic buffer to time the FC110 call Reduce rule count, simplify MFs, or move to a faster OB (OB32..OB38) or a higher CPU
Different behavior between PLCSIM and the real CPU REAL rounding or denormal handling Compare trace recordings at the same input vectors Guard against denormals in MF denominators; add a small epsilon
Plant oscillates at the natural frequency of the plant Rule base adds gain at the wrong phase Bode plot of the open loop with the FL inserted Reduce the de/dt input weighting, or add a de/dt = 0 zero MF row
Steady-state error remains after the setpoint step No rule with a zero singleton fires at the final (e, de) = (0, 0) Inspect the rule that covers (e = 0, de = 0) and check its singleton Force the ZE-ZE rule singleton to 0.0 and re-tune neighbors
Controller output saturates at full scale during normal operation PL / NL output MFs too broad, no shaping of the working region Plot the aggregated output over a representative input trajectory Narrow the PL / NL output MFs and add a "saturation safe" rule that limits u

The SIMATIC S7 Fuzzy Control manual provides a more extensive fault-tree; consult it as the second reference after this article. For cross-checking the S7-300 platform behaviour (OB priority, cycle-time measurement, FB41 anti-windup), consult the S7-300 CPU manual for the specific MLFB.

Versioning: The cycle-time guarantees above assume STEP 7 V5.5 with the latest hotfix on a CPU 315-2 PN/DP or higher. Sites on TIA Portal with a S7-300 compatible CPU (S7-300 is on the TIA Portal compatibility list up to a recent V18/V19 for most CPU 3xx models; verify the exact CPU MLFB against the TIA Portal device catalogue) should re-test, as the SCL compiler and STL mnemonics differ slightly between V5.5 and TIA Portal. S7-300 is end-of-life for new developments per the Siemens product lifecycle - the recommended migration path is to S7-1500 with TIA Portal, but the SCL patterns in this article translate one-to-one to the S7-1500 / SCL instruction set.

Can the original SIMATIC Fuzzy Control package still be licensed for an S7-300 project?

The product is shown as discontinued on the Siemens support page for entry 66639. New licenses are not generally available; sites with an active maintenance contract from the active period may still receive support, but a new deployment should re-implement the blocks in STL or SCL using the pattern in this article.

Which S7-300 CPU is the minimum for a 49-rule fuzzy controller?

A CPU 314 with 128 KB of work memory is sufficient for 49 rules with 7 output MFs, but a CPU 315-2 PN/DP is preferred for headroom. Below CPU 314, the work memory is too tight for both the program and the rule DB at the sizes documented in Section 3.

What is the fastest OB to run the fuzzy inference on an S7-300?

OB35 is the default 100 ms cyclic interrupt and is the conventional choice. Faster OBs (OB32 through OB38) are available down to 10 ms on most S7-300 CPUs, but the inference cost typically makes OB35 the right balance between loop bandwidth and cycle headroom. Confirm the OB priority and minimum period for your specific CPU in the device manual.

Should I use Mamdani or Sugeno for an S7-300 fuzzy controller?

Use Sugeno (zero-order) for production code on an S7-300 unless the plant literature specifically calls for linguistic interpretability of the consequents. The Sugeno weighted-average defuzzification is closed form and avoids the sampled-set scan that the Mamdani COG requires, reducing CPU time by roughly a factor of 5 to 10 for the same rule base size.

How do I validate the fuzzy controller against my MATLAB/Simulink plant model?

Run the S7-300 controller in S7-PLCSIM, connect PLCSIM to the Simulink model over OPC UA, replay the three test vectors (setpoint step, load disturbance, setpoint ramp), and compare the manipulated-variable and process-variable traces. The S7-300 trajectory should match the reference PC simulation within the OB35 quantization error of 1 sample (typically ≤ 100 ms).

Back to blog