|
Resources for Codesys
Videos Video tutorials on Youtube (in Norwegian). Function blocks The following function blocks (*.export files) can be imported into a Codesys project with the meny Project -> Import (in Codesys). The function blocks are generated in CODESYS V3.5 SP21 Patch 4. Measurement signal scaling
Inputs:
Output:
Function: p is calculated with the following linear formula: p := (a * m) + b; where a := (p_max - p_min) / (m_max - m_min); b :=
p_min - (a * m_min); Control signal scaling
Inputs:
Output:
Function: u_act is calculated with the following linear formula: u_act := (a * u_con) + b; where a := (u_act_max - u_act_max) / (u_con_max - u_con_min); b := u_act_min - (a * u_con_min); EWMA filter (EWMA = Exponentially Weighed Moving Average)
Inputs:
Output:
Function: y_filt is calculated with y_filt := (1 - a) * y_filt_prev + a * y_nonfilt; where a is the filter constant: a := 1/nf; where nf is the filter length: nf := (tf/ts) + 1; At the first iteration, y_filt_prev is set equal to y_nonfilt, which makes the initial value of y_filt become equal to y_nonfilt. Analog input: From WORD to REAL
Inputs:
Output:
Function: This function block implements the linear conversion of an analog input value of data type WORD to a corresponding value of data type REAL (e.g. from 16380 WORD to 5.0 REAL (Volt) as on Wago CC100 PLCs). The mathematical function of the conversion is the following linear function: ai_real := (a * ai_word_as_real) + b; where a := (ai_real_max - ai_real_min) / (ai_word_as_real_max - ai_word_as_real_min); b := ai_real_min - (a * ai_word_as_real_min); This function uses the built-in function WORD_TO_REAL to convert a WORD value into a REAL value (of the same numerical value). This is necessary since the digital-analog converter generates a WORD value (not a REAL value), and the pertinent calculations works on REAL values (not WORD values). Resources: Analog output: From REAL to WORD
Inputs:
Output:
Function: This function block implements the linear conversion of a REAL value in unit e.g. V or mA to the corresponding value of data type WORD (e.g. from 5.0 V to 16384 WORD as on Wago CC100 PLCs). The mathematical function of the conversion is following linear function: ao_word_as_real := (a * ao_real) + b; where a := (ao_word_as_real_max - ao_word_as_real_min) / (ao_real_max - ao_real_min); b := ao_word_as_real_min - (a * ao_real_min); This function uses the built-in function REAL_TO_WORD to convert a REAL value into a WORD value (of the same numerical value). This is necessary since the digital-analog converter operates on basis of a WORD value (not on a REAL value). Resources: Time constant system This function block implements a time constant system, which can be used in e.g. a process simulator. The output is updated continuously.
Inputs:
Output:
Function: The function block implements a numerical calculation of output y based on Euler Forward algorithm for solving the differential equation comprising the model of the system. The model (differential equation) is y' = (K*u - y) / tc The Euler Forward simulation algorithm implemented in the function block (initialization code not shown here): y := y_next; dy_dt := (K*u - y)/tc; y_next := y + ts * dy_dt; Time delay This function block implements a time delay, which can be used in e.g. a process simulator. The output is updated continuously.
Inputs:
Output:
Function: The delay is implemented with an array. At each point of time: 1. y_delayed is the value of the last element of the array. 2. Each of the elements of the array are one step to the right. 3. y_nondelayed is entered into the first element of the array. Updated 9 Nov 2026 by Finn Aakre Haugen (finn@techteach.no). |