Configuring Dynamic WinCC Recipes for S7-300 PLCs

David Krause11 min read
SiemensTutorial / How-toWinCC
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: Why Dynamic Recipes in WinCC for S7-300

Recipe handling in SIMATIC WinCC is the standard mechanism for transferring batch data between the SCADA layer and the automation layer. In a fixed-sequence implementation, the PLC program contains hard-coded step logic, and the SCADA only delivers setpoint values. The dynamic recipe approach is different: the complete sequence definition (step list, transition conditions, ramp values, dwell times) lives in the WinCC recipe database and is downloaded to the S7-300 before each batch run.

This pattern is required when:

  • Product variants are introduced frequently and re-programming the PLC is not acceptable.
  • Operators must be able to edit the sequence without engaging the PLC engineer.
  • Validation and GMP environments require that the "master recipe" be stored in the SCADA/ERP layer.
  • The number of steps per product is variable (1 to N), and the PLC holds a generic executor.

The article builds the configuration end-to-end for an S7-300 CPU (e.g., 315-2 PN/DP, 317-2 PN/DP, 319-3 PN/DP) controlled by WinCC V7.x, with the TIA Portal / WinCC RT Professional path called out where relevant. The official Siemens entry point for recipe examples is the TIA Portal example: Creating recipes (RT Professional) and the historical WinCC V7 demo project at Siemens Support Entry 35102867.

System Architecture and Data Flow

WinCC Station Graphics Designer (HMI) Recipe Editor (up to N records) Access / SQL Recipe DB C / VBS Action Handlers S7-300 PLC Recipe Interface DB (e.g. DB500) Generic Step Executor (FB100) I/O / Field Process S7-Protocol (RFC1006/TCP) Ack / Status Operator / Engineering Recipe Authoring Versioning / Audit Trail Operator Selection Screen Batch Report Export

The recipe lives in the WinCC Recipe Editor and is persisted to a relational database (Microsoft Access for WinCC V7 base installations, Microsoft SQL Server for larger configurations or RT Professional). When the operator triggers "Download to PLC", WinCC writes the recipe data into a dedicated data block (DB) on the S7-300. The PLC then executes the steps using a generic executor block that interprets the data rather than relying on hard-coded logic.

Prerequisites and Software Requirements

Layer Component Minimum Version / Catalog Notes
Engineering STEP 7 V5.5 / V5.6 for S7-300 project authoring Or TIA Portal V16+ with S7-300 add-on
Engineering SIMATIC WinCC V7.0 SP2 ... V7.5 SP2 Article base version V7.0.2 Recipes introduced in V6.0, refined through V7.5
Engineering (alt) WinCC Professional / RT Professional TIA Portal V16 ... V20 See example
Runtime WinCC Runtime (RC/RT) RT 128 / 512 / 2048 / 4096 PowerTags License key sized to total tag count
Automation CPU 315-2 PN/DP (6ES7 315-2EH14-0AB0) or higher Firmware V3.3+ recommended CPU 317/319 also supported
Network Industrial Ethernet TCP/IP RFC1006 (port 102) Or Profinet, MPI for legacy cells
Storage Microsoft Access (Jet) or MS SQL Server Access 2010+ for V7.0.2 SQL required for RT Professional
Note: The "maximum 10 recipes" limit cited in the original requirement is not a hard product boundary. WinCC V7 will store as many recipe data records as the database allows; the practical limit is operator-screen usability and recipe DB file size (Access: 2 GB absolute cap). For > 200 active recipes, migrate to SQL Server.

PLC Data Block Structure for Recipes

The S7-300 needs a clearly defined interface DB. The example below uses DB500 as the recipe interface. All offsets are byte-based and align with what the WinCC Recipe Editor will target.

