Variables
According to the IEC 61131-3 standard, the application program logic in PLCnext Engineer is developed using variables instead of directly addressing inputs/outputs or using flags. Each variable and each function block instance that is used in the project must be declared.
Variables are declared in the:- variables table of a POU (each POU provides an own variables table). The variables table contains the declaration of all variables and function block instances that are used in the particular POU.
- Data List of the 'IEC 61131-3' node in the PLANT.The Data List contains all resource-global variables and system variables of the resource (according to the IEC 61131-3 standard). The variables declared here can be used in all POUs within the project (by declaring an external variable there).
The same variables are also contained in the Data List of the controller node.The Safety PLC, if contained in your project, provides its own Data List which may contain Safety PLC variables of safety-related and standard data types.PLCnext Technology controller types have a GDS Port List in addition to the Data List (on the 'PLCnext' node in the PLANT). Here, IN and OUT ports can be assigned to each other (also ports provided by non-IEC 61131-3 programs you have included as libraries).
Variables can be declared either while inserting them into the code (via the context menu of the undeclared variable) or before using them in the code by manually entering the declaration into the table.
This topic contains the following sections:
- Scope of variables
- Standard and safety-related variables
- Exchange variables and reading safety signals in the standard controller
- Feedback variables
- System variables for diagnostic/monitoring purposes
- Ports for PLCnext Technology controllers
Scope of variables
The scope of a variable determines in which POU(s) it is valid, i.e., where it can be used. Possible scopes are local and global. The scope of each variable is defined by the location where it is declared (local variables table or Data List of the 'IEC 61131-3' node) and by the variable keyword used in the declaration.
- Local variables: a variable, which can only be used in one POU (including its methods, coded actions or transitions, if applicable), is called a local variable (i.e., its scope is local). Local variables have to be declared in the variables table relating to the POU where the variable is going to be used. Possible variable declaration keywords are Local, Input, Output or InOut. PLCnext Engineer stores these variables to free memory areas in the controller memory which are not known by the user. These variables may have an optional initial value.
-
Resource-global variables: a variable which can be used in all POUs which are executed by the standard controller is called a resource-global variable. Such variables have to be declared in the Data List of the 'IEC 61131-3' node in the PLANT. The Safety PLC has its own resource-global variables which can be used in all safety-related POUs executed by the Safety PLC. These variables have to be declared in the Data List of the 'Safety PLC' node of the PLANT. Global variables of the Safety PLC can be of safety-related or standard data types.
Note
In the Data Lists of both the standard controller and the Safety PLC you can map global standard variables of the Safety PLC to global variables of the standard controller thus creating an exchange variable. Exchange variables are always of a standard data type and enable the communication between standard controller and Safety PLC. -
Program-global variables: a variable which can be used in the program POU where it is declared and in all FB POUs which are instantiated within this program. In the program POU such a variable is declared with 'Usage = Program'. In addition, it has to be declared with 'Usage = External' in the local variables table of each instantiated FB where the variable is going to be used.
Program-global variables are not supported for safety-related POUs.
Further Info
Refer to the topic "Instance-related I/O variables" for further details.
Standard and safety-related variables
Safety-related and standard (non-safety-related) code is strictly distinguished in PLCnext Engineer. Therefore, also safety-related and standard variables, or more precise, data types, are distinguished.- Standard (non-safety-related) IEC 61131-3-compliant data types. This includes elementary and user-defined data types.
- Safety-related elementary data types.
In safety-related code worksheets, safety-related and standard variables can be mixed and directly connected to each other. This corresponds to an implicit data type conversion which requires some rules to be observed.
For easier distinction of standard and safety-related variables, all safety-related variables are displayed with a yellow color marking in safety-related SNOLD code worksheets and variables grids. Variables of standard data types are shown without color marking. While programming safety-related FBD/LD code in SNOLD worksheets, the continuous data flow analysis in the SNOLD code highlights the leading safety-related signal paths of a network by displaying them as thick yellow lines. Refer to the topic "Mixing Safety-related and Standard Variables in the Code" for details.
Further Info
Refer to the topic "Data Types" for further information on the properties of safety-related and standard data types. |
Exchange variables and reading safety signals in the standard controller
Exchange variables enable the communication between the standard controller and the Safety PLC. An exchange variable is created by assigning a global controller variable to a standard variable of the Safety PLC. This way, both controllers can exchange information.
Furthermore, the standard controller can read the status of signals in the safety application. However, such a threefold mapping of a Safety PLC variable, a controller variable and a process datum is not referred to as exchange variable.
The creation of exchange variables as well as the assignment of process data items have to be done in the Data List of the standard controller or the Safety PLC (role mapping).
For details refer to the topics "Exchanging Data between Controller and Safety PLC" and "Role Mapping in Data Lists: I/O Variables and Exchange Variables".
Feedback variables
In FBD/LD function block and program POUs, implicit feedbacks can be programmed by connecting an output back to an input. A variable which is inserted into a feedback connection line is considered as feedback variable. It provides two connection points (in/out). The menu item 'Toggle Feedback Variable' in the context menu of such a variable is marked as selected. Feedback variables must be connected on both sides.
Further Info
Refer to the topic "Feedback variables in FBD/LD" for details. |
System variables for diagnostic/monitoring purposes
System variables are provided by the runtime. They allow access to, for example, the system state, CPU performance etc. System variables have fixed memory addresses and can be used by the controller program to get this information.
System variables are automatically declared as global variables in the Data List of the controller. The name and properties of a system variable are predefined by default and cannot be modified.
As each system variable is a global variable, an 'External' declaration must be inserted in the local variables table of the POU where it is used.
Note
If a Safety PLC is included in your project, specific safety-related (Profisafe) system variables may be provided in the Data List of the 'Safety PLC' PLANT node. The creation of these Profisafe system variables can be enabled/disabled in PLCnext Engineer. They can be used for communication/F-Device state diagnostics in the Profisafe system. |
Further Info
For a description of the available system variables, refer to the PLCnext Info Center and the user manual of the controller involved. |
Ports for PLCnext Technology controllers
For controllers of the PLCnext Technology generation, input and output ports can be used in addition to or instead of resource-global variables. Programs communicate using ports, i.e., data can be read from and written to programs via ports.
Via ports, communication is even possible between IEC 61131-3-compliant programs and programs developed with a non-IEC 61131-3 programming language such as C++.
For that purpose, input and output ports can be assigned to each other using the role mapping function in the GDS Port List. Port Lists are available on the 'PLCnext' PLANT node and on program instance nodes. A Port List contains the ports which are relevant for the respective PLANT node. All port connections are stored in the Global Data Space of the PLCnext Technology controller.
Further Info
Further information can be found in the topic "PLCnext Technology controller generation". |