MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › What is the difference between a function block (FB) and a function call (FC)?
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)(每月更新中)

What is the difference between a function block (FB) and a function call (FC)?

The core difference between an FB (Function Block) and an FC (Function) is one sentence: an FB carries its own memory (instance data); an FC has no memory (it computes and leaves). Choosing wrongly is not a style issue — control logic with state written into an FC tramples itself across calls; pure computation written into an FB sprays instances everywhere. The sections below compare structure, behaviour and selection.

1. Structure and behaviour compared

AspectFB (function block)FC (function)
Instance dataYes: each call binds one instance (DB/instance area); state persists across scansNone: no memory; temporaries rebuilt every call
Multiple callsInstances independent, no interferenceSame input, same output (the design goal)
Internal timers/edgesFine — state lives in the instanceRisky: timers/edges need externally supplied state or instances trample each other
ReturningWrites instance output variables, multiple outputs fineOne return value, or writes a designated output area
Typical dutyMotor, valve, axis control — every "equipment object"Scaling, comparing, checksums — every "pure calculation"

Why memory matters: a motor's start/stop logic must remember "am I running or stopped?" — that "now" lives in the instance, and two motors means two instances, each remembering its own. Scaling 0~10 V to engineering units needs no memory — input decides output, and an FC is the perfect home.

2. The FB instance mechanism: one logic, N machines

Write the FB once and create N instances at the calls: a pump-control FB with three instances serves three pumps — same interface, isolated state. That is the FB's core value: logic reuse through instance isolation. Two traps: ① timers and edge detectors inside the FB must use instance-owned resources (TIA's IEC timer instances / multi-instance capability) — three pumps sharing one global timer is chaos; ② instance-data retention is set per need (run-hours retained, current state not).

3. The FC discipline: be a pure function

An FC has no memory, so hold it to the pure-function standard: read only its input parameters, write only its return/designated outputs, touch no global variables, no timing/edges/accumulation inside. A pure FC is safe to call anywhere — loops, multiple sites, across tasks — because it depends on and changes no history. An FC quietly writing globals is the breach that breaks everything: call order changes the result and nothing explains it.

4. The selection decision table

QuestionAnswer decides
Does the logic need to remember last time?Yes → FB; no → FC
Does one logic serve several objects?Yes → FB with instances; no → next row
Is it pure computation (same in, same out)?Yes → FC; stateful → FB
Internal timers/edges/accumulators needed?Yes → FB (instance resources); no → FC

The quick rhyme: "equipment gets an FB, formulas get an FC". For mixed needs like "scaling with a filter inside", split into two layers: a filter FB (stateful) + a scaling FC (pure) — never smuggle state into an FC pretending it has none.

5. Common errors

SymptomCauseFix
Two pumps interfere with each otherControl logic as an FC with global stateRebuild as an FB with instances
FC result varies with call orderThe FC writes global variablesMake it pure; move state outside
FB timers pollute each otherInstances share a global timer numberTimers as instance resources
"No instance" error calling an FBCall without a bound instanceBind the instance DB per the platform
Pure maths hoarding instancesShould-have-been FC written as FBRefactor to FC

6. Naming and organisation

① FB names carry object semantics (FB_Motor, FB_Valve, FB_Axis), FC names carry action semantics (FC_Scale, FC_CheckSum); ② the interface area (in/out/in-out) doubles as the object's attributes in an FB — fix it in the team template; ③ library FBs/FCs live in the company's standard library project, referenced unchanged; changes go through a library version upgrade; ④ every FB's header comment states purpose, usage limits and version.

7. Notes

The FB/FC split is the stateful/stateless divide: equipment is a persisting object whose state belongs to it — FB instances carry it; calculation is a momentary transform indifferent to history — FC carries it. Ask two questions — "does it remember?" and "will it be reused for several objects?" — and the choice makes itself.

8. References

FB/FC definitions (POU types, instance mechanism) follow IEC 61131-3; creation and calling syntax follow the platform manuals (TIA, CODESYS, TwinCAT, AutoShop); instance-data retention follows each platform's storage documentation.

9. Cautions

⚠️ Three traps to avoid:
① Control logic as an FC with global state — multi-object calls trample each other;
② FB instances sharing a global timer — instance timers pollute each other;
③ An FC "casually" writing globals — results drift with call order.

At review, ask two questions of every POU: "does it keep state?" and "is it reused?" — when the answers match FB/FC, the structure is right.

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