Offset Name Type WinCC Tag Description
0.0 Recipe_ID INT REC_ID 1..N recipe selector
2.0 Step_Count INT REC_STEPS Number of valid steps (1..50)
4.0 Download_Cmd BOOL REC_DL_CMD Rising edge triggers load
6.0 Download_Ack BOOL REC_DL_ACK Set by PLC when ready
8.0 Current_Step INT REC_CUR_STEP Active step index
10.0 Step_Array[0..49] STRUCT REC_STEP_xx 50 step records @ 16 bytes each
10.0 + 0 Step_Type BYTE — 0=Dwell, 1=Ramp, 2=Output, 3=Wait
10.0 + 1 Target_Value REAL — Setpoint for this step
10.0 + 5 Dwell_ms DINT — Hold time in ms
10.0 + 9 Output_Map WORD — Bitmask of digital outputs
10.0 + 11 Transition BYTE — 0=Time, 1=Ack, 2=Value reached
10.0 + 12 Reserved[4] ARRAY of BYTE — Pad to 16 bytes

Total DB size: 10 + 50 * 16 = 810 bytes. Keep the DB length above the last used byte.

WinCC Communication Channel Configuration

  1. Open the WinCC Explorer and add the SIMATIC S7 Protocol Suite channel if not already present.
  2. Right-click TCP/IP → New Driver Connection. Name it e.g. S7_300_Recipe.
  3. Set the connection parameters:
    IP Address = 192.168.0.10 (CPU PN interface)
    Rack = 0
    Slot = 2 (CPU 315-2 PN/DP)
  4. Test the connection using the channel diagnostics (right-click → Connection Status). Expected: green "Connected" indicator within 2 s.
  5. In the tag management, create the WinCC tags listed in the table above. Use Data Block addressing and set DB number = 500, Offset = 0, etc.
Note: The S7-300 supports the S7 communication with PUT/GET, so WinCC can act as both server and client. If the PLC is in a security-tightened configuration, enable Permit PUT/GET access by remote partner in STEP 7 under CPU Properties → Protection. This is not optional for recipe download initiated by WinCC.

Defining Recipes in WinCC Explorer

  1. In WinCC Explorer, open the Recipe Editor.
  2. Create a new recipe MASTER_RECIPE.
  3. Add the recipe elements matching the PLC structure. Each element name must be unique and is what the operator sees in the selection list.
  4. Set the storage path. The default in WinCC V7.0.2 is the project path; for a centralized database use a shared *.mdf on the WinCC server.
  5. Create the data records. Each record corresponds to one product variant. A field-proven rule is to limit step count to 50, because the PLC interface DB above is sized for 50.

The TIA Portal example for RT Professional shows the equivalent workflow in the newer toolchain, where the recipe elements are configured per HMI tag and the storage backend is always SQL Server.

Implementing Dynamic Auto-Sequences

Native WinCC V7 recipes do not have an "auto-sequence" entity; the dynamic behavior is built with scripts attached to the Recipe View control. The typical pattern uses the C or VBS action interface and the Recipe View's event "Status Change".

VBS example — Build the sequence dynamically before download

' WinCC V7 VBS action attached to "Download" button
Sub OnClick(ByVal Item)
    Dim rcs, rec, elem, val
    Set rcs = HMIRuntime.ActiveProject.RecipeSystem
    Set rec = rcs.Recipe("MASTER_RECIPE").DataRecord(RecipeListBox.Text)

    rec.Read

    ' Map PLC bits into step_1..step_N by pulling operator input
    Dim stepCount
    stepCount = CInt(OperatorInputStepsField.Text)
    rec.Element("Step_Count").Value = stepCount

    Dim i
    For i = 1 To stepCount
        ' Pull values from dynamic HMI fields generated by the operator panel
        rec.Element("Step_" & i & "_Type").Value  = _
            CInt(Me.GetSibling("S" & i & "_TYPE").OutputValue)
        rec.Element("Step_" & i & "_Value").Value = _
            CSng(Me.GetSibling("S" & i & "_VALUE").OutputValue)
        rec.Element("Step_" & i & "_Dwell").Value = _
            CLng(Me.GetSibling("S" & i & "_DWELL").OutputValue)
    Next

    rec.Write

    ' Trigger the PLC download command
    HMIRuntime.Tags("REC_DL_CMD").Write 1
    HMIRuntime.Tags("REC_DL_CMD").Write 0   ' pulse
End Sub

