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-3 | Hakkas | Notes |
|---|---|---|
| Configuration, resource | Controller | One engine per controller |
| Program (POU) in FBD | Process | Several per controller, each started and stopped on its own |
| Task, cyclic or event | No counterpart | Blocks compute when an input changes (Section 2.2) |
| Execution order of networks | The order in which changes arrive | No order to set; feedback in Section 14.8 |
| Function block instance | Block | Named, unique within its process |
| Function block type | Block type | family/Name, Chapter 15 |
| User-defined function block | Composite block type | Built from blocks, Chapter 7 |
| Function (no state) | A stateless block type | math/*, compare/*, logic/* and others |
| Connection in FBD | Connection | One source per input; an output feeds any number |
| Constant on an input | Fixed value | Changeable while running |
VAR_INPUT / VAR_OUTPUT of a program | Process ports | Bound to channels, or linked to other processes |
%IX, %IW, %QX, %QW addresses | Channels, slot1-ai[2] | Reached only through bindings, Chapter 8 |
VAR_GLOBAL between programs | Links between process ports | Chapter 11 |
RETAIN, PERSISTENT | No counterpart | Every start is a cold start (Section 14.7) |
| Online change | Every edit | Applied at once to the running process |
| Compile, download | No counterpart | The controller holds the process itself |
| Upload from the PLC | Download (Section 9.2) | The file carries the bindings and composite types too |
| Structured Text, LD, IL, SFC | Not available | Processes are diagrams |
A.2 Data types
| IEC 61131-3 | Hakkas |
|---|---|
BOOL | bool |
REAL, LREAL, INT, DINT, … | number, a 64-bit floating-point value |
STRING | string |
TIME | a number of milliseconds (process/Delay's milliseconds, process/PID's sample_ms); timing/Hours and its siblings convert from units |
TIME_OF_DAY, DATE | strings in the calendar blocks' settings (06:00-18:00, 1-5) |
| Arrays, structures, enumerations | None; 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-3 | Hakkas |
|---|---|
ADD, SUB, MUL, DIV, MOD | math/Add2 and Add4, math/Subtract, math/Mult2, math/Divide, math/Modulo (floored) or math/Remainder (truncating, as IEC's MOD) |
MAX, MIN, LIMIT | math/Max, math/Min, process/Limit |
SEL, MUX | process/SelectIn, process/MultiplexIn (counting from 1) |
GT, GE, EQ, NE, LE, LT | compare/Greater, GreaterEqual, Equal, NotEqual, LessEqual, Less |
AND, OR, XOR, NOT | logic/And, Or, Xor, Not (two inputs; cascade for more) |
EXP, LN | process/Exponential, process/Logarithmic, with a gain and a scale |
TON, TOF | process/Delay with mode 1 or 2; mode 0 delays both edges (Section 14.3) |
TP | process/Trigger with a process/Delay (Section 13.3) |
SR, RS | process/Trigger (edges); a latch of logic blocks (Section 14.2) |
R_TRIG, F_TRIG | Rarely needed: only changes travel, and edge-driven blocks act on edges themselves |
CTU, CTD | Not 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 schedules | timing/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/Deadbandwhere 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).