Code template structure for S Series can be found from section Code Template Structure S Series. |
Code template structure for E Series can be found from section Code Template Structure E Series |
MultiTool Creator automatically creates a code template for CODESYS project when Create CODESYS Project is selected. The code template contains all variable definitions and initialization needed for programming the device.
This topic briefly introduces the code template parts:
The PLC_PRG is the main POU of a CODESYS project. MultiTool Creator automatically generates PLC_PRG for the CODESYS project and it will always be overwritten when changes done in MultiTool Creator are imported to the CODESYS project. For this reason, the user application code should never be added to PLC_PRG.
The entry point of the user application will be a POU called Main. The code template automatically calls the Main program in the PLC_PRG's action Application. It is not overwritten by MultiTool Creator. If the Main POU is missing from the application, the CODESYS build command gives an error. The code template in CODESYS 3.5 projects includes a Main POU that is made with ST language. To make the Main POU with another programming language, delete the Main POU and make a new one.
The CODESYS 3.5 Device tree in the following images includes all project objects on the same view.
The following project structure is used in:
5050 CODESYS 3.5 projects with device description 1.1.0.X or older
6000 series projects with device description 1.2.0.X or older
The following project structure is used in:
5050 CODESYS 3.5 projects with device description 1.2.0.X or newer
6000 series projects with device description 1.3.1.X or newer
The PLC_PRG is divided into four actions: Init, Epec_In, Application and Epec_Out.
The Init action is run on each program cycle until all initializations are done. The initialization phase is divided into several steps to minimize the needed time of each program cycle. After the initialization phase, Epec_In, Application and Epec_Out actions are run on each program cycle.
PLC_PRGs action |
Sub-action |
Description |
Init |
Init_Entry |
Reads system parameters Contains call of the user POU |
Init_Flash |
Initializes non volatile memory |
|
Init_IO |
I/O initialization functions |
|
Init_Bus |
Initializes CANVXD library instance for each CAN |
|
Init_Protocols_CANx (*) |
CAN protocol initializations for each CAN bus, including CANopen and SAE J1939 |
|
Init_Events |
Initializations for Events |
|
Init_Globe |
Initializations for GlobE (6000/X series with device 1.3.1.X or newer) |
|
Init_Exit |
Initializations for other variables which do not have own action |
|
Epec_In |
IO_Filter |
Filters I/O pin raw values |
Diag |
CAN bus diagnostics HWD_Diagnostic instance call G_SystemOk variable handling LED handling |
|
Bus |
Updates CAN buffers and protocols |
|
Other |
Reserved for future use |
|
Application |
Only contains call for the user application Main |
|
Epec_Out |
Other |
All functions that are needed to run at the end of the program cycle, such as - analogue input protection - parameter saving - resetting the control device if needed (NMT reset) |
IOHandleOutputs |
Copies data from variables which are used in application for the IO to variables defined in description file. This copying sets actual IO to wanted state. |
* CAN bus consecutive numbering, typically 1=CAN1, 2=CAN2 etc.
MultiTool Creator generates global variable and function block instance definitions to (Implicit) Globals lists. These variables and instances can be used, for example, for diagnosing CAN bus and hardware. Code template calls these function blocks automatically. Code template global definitions can be found from the Device tree in CODESYS 3.5 (CodeTemplate > Globals)
Variable definitions are divided into several global lists.
The table below applies to:
5050 CODESYS 3.5 projects with device description 1.1.0.X or older
6000/X series projects with device description 1.2.0.X or older
Global variable list |
Description |
Code_Template_constants |
Constant definitions |
Code_Template_Globals |
All variable definitions and function block instances needed in code template, such as init phase booleans - CANopen instance and array definitions Variables that might be needed in application, such as G_SystemOk boolean, HWD_Measurements instance and limit definitions. |
ERRORS |
Error variables |
CANx_Events |
Event source addresses and data initialization. |
IO |
I/O pin variables that are needed when developing an application |
IO_RAW |
Non scaled raw values of I/O pins. Not needed in normal use, since the code template filters and scales the values before writing them to I/O variables. |
IO_CONFIG |
I/O pin configurations, such as - input pull up configurations - pulse input range selections - input mode selections (mA/V) - output mode selections |
IO_INTERNAL |
Internal I/O - Scaled and filtered voltage and temperature measurements - Reference output enable variables - Overcurrent error statuses for AI pins |
J1939 (optional) |
J1939 library instance Global variable definitions - J1939_CANx(*) variable for each CAN bus that uses J1939 - Variable type is a structure defined in the application |
ODx_VAR (*) |
OD variables whose variable type is RAM, retain or retain persistent. |
ODx_PAR (*) |
OD variables whose variable type is Parameter |
ODx_CANI (*) |
Variables of received PDOs (RPDO) |
ODx_CANO (*) |
Variables of transmitted PDOs (TPDO) |
SYSTEM |
Project information, such as device type, serial number, firmware version, 5050 FW error log. |
slave Configurations (folder) |
This folder includes a global variable list for each slave device |
* OD's consecutive numbering, typically 1=CAN1, 2=CAN2 etc.
The table below applies to:
5050 CODESYS 3.5 projects with device description 1.2.0.X or newer
6000/X series projects with device description 1.3.1.X or newer
Global variable list |
Description |
Code_Template_constants |
Constant definitions |
Code_Template_Globals |
All variable definitions and function block instances needed in code template which are not defined in other variable lists, such as init phase booleans. Variables that might be needed in application, such as G_SystemOk boolean, HWD_Measurements instance and limit definitions. |
ERRORS |
Error variables |
CANx_Events |
Event source addresses and data initialization. |
IO |
I/O pin variables that are needed when developing an application |
IO_CONFIG |
I/O pin configurations, such as - input pull up configurations - pulse input range selections - input mode selections (mA/V) - output mode selections |
IO_INTERNAL |
Internal I/O - Scaled and filtered voltage and temperature measurements - Reference output enable variables - Overcurrent error statuses for AI pins |
J1939 (optional) |
J1939 library instance Global variable definitions - J1939_CANx(*) variable for each CAN bus that uses J1939 - Variable type is a structure defined in the application |
G_CANx_PAR |
OD variables stored in non-volatile memory, so called application parameters |
G_CANx_RPDO |
Variables received in PDO messages |
G_CANx_TPDO |
Variables transmitted in PDO messages |
G_CANx_VAR |
- parameter stored in volatile memory (RAM parameter) and defined in OD - all the other OD variables that do not belong to any of the other G_CANx groups mentioned above |
G_CANopen_CANx |
CANopen related function blocks that the code template uses |
G_CANopen_CANx_Mappings |
PDO mappings |
G_CANopen_CANx_slave_Configurations |
A global variable list for each slave device |
G_CANopen_CANx_VAR |
CANopen related variables that the code template uses |
G_Common |
Contains variables common for all CANs, e.g. parameter system handlers which are used by code template. |
G_SystemInfo |
Information about the project and the unit |
G_UI |
Code template variables related to UI, e.g. UI time and offset |
* OD's consecutive numbering, typically 1=CAN1, 2=CAN2 etc.
MultiTool Creator creates structures and/or enumerations for
J1939 receive and transmit PGNs
Pre-defined indexes
User defined record indexes
Events
In CODESYS 3.5, Data unit types (DUT) can be found from the Device tree. Enumerations are placed into the Enums and structures into the Structs folder.
Epec Oy reserves all rights for improvements without prior notice.
Source file topic200014.htm
Last updated 26-Nov-2024