The C equivalent (ANSI C, WinCC Global Script) is faster for large step counts:

// C action, fired on "Status Change" of the Recipe View
#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName)
{
    CMN_ERROR err;
    int stepCount = GetTagWord(lpszPictureName, "OP_STEPS");
    SetTagWord(lpszPictureName, "REC_STEPS", (WORD)stepCount);
    for (int i = 1; i <= stepCount; ++i)
    {
        char tagType[32], tagVal[32], tagDwell[32];
        sprintf(tagType,  "S%d_TYPE",  i);
        sprintf(tagVal,   "S%d_VALUE", i);
        sprintf(tagDwell, "S%d_DWELL", i);
        SetTagByte(lpszPictureName, tagType,  GetTagByte(lpszPictureName, tagType));
        SetTagFloat(lpszPictureName, tagVal,  GetTagFloat(lpszPictureName, tagVal));
        SetTagDWord(lpszPictureName, tagDwell, GetTagDWord(lpszPictureName, tagDwell));
    }
    SetTagBit(lpszPictureName, "REC_DL_CMD", 1);
    SetTagBit(lpszPictureName, "REC_DL_CMD", 0);
}

PLC-Side Generic Step Executor (STEP 7 SCL)

The S7-300 program needs a generic block that interprets the downloaded steps. Below is an SCL sketch for FB100, called in OB1 with the recipe DB passed as INPUT.

FUNCTION_BLOCK FB100
VAR_INPUT
    RecipeDB : BLOCK_DB;       // DB500 expected
    StepCount : INT;           // From DB500.DBW2
END_VAR
VAR
    i : INT := 1;
    TimerInst : TON;
    StepType : BYTE;
    StepVal  : REAL;
    StepDwell: DINT;
    StepTran : BYTE;
END_VAR
BEGIN
    IF StepCount < 1 OR StepCount > 50 THEN RETURN; END_IF;

    // Read current step header at offset 10 + (cur-1)*16
    StepType := RecipeDB.DBB[10 + (i-1)*16 + 0];
    StepVal  := RecipeDB.DBD[10 + (i-1)*16 + 1];
    StepDwell:= RecipeDB.DBD[10 + (i-1)*16 + 5];
    StepTran := RecipeDB.DBB[10 + (i-1)*16 + 9];

    CASE StepType OF
        0: // Dwell
            TimerInst(IN := TRUE, PT := DINT_TO_TIME(StepDwell));
        1: // Ramp
            RampOutput := StepVal;   // analog output scaling handled elsewhere
        2: // Digital output bitmask
            DigitalOut := WORD_TO_INT(RecipeDB.DBW[10 + (i-1)*16 + 9]);
        3: // Wait for operator "Continue"
            ; // noop
    END_CASE;

    // Transition handling
    IF (StepTran = 0 AND TimerInst.Q) OR
       (StepTran = 1 AND OperatorContinue) OR
       (StepTran = 2 AND ABS(ProcessPV - StepVal) < 0.5) THEN
        i := i + 1;
        IF i > StepCount THEN i := 1; END_IF;
    END_IF;
END_FUNCTION_BLOCK
Warning: The SCL snippet above is for illustration of the dynamic pattern. Validate against your specific safety category (SIL), I/O scaling, and watch-dog timing before deployment. S7-300 cyclic OB1 with this FB must complete in < 50 ms on the targeted CPU.

Recipe Download Procedure

  1. Operator opens the Recipe View control on the HMI screen.
  2. Operator selects the data record (e.g., PRODUCT_42_REV03) from the list.
  3. Operator edits any step values via the dynamic input fields generated by the VBS action.
  4. Operator presses Save Record — WinCC persists the record to the Access/SQL database.
  5. Operator presses Download to PLC — the VBS action writes the elements to WinCC tags and pulses REC_DL_CMD.
  6. S7-300 FB100 latches the data into DB500, sets REC_DL_ACK after validation, and starts execution.
  7. WinCC receives REC_DL_ACK and displays a green status indicator in the recipe view.

Verification and Commissioning

