D ECLARING V ARIABLES

D ECLARING V ARIABLES

During the implementation of a control system, the user must name, or declare , the variables used. This variable declaration is nothing more than the mapping of I/O addresses, indicating which field devices are wired to which I/O modules (see Chapter 5). Figure 10-1a shows a limit switch (LS1) implemented in a standard programmable controller environment. In this configuration, the device is declared (or named) in the control program as its address—10. In an IEC 1131-3 environment, however, a device can be described by any alphanumeric name. This name can include underscores (_). Hence, the limit switch can be declared as a variable named Limit_Switch_1, Clamp_Limit_Switch, or another appropriate name (see Figure 10-1b). From the moment a variable is declared, it will be known by that name throughout the control program, regardless of the IEC 1131-3 programming language used. The name assigned to a variable is not case sensitive; that is, it can be declared in uppercase, lowercase, or a combination of the two. Therefore, the user may choose the appropriate name represen- tations for the purposes of program appearance (e.g., the use of uppercase for

a main variable name and lowercase for a secondary variable name).

Slot 1 Address

2 12 PLC Address 10

(a)

3 13 C

Variable Definition

LD Language

Type:

Boolean

Limit_Switch_1

Name:

Limit_Switch_1

Input variable address Limit_Switch_1

Location

assigned to PLC address

VAR_NAME Rack Slot Terminal

ST Language

Limit_Switch_1 0 1 0

IF Limit_Switch_1 THEN Motor=True Figure 10-1. Limit switch addressed in (a) a standard PLC environment and (b) an IEC

1131-3 environment.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC The IEC 1131 Standard and C HAPTER 3 Programming

Programming Language 10

When declaring a variable, the user must specify the variable type in addition to the variable name. This allows the PLC to know what type of data the device corresponding to the variable transmits. The IEC 1131-3 supports many different local and global data variable types (see Table 10-2); however, the three most common are:

• Boolean • integer • real

C o n t r o l r e l a y s ( B o o l ) I n t e r n a l r e l a y c o li s , t i m e r o u t p u t s

Table 10-2. Data variable types.

Boolean variables are single-bit variables, meaning that the data transmit- ted and received is in the form of 1s and 0s. Discrete I/O variables fall under this category; therefore, they must be specified as “Bool” (short for Boolean) variables in the control program. Many nondiscrete variables, such as analog input signals that are read through an analog input card, are integer variables , because they transmit data in the form of whole numbers (e.g., 2042, –127, etc.). Thus, they must be specified in the control program as integer variables. Internal variables that transmit fractional and floating- point data (i.e., a number multiplied by an exponential expression—2.7 ×

10 2 ) are real variables and, again, must be classified as such. Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC The IEC 1131 Standard and C HAPTER 3 Programming

Programming Language 10

E X AM PLE 1 0 -1

Implement the Boolean variable declaration (variable names and variable types) for the input devices shown in Figure 10-2a for use in

a control program. Assume that the controller being used follows the rack-slot-terminal address configuration (e.g., rack 0, slot 0, terminal 3 is address 003). Figure 10-2b shows the wiring to the input module.

Hardwired Circuit

Description of Inputs

PB1: Used to manually start conveyor sequence LS1: Detects parts in automatic start LS2: Detects a no-jam condition

L1

PLC Input Module Wiring

Figure 10-2. (a)

A traditional hardwired circuit and (b) its wiring diagram.

S OLU T I ON

Figure 10-3 shows a sample variable declaration for this example. All of the input devices are discrete; therefore, they are specified as Boolean variables. PB1 is named MAN_START_PB, LS1 is named AUTO_PART_Detect, and LS2 is named NO_JAM_Detect.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC The IEC 1131 Standard and C HAPTER 3 Programming

Programming Language 10

Note that these variable names, which can be chosen by the user, describe the operational functions of the input devices.

Address Location

Input Variable Name

Variable Type Rack Slot Terminal

MAN_START_PB

Bool

AUTO_PART_Detect

Bool

NO_JAM_Detect

Bool

Figure 10-3. Boolean variable declaration.

1 0 -2 I E C 1 1 3 1 -3 P ROGRAMMING L ANGUAGES

While the IEC 1131-3 programming standard provides great new potential for programmable controller users, it is actually based on the relay ladder logic that has been inherent in PLCs since their inception. The IEC 1131-3 is based on the ladder logic used in PLC ladder diagrams (including functional blocks) because of its simplicity of use, representation, and to some extent, programmability. The IEC 1131-3, however, reduces the need for complex interlocking circuits within PLC ladder diagram circuits. It enhances the languages previously used in programmable controllers and incorporates them with a powerful framework—sequential function charts—making in- terlocking, interpretation of the control program, and implementation of the control system much easier for both the programmer and the final user of the system. With this in mind, let’s briefly discuss the four languages that are used with the IEC 1131-3 standard—ladder diagrams, function block dia- grams, instruction list, and structured text—along with sequential function charts. Note that, when programming in the IEC 1131-3, any of these languages may be used either alone or as a group, with or without sequential function charts. In Section 10-4, we will list all available IEC 1131-3 programming instructions.