Resources for Codesys
Abbreviations:
LD = Ladder Diagram
FBD = Function Block Diagram
ST = Structured Text
CFC = Continuous Function Chart
SFC = Sequential Function Chart
FUN = Function
FB = Function Block
Videos
Video tutorials on Youtube.
The videos are in Norwegian.
Function blocks
The following function blocks (*.export files) can be imported into a Codesys project with the meny Project -> Import (in Codesys).
Measurement scaling
P is process value (e.g. celsius).
M is measurement signal value (e.g. milliampere).
(M1, P1) and (M2, P2) are two given measurement points.
P is calculated with the following linear formula:
P = a*M + b
where
a = (P2 - P1) / (M2 - M1)
b = P1 - a*M1
Measurement filter

y_mf is filtered measurement value.
y_m is nonfiltered (raw; noisy) measurement value.
tf [s] is filter time constant.
ts [s] is time step, or sampling interval.
y_mf is calculated with:
y_mf = (1 - a) * y_mf_prev + a * y_m
where a is the filter constant:
a = 1/Nf
where Nf is the filter length:
Nf = (tf/ts) + 1
At the first iteration, y_mf_prev is set equal to y_m, which makes the initial value of y_mf become equal to y_m.
Time delay
This function block implements a time delay, which can be used in e.g. a process simulator.

y_delayed is the time delayed signal.
y_nondelayed is the signal to be time delayed.
delay_array_init is the initial value of y_delayed, i.e. its value before the time delay has elapsed.
t_delay [s] is the time delay.
ts [s] is time step, or sampling interval.
Updated 30 Oct 2026 by Finn Aakre Haugen (finn@techteach.no).