Functions, Function Blocks, and Reading Checklist¶
Functions And Function Blocks¶
Use an FC when the logic has no memory of its own. Typical examples are calculations and value
conversions.
FUNCTION "FC_ClampReal" : Real
VAR_INPUT
reValue : Real;
reMinimum : Real;
reMaximum : Real;
END_VAR
BEGIN
IF reValue < reMinimum THEN
"FC_ClampReal" := reMinimum;
ELSIF reValue > reMaximum THEN
"FC_ClampReal" := reMaximum;
ELSE
"FC_ClampReal" := reValue;
END_IF;
END_FUNCTION
Use an FB when the logic needs memory: timers, filters, latches, previous values, counters, or
state machines.
Practical Reading Pattern¶
When you open an unfamiliar SCL block, scan it in this order:
- Read the block name and description header.
- Read
VAR_INPUTandVAR_OUTPUTto understand the contract. - Look for static
VARstate: timers, latches, counters, state values. - Read the
REGIONnames. - Find output assignments and state transitions.
- Check reset and fallback paths.
This is usually faster than reading top to bottom from the first line.
Beginner Checklist¶
Before committing a new or changed SCL block:
- Every Boolean marker has an obvious reset strategy.
- Timers are declared once, called once, and their
.Qresult is stored if used in several places. REALvalues use tolerances instead of exact zero comparisons.- Arrays and loop results are initialized before the loop.
- State-machine transitions are explicit and include a fallback state.
- Outputs have deterministic assignments in every relevant mode.
- Names follow the PCS coding style and include units where units matter.
Next Topics¶
This guide covers the basics. The next handbook page should collect real project lessons learned: timer call order, reset priority, alarm latching, startup behavior, HMI command handshakes, simulation hooks, and review checklists for common PLC programming mistakes.