MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › How do you switch between multiple recipes using data blocks (DB)?
HomeModels
Table of contents

On this page

PLC & Programming (100 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

How do you switch between multiple recipes using data blocks (DB)?

Multi-product lines carry one parameter set per product (temperature, speed, durations, positions...), and recipe switching means "load the selected recipe into the working area; the equipment reads only the working area". A two-layer "recipe library + working area" data-block structure makes switching a copy operation and adding a recipe a data entry, not a code change. This article gives the structure and the deployment steps.

1. The two layers: recipe library and working area

LayerContentProperty
Recipe libraryAn array of N recipe structures: recipe 1~N, each holding the full parameter setRetentive storage, editable from the HMI
Working areaOne parameter structure: read-only to the running equipmentThe only place process logic references
Switching controlCurrent recipe number, switch request, switch statusEdge-triggered copy

The key discipline: process logic references the working area only, never the library directly. The moment the logic contains "recipe 2's temperature" hard-coded, the recipe mechanism is broken — every reference is "working.Temperature", and which recipe sits in the working area is the switching layer's business alone.

2. Structure definition: what one recipe looks like

Define the recipe as a structure/UDT: heating temperature, hold time, conveyor speed, press position, allowed deviation, product name (string)... roughly 20~50 parameters. The library is a structure array in a DB (Array[1..20] of UDT_Recipe). The array's virtue: switching copies by index, the HMI edits by index, and adding a recipe means filling another array slot — zero program change.

MemberTypeExample
NameString"ProductA-Blue"
Heating temperatureREAL / scaled integer180.0 °C
Hold timeInteger (s)30
Conveyor speedInteger (0.1 m/min)125 → 12.5 m/min
Press positionInteger (0.01 mm)12500 → 125.00 mm
ChecksumWordVerifies data integrity at load

3. The switching flow: edge-triggered, three steps

① Trigger: the HMI selects a recipe number and presses "switch"; the PLC takes the recipe number's change edge; ② verify: the number is in range and the recipe's checksum is correct (keeping corrupted library data from loading); ③ copy: BLKMOV/MOVE transfers Array[number] wholesale into the working area and sets "switch complete". Execute with the machine stopped or idle — switching while running is a different requirement (online changeover) that must wait for a "safe point" (end of a cycle); this article covers stopped switching.

Switch complete = number edge AND number in range AND checksum OK → copy Array[number] → working area

4. Retention and initialisation: data that survives outages

The recipe library must sit in a retentive area (DB retention attribute / holding D area) or an outage erases it. Three supports: ① factory default recipe: on first power-up (or when the library is detected invalid) load defaults and mark "default"; ② checksums: compute over the parameter area on save, verify at load — HMI-corrupted data is caught at the switch gate; ③ edit permissions: recipe pages tiered — operators select, process engineers edit.

5. Working with the HMI

ScreenFunctionPoints
Recipe selectionDropdown for the number + switch button + done/error feedbackDisable switching while running (or route to online changeover)
Recipe editorRead/write library parameters by number, with save and verifyRecompute the checksum on save
Current parametersRead-only view of the working areaAlways shows the parameters "in force"

The HMI binds the library array by index directly; the "current parameters" screen binds the working area, so the operator always sees what is actually in force and never wonders "I changed the recipe, why nothing happened".

6. Common errors

SymptomCauseFix
Recipes gone after an outageLibrary area not retentiveEnable retention / move to a holding area
Some parameters unchanged after switchingHard-coded in logic / copy length shortAudit references; align copy length with the structure
Corrupt data loaded, machine misbehavesNo checksumAdd checksums; refuse on failure
Machine stumbles when switching liveNo safe-point control on the switch timingStopped switching, or cycle-boundary online changeover
HMI edit has no effectNo re-switch (working area not refreshed)Switch again, or a "sync" button re-copies

7. Notes

A recipe system is "data and logic separated": logic reads the working area (stable), data lives in the library (editable), and switching is the single channel between them. Govern the channel (edge, verification, timing) and the recipe system becomes the live template of "new recipes without code changes"; leave the channel open (logic reading the library, random live copies) and it becomes a false-action generator.

8. References

DB structure/array and retention attributes follow the platform manuals (TIA, CODESYS, AutoShop); block-transfer behaviour follows the applied-instruction chapters; recipe governance and change records follow the corporate quality system; online changeover timing must preserve safety per GB 5226.1 / IEC 60204-1.

9. Cautions

⚠️ Three traps to avoid:
① One parameter hard-coded in the logic — the one that "never takes effect" after switching;
② Copying recipes mid-motion — parameters change half-action and mechanisms compound wrongly;
③ No checksum on the library — a mistyped HMI edit drives the machine.

Acceptance tests: power-off retention, 20 consecutive switches with identical results, and the corruption-interception test (hand-break one parameter's checksum — it must alarm).

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL