Skip to content

A. IEC 61131-3 and hakkas ​

For readers who know the IEC 61131-3 languages: what corresponds to what, and what works differently. Section 2.8 has the short version.

A.1 The model ​

IEC 61131-3HakkasNotes
Configuration, resourceControllerOne engine per controller
Program (POU) in FBDProcessSeveral per controller, each started and stopped on its own
Task, cyclic or eventNo counterpartBlocks compute when an input changes (Section 2.2)
Execution order of networksThe order in which changes arriveNo order to set; feedback in Section 14.8
Function block instanceBlockNamed, unique within its process
Function block typeBlock typefamily/Name, Chapter 15
User-defined function blockComposite block typeBuilt from blocks, Chapter 7
Function (no state)A stateless block typemath/*, compare/*, logic/* and others
Connection in FBDConnectionOne source per input; an output feeds any number
Constant on an inputFixed valueChangeable while running
VAR_INPUT / VAR_OUTPUT of a programProcess portsBound to channels, or linked to other processes
%IX, %IW, %QX, %QW addressesChannels, slot1-ai[2]Reached only through bindings, Chapter 8
VAR_GLOBAL between programsLinks between process portsChapter 11
RETAIN, PERSISTENTNo counterpartEvery start is a cold start (Section 14.7)
Online changeEvery editApplied at once to the running process
Compile, downloadNo counterpartThe controller holds the process itself
Upload from the PLCDownload (Section 9.2)The file carries the bindings and composite types too
Structured Text, LD, IL, SFCNot availableProcesses are diagrams

A.2 Data types ​

IEC 61131-3Hakkas
BOOLbool
REAL, LREAL, INT, DINT, …number, a 64-bit floating-point value
STRINGstring
TIMEa number of milliseconds (process/Delay's milliseconds, process/PID's sample_ms); timing/Hours and its siblings convert from units
TIME_OF_DAY, DATEstrings in the calendar blocks' settings (06:00-18:00, 1-5)
Arrays, structures, enumerationsNone; a selector number for an enumeration (process/MultiplexIn)

Types convert where it makes sense: a bool on a number input is 0 or 1, and a number on a bool input is true when it is not 0.

A.3 Standard function blocks ​

IEC 61131-3Hakkas
ADD, SUB, MUL, DIV, MODmath/Add2 and Add4, math/Subtract, math/Mult2, math/Divide, math/Modulo (floored) or math/Remainder (truncating, as IEC's MOD)
MAX, MIN, LIMITmath/Max, math/Min, process/Limit
SEL, MUXprocess/SelectIn, process/MultiplexIn (counting from 1)
GT, GE, EQ, NE, LE, LTcompare/Greater, GreaterEqual, Equal, NotEqual, LessEqual, Less
AND, OR, XOR, NOTlogic/And, Or, Xor, Not (two inputs; cascade for more)
EXP, LNprocess/Exponential, process/Logarithmic, with a gain and a scale
TON, TOFprocess/Delay with mode 1 or 2; mode 0 delays both edges (Section 14.3)
TPprocess/Trigger with a process/Delay (Section 13.3)
SR, RSprocess/Trigger (edges); a latch of logic blocks (Section 14.2)
R_TRIG, F_TRIGRarely needed: only changes travel, and edge-driven blocks act on edges themselves
CTU, CTDNot built in
PID (vendor libraries)process/PID: parallel form, bumpless, anti-windup
Scaling (vendor libraries)process/Linear, process/Curve
Alarm handling (vendor libraries)process/Alarm
Real-time clock and schedulestiming/MinuteRange, DayOfWeek, … (Section 14.4)

A.4 Thinking in changes instead of cycles ​

Most of what is new comes from one difference: a PLC evaluates everything every cycle, and hakkas evaluates what a change reaches, when it arrives. That changes some habits:

  • No scan time to budget. A large process costs nothing while its inputs are still. A regulator's timing is its own sample_ms, not the task's.
  • No edge detection boilerplate. A value that changes travels once. A block that must act on a rising edge, such as Trigger, Alarm's acknowledge or the calendar blocks, does so itself.
  • Noise is filtered by the change threshold (0.05 by default), and by a process/Deadband where more is needed. A value that moves less does not travel.
  • Feedback runs to completion. A loop is not cut once per cycle: it runs until it settles (Section 14.8).
  • Start-up is a cold start. All blocks compute once and send their outputs. The sensors follow a moment later. Design for that (Section 14.7).
  • The editor is always online. There is no offline copy to keep in step, and every edit is live. Test against the emulator first (Section 9.1).