
- •1 A Brief Introduction to CoDeSys
- •1.1 What is CoDeSys
- •1.2 Overview of CoDeSys Functions...
- •1.3 Overview on the user documentation for CoDeSys
- •2 What is What in CoDeSys
- •2.1 Project Components...
- •2.2 Languages...
- •2.2.1 Instruction List (IL)...
- •2.2.2 Structured Text (ST)...
- •2.2.3 Sequential Function Chart (SFC)...
- •2.2.4 Function Block Diagram (FBD)...
- •2.2.5 The Continuous Function Chart Editor (CFC)...
- •2.2.6 Ladder Diagram (LD)...
- •2.3 Debugging, Online Functions...
- •2.4 The Standard...
- •3 We Write a Little Program
- •3.1 Controlling a Traffic Signal Unit...
- •3.2 Visualizing a Traffic Signal Unit...
- •4 The Individual Components
- •4.1 The Main Window...
- •4.3 Managing Projects...
- •4.4 Managing Objects in a Project...
- •4.5 General Editing Functions...
- •4.8 Help when you need it...
- •5 Editors in CoDeSys
- •5.1 This is for all Editors...
- •5.2 Declaration Editor...
- •5.2.1 Working in the Declaration Editor
- •5.2.3 Pragma instructions in the Declaration Editor
- •5.3 The Text Editors...
- •5.3.1 Working in text editors
- •5.3.2 The Instruction List Editor...
- •5.3.3 The Editor for Structured Text...
- •5.4 The Graphic Editors...
- •5.4.1 Working in graphic editors
- •5.4.2 The Function Block Diagram Editor...
- •5.4.3 The Ladder Editor...
- •5.4.4 The Sequential Function Chart Editor...
- •5.4.5 The Continuous Function Chart Editor (CFC)...
- •6 The Resources
- •6.1 Overview of the Resources
- •6.2 Global Variables, Variable Configuration, Document Frame
- •6.2.1 Global Variables...
- •6.2.2 Variable Configuration...
- •6.2.3 Document Frame...
- •6.3 Alarm Configuration
- •6.3.1 Overview
- •6.3.2 General information on alarms, Terms
- •6.3.3 Alarm classes
- •6.3.4 Alarm groups
- •6.3.5 Alarm saving
- •6.3.6 'Extras' Menu: Settings
- •6.4 Library Manager...
- •6.6 PLC Configuration...
- •6.6.1 Overview
- •6.6.2 Working in the PLC Configuration...
- •6.6.3 General Settings in the PLC Configuration
- •6.6.4 Custom specific parameter dialog
- •6.6.5 Configuration of an I/O Module...
- •6.6.6 Configuration of a Channel
- •6.6.7 Configuration of Profibus Modules...
- •6.6.8 Configuration of CAN modules...
- •6.6.9 Configuration of a CanDevice (CANopen Slave)
- •6.6.10 PLC Configuration in Online Mode
- •6.6.11 Hardware scan/State/Diagnosis information from the PLC
- •6.7 Task Configuration...
- •6.7.1 Working in the Task Configuration
- •6.7.2 System Events
- •6.7.3 Taskconfiguration in Online Mode
- •6.8 Watch and Receipt Manager...
- •6.8.1 Overview
- •6.8.2 Watch and Receipt Manager in the Offline Mode
- •6.8.3 Watch and Receipt Manager in the Online Mode
- •6.9 The Sampling Trace
- •6.9.1 Overview and Configuration
- •6.9.2 Display of the Sampling Trace
- •6.9.3 'Extras' 'Save Trace'
- •6.9.4 'Extras' 'External Trace Configurations'
- •6.10 Workspace
- •6.11 Parameter Manager ..
- •6.11.1 Overview, Activating
- •6.11.2 The Parameter Manager Editor, Overview
- •6.11.3 Parameter List Types and Attributes
- •6.11.4 Managing parameter lists
- •6.11.5 Editing parameter lists
- •6.11.6 Parameter Manager in Online Mode
- •6.11.7 Export / Import of parameter lists
- •6.12 Target Settings
- •6.13 The PLC-Browser
- •6.14 Tools
- •6.14.1 Properties of available Tool Shortcuts (Object Properties)
- •6.14.2 Managing Tool Shortcuts
- •6.14.3 Frequently asked questions on Tools
- •7.1 What is ENI
- •7.2 Preconditions for Working with an ENI project data base
- •7.3 Working with the ENI project data base in CoDeSys
- •7.4 Object categories concerning the project data base
- •8 DDE Interface
- •8.1 DDE interface of the CoDeSys programming system...
- •8.2 DDE communcation with the GatewayDDE Server...
- •9 The License Management in CoDeSys
- •9.1 The License Manager
- •9.1.1 Creating a licensed library in CoDeSys
- •10 APPENDIX
- •Appendix A: IEC Operators and additional norm extending functions
- •Arithmetic Operators...
- •Bitstring Operators...
- •Selection Operators
- •Comparison Operators...
- •Address Operators...
- •Calling Operators...
- •Type Conversions...
- •Numeric Operators...
- •Appendix B: Operands in CoDeSys
- •Constants
- •Variables
- •Addresses
- •Functions
- •Appendix C: Data types in CoDeSys
- •Standard data types
- •Defined data types
- •Appendix D: The CoDeSys Libaries
- •The Standard.lib library
- •String functions...
- •Bistable Function Blocks...
- •Trigger...
- •Counter...
- •Timer...
- •The Util.lib library
- •BCD Conversion
- •Bit-/Byte Functions
- •Mathematic Auxiliary Functions
- •Controllers
- •Signal Generators...
- •Function Manipulators...
- •Analog Value Processing...
- •The AnalyzationNew.lib library
- •The CoDeSys System Libraries
- •Appendix E: Operators and Library Modules Overview
- •Appendix F: Command Line-/Command File
- •Command Line Commands
- •Command File (cmdfile) Commands
- •Appendix G: Siemens Import
- •Import from a SEQ Symbol File
- •Import from a S5 Project File
- •Converting S5 to IEC 61131-3
- •Appendix H: Target Settings in Detail
- •Settings in Category Target Platform
- •Appendix I: Use of Keyboard
- •Appendix J: Compiler Errors and Warnings
- •Warnings
- •Errors

