Glossary · PLC and control programming
Global variable
Also known as: VAR_GLOBAL, Global tag
German: Globale Variable
In IEC 61131-3 programming, a global variable is a variable declared with VAR_GLOBAL in a configuration or resource, so that every program organization unit that declares it as VAR_EXTERNAL can read and write it.
- PLC programming
- Standards
In one sentence
A global variable is declared once for a whole PLC configuration or resource and can be accessed by all program parts.
Example
The global variable gMachineMode holds the current operating mode, which the mode selector program writes and many other programs read.
How it applies
- Engineering: Global variables are the simplest way to share data between programs, tasks and HMI connections. Coding guidelines usually limit them to interface data and machine-wide values, because every global can be written from anywhere.
- Multitasking: When tasks with different priorities access the same global variable, a high-priority task can interrupt a low-priority one in the middle of an update. Structures copied in several steps may then be inconsistent; engineers use copies, flags or controller-specific mechanisms to prevent this.
- Maintenance: A Cross-reference shows every write access. More than one writer per global variable is a common source of faults.
- Documentation: List global variables that other systems use (HMI, SCADA, MES) in the interface description with type, unit and meaning. Each value should have one clearly named writer, its Source of truth.
Global variable vs. local variable
A global variable is visible across the program. A Local variable is visible only inside the program unit that declares it. Local variables are the default; global ones are the exception that must be justified.