# Check Method Pass Criterion
1 Channel connection WinCC channel diagnostics Status "Connected", no reconnects in last 5 min
2 Recipe DB writable Edit and save a record Access/SQL row timestamp updated
3 Element mapping Online → tag monitor on REC_ID... Values match operator input within 1 s
4 Download trigger Toggle REC_DL_CMD in PLCSIM or online REC_DL_ACK rises within 200 ms
5 Step executor Force a step and watch output Dwell/Ramp/Output behaves as configured
6 Round trip Read back from PLC → WinCC Values identical, bit-exact
7 Step limit Set step count = 50 No DB out-of-range, executor halts gracefully on invalid

Troubleshooting Matrix

Symptom Likely Root Cause Diagnostic Corrective Action
"Recipe data record cannot be opened" Access DB locked by another process Check *.ldb file presence Close the .mdb in MS Access, verify single-writer model
REC_DL_ACK never set PUT/GET access disabled in CPU STEP 7 → CPU Properties → Protection Enable "Permit access with PUT/GET from remote partner"
WinCC shows wrong values after download Byte-swap on REAL/INT in DB mapping Cross-check offset, type, length Recreate the tag with the correct length attribute (4 bytes for REAL)
Channel flapping every 30 s Wrong rack/slot or IP WinCC channel status log Verify Rack 0, Slot 2; ping the CPU PN port
VBS runtime error "Object required" Recipe name typo or no record selected HMIRuntime.Trace Validate the recipe name string and add a selection check
DB length too short error in STEP 7 Recipe DB not extended for 50 steps STEP 7 → DB500 → Properties Set length to 810 bytes or greater
Step values not refreshed WinCC not reading after write Tag diagnostics → last update time Call rec.Read after rec.Write in the VBS

Notes on Migration to TIA Portal / RT Professional

For new deployments targeting S7-1500 or for unified engineering, the equivalent setup is described in the RT Professional recipe example. The S7-300 connection remains valid in TIA Portal through the legacy S7-300 add-on, but recipe storage moves from Access to SQL Server and the script interface changes from VBS/C to the unified TIA Portal VBS / C / JavaScript action API. The PLC-side interface DB can be reused as-is, which limits migration effort.

How many recipes can WinCC V7 hold for an S7-300 cell?

WinCC V7 itself does not impose a fixed recipe record cap; the practical limit is the database. With Microsoft Access, expect a hard ceiling near 200 active data records before the .mdb file becomes cumbersome. Above that, migrate the recipe storage to Microsoft SQL Server, which is the only storage backend used in WinCC RT Professional from TIA Portal V16 onward.

Can the auto-sequence be defined entirely in WinCC without touching the PLC program?

Yes, provided the PLC holds a generic step executor (e.g., FB100 above) and the recipe data record carries the step list, setpoints, dwell times, and transition rules. New products are added by editing the recipe in WinCC; the PLC program is not recompiled. This is the standard pattern for batch processes in regulated industries.

Which communication driver should I use between WinCC and an S7-300 CPU?

Use the SIMATIC S7 Protocol Suite via TCP/IP (RFC1006 on port 102) for Ethernet-attached CPUs. For MPI or Profibus networks, the same suite provides dedicated channel units. Confirm in the CPU protection settings that PUT/GET access from a remote partner is permitted, otherwise the recipe download handshake will silently fail.

What is the difference between a fixed-sequence and a dynamic-sequence recipe?

A fixed-sequence recipe delivers only setpoint values; the PLC program determines the order of operations. A dynamic-sequence recipe delivers the step list, transition conditions, and timing parameters themselves, so the SCADA owns the master recipe and the PLC only executes a generic interpreter. Dynamic sequences are required when product variants exceed what is practical to hard-code in the PLC.

Where can I find a working WinCC V7 recipe sample project for S7-300?

Siemens publishes demo projects for SIMATIC WinCC V7 starting with SP2 on the Support entry 35102867. For TIA Portal / RT Professional, the equivalent sample is the "Creating recipes (RT Professional)" example in the TIA Portal documentation. Both projects include the PLC interface DB, the WinCC tag list, and a runnable screen layout that you can adapt to your cell.

Back to blog