Appendix D: - The CoDeSys Libaries
reset to the initial value DT#1970-01-01-00:00:00. Please note that the time in PDT is only set by a rising edge.
10.17 The Util.lib library
This library contains an additional collection of various blocks which can be used for BCD conversion, bit/byte functions, mathematical auxiliary functions, as controller, signal generators, function manipulators and for analogue value processing.
As some of the functions and function blocks contain REAL variables, an accessory library named UTIL_NO_REAL exists in which these POUs are excluded.
10.17.1BCD Conversion
A byte in the BCD format contains integers between 0 and 99. Four bits are used for each decimal place. The ten decimal place is stored in the bits 4-7. Thus the BCD format is similar to the hexadecimal presentation, with the simple difference that only values between 0 and 99 can be stored in a BCD byte, whereas a hexadecimal byte reaches from 0 to FF.
An example: The integer 51 should be converted to BCD format. 5 in binary is 0101, 1 in binary is 0001, which makes the BCD byte 01010001, which corresponds to the value $51=81.
BCD_TO_INT
This function converts a byte in BCD format into an INT value:
The input value of the function is type BYTE and the output is type INT.
Where a byte should be converted which is not in the BCD format the output is -1.
Examples in ST:
i:=BCD_TO_INT(73); (* Result is 49 *) k:=BCD_TO_INT(151); (* Result is 97 *)
l:=BCD_TO_INT(15); (* Output -1, because it is not in BCD format *)
INT_TO_BCD_
This function converts an INTEGER value into a byte in BCD format: The input value of the function is type INT, the output is type BYTE.
The number 255 will be outputted where an INTEGER value should be converted which cannot be converted into a BCD byte.
Examples in ST:
i:=INT_TO_BCD(49); (* Result is 73 *) k:=BCD_TO_INT(97); (* Result is 151 *) l:=BCD_TO_INT(100); (* Error! Output: 255 *)
10.17.2 Bit-/Byte Functions
EXTRACT
Inputs to this function are a DWORD X, as well as a BYTE N. The output is a BOOL value, which contains the content of the Nth bit of the input X, whereby the function begins to count from the zero bit.
Examples in ST:
FLAG:=EXTRACT(X:=81, N:=4); (* Result : TRUE, because 81 is binary 1010001, so the
4th bit is 1 *)
10-50 |
CoDeSys V2.3 |

Appendix D: - The CoDeSys Libaries
FLAG:=EXTRACT(X:=33, N:=0); (* Result : TRUE, because 33 is binary 100001, so the bit '0' is 1 *)
PACK
This function is capable of delivering back eight input bits B0, B1, ..., B7 from type BOOL as a BYTE. The function block UNPACK is closely related to this function.
PUTBIT
The input to this function consists of a DWORD X, a BYTE N and a BOOLean value B. PUTBIT sets the Nth bit from X on the value B, whereby it starts counting from the zero bit.
Example in ST:
A:=38; |
(* binary 100110 *) |
B:=PUTBIT(A,4,TRUE); (* Result : 54 = 2#110110 *)
C:=PUTBIT(A,1,FALSE); (* Result : 36 = 2#100100 *)
UNPACK
UNPACK converts the input B from type BYTE into 8 output variables B0,...,B7 of the type BOOL, and this is the opposite to PACK.
Example in FBD: Output:
10.17.3 Mathematic Auxiliary Functions
DERIVATIVE
This function block approximately determines the local derivation.
The function value is delivered as a REAL variable by using IN. TM contains the time which has passed in msec in a DWORD and the input of RESET of the type BOOL allows the function block to start anew through the delivery of the value TRUE.
The output OUT is of the type REAL.
In order to obtain the best possible result, DERIVATIVE approximates using the last four values, in order to hold errors which are produced by inaccuracies in the input parameters as low as possible.
Block in FBD:
CoDeSys V2.3 |
10-51 |

Appendix D: - The CoDeSys Libaries
INTEGRAL
This function block approximately determines the integral of the function.
In an analogue fashion to DERIVATIVE, the function value is delivered as a REAL variable by using IN. TM contains the time which has passed in msec in a DWORD and the input of RESET of the type BOOL allows the function block to start anew with the value TRUE.
The output OUT is of the type REAL.
The integral is approximated by two step functions. The average of these is delivered as the approximated integral.
Block in FBD: Example: Integration of a linear function:
STATISTICS_INT
This function block calculates some standard statistical values:
The input IN is of the type INT. All values are initialised anew when the BOOLean input RESET is TRUE.
The output MN contains the minimum, MX of the maximum value from IN. AVG describes the average, that is the expected value of IN. All three outputs are of the type INT.
Block in FBD:
STATISTICS_REAL
This function block corresponds to STATISTICS_INT, except that the input IN is of the type REAL like the outputs MN, MX, AVG.
VARIANCE
VARIANCE calculates the variance of the entered values.
The input IN is of the type REAL, RESET is of the type BOOL and the output OUT is again of the type REAL.
This block calculates the variance of the inputted values. VARIANCE can be reset with RESET=TRUE.
The standard deviation can easily be calculated as the square root of the VARIANCE.
10-52 |
CoDeSys V2.3 |

Appendix D: - The CoDeSys Libaries
10.17.4 Controllers
PD
The PD controller function block:
ACTUAL (actual value) and DESIRED (desired or nominal value) as well as KP, the proportionality coefficient, are all input values of the type REAL. TV is of the type DWORD and contains the derivative action time in msec. Y_OFFSET, Y_MIN and Y_MAX are of type REAL and are used for the transformation of the manipulated variable within a prescribed range. MANUAL, of type BOOL, switches to manual operation. RESET is of the type BOOL and serves to reset the controller.
Y = KP (∆ + TV δ∆/δt) + Y_OFFSET whereby ∆=SET_POINT-ACTUAL
Y is also limited to the allowed range between Y_MIN and Y_MAX. If Y exceeds this range, LIMITS_ACTVE, a BOOLean output variable, becomes TRUE. If no limitation of the manipulated variable is desired, Y_MIN and Y_MAX are set to 0.
If MANUAL is TRUE, then the regulator is suspended, that is Y is not altered (by the controller), until MANUAL becomes FALSE, whereby the controller is re-initialized.
A P-controller is easily generated by setting TV to a fixed value of 0.
PID
The PID controller function block:
Unlike the PD controller, this function block contains a further DWORD input TN for the readjusting time in msec.
The output, the manipulated variable (Y) is again of type REAL, and contains, unlike the PD controller, an additional integral part:
Y = KP (∆ + 1/TN ?∆(t)dt + TV δ∆/δt) + Y_OFFSET
The PID controller can be easily converted to a PI controller by setting TV=0.
CoDeSys V2.3 |
10-53 |