Allen Bradley uses the terminology ’tags’ to describe variables, status, and input/output (I/O) values for the controller. ’Controller Tags’ include status values and I/O definitions. These are scoped, meaning that they can be global and used by all programs on the PLC. These can also be local, limiting their use to a program that owns it.
Variable tags can be an alias for another tags, or be given a data type. Some of the common tag types are listed below.
Figure 13.1 Selected ControlLogic Data Types
Data values do not always need to be stored in memory, they can be define literally. Figure 13.1 Literal Data Values shows an example of two different data values. The first is an integer, the second is a real number. Hexadecimal numbers can be indicated by following the number with H, a leading zero is also needed when the first digit is A, B, C, D, E or F. A binary number is indicated by adding a B to the end of the number.
Figure 13.1 Literal Data Values
Data types can be created in variable size 1D, 2D, or 3D arrays.
Sometimes we will want to refer to an array of values, as shown in Figure 13.1 Arrays. This data type is indicated by beginning the number with a pound or hash sign ’#’. The first example describes an array of floating point numbers staring in file 8 at location 5. The second example is for an array of integers in file 7 starting at location 0. The length of the array is determined elsewhere.
Expressions allow addresses and functions to be typed in and interpreted when the program is run. The example in Figure 13.1 Expressions will get a floating point number from ’test’, perform a sine transformation, and then add 1.3. The text string is not interpreted until the PLC is running, and if there is an error, it may not occur until the program is running - so use this function cautiously.
These data types and addressing modes will be discussed more as applicable functions are presented later in this chapter and book.
Figure 13.1 An Example of Ladder Logic Functions shows a simple example ladder logic with functions. The basic operation is such that while input A is true the functions will be performed. The first statement will move (MOV) the literal value of 130 into integer memory X. The next move function will copy the value from X to Y. The third statement will add integers value in X and Y and store the results in Z.
Figure 13.1 An Example of Ladder Logic Functions
Previous chapters have discussed the basic operation of timers and counters. The ability to address their memory directly allows some powerful tools. The bits and words for timers are;
Counter have the following bits and words.
As discussed before we can access timer and counter bits and words. Examples of these are shown in Figure 13.1 Examples of Timer and Counter Addresses. The bit values can only be read, and should not be changed. The presets and accumulators can be read and overwritten.
Figure 13.1 Examples of Timer and Counter Addresses
Consider the simple ladder logic example in Figure 13.1 Door Light Example. It shows the use of a timer timing TT bit to seal on the timer when a door input has gone true. While the timer is counting, the bit will stay true and keep the timer counting. When it reaches the 10 second delay the TT bit will turn off. The next line of ladder logic will turn on a light while the timer is counting for the first 10 seconds.
Figure 13.1 Door Light Example
Status memory allows a program to check the PLC operation, and also make some changes. A selected list of status bits is shown in Figure 13.1 Status Bits and Words for ControlLogix for Allen-Bradley ControlLogix PLCs. More complete lists are available in the manuals. The first six bits are commonly used and are given simple designations for use with simple ladder logic. More advanced instructions require the use of Get System Value (GSV) and Set System Value (SSV) functions. These functions can get/set different values depending upon the type of data object is being used. In the sample list given one data object is the ’WALLCLOCKTIME’. One of the attributes of the class is the DateTime that contains the current time. It is also possible to use the ’PROGRAM’ object instance ’MainProgram’ attribute ’LastScanTime’ to determine how long the program took to run in the previous scan.
Figure 13.1 Status Bits and Words for ControlLogix
An example of getting and setting system status values is shown in Figure 13.1 Reading and Setting Status bits with GSV and SSV. The first line of ladder logic will get the current time from the class ’WALLCLOCKTIME’. In this case the class does not have an instance so it is blank. The attribute being recalled is the DateTime that will be written to the DINT array time[0..6]. For example ’time[3]’ should give the current hour. In the second line the Watchdog time for the MainProgram is set to 200 ms. If the program MainProgram takes longer than 200ms to execute a fault will be generated.
Figure 13.1 Reading and Setting Status bits with GSV and SSV
As always, additional classes and attributes for the status values can be found in the manuals for the processors and instructions being used.
Simple ladder logic functions can complete operations in a single scan of ladder logic. Other functions such as timers and counters will require multiple ladder logic scans to finish. While timers and counters have their own memory for control, a generic type of control memory is defined for other function. This memory contains the bits and words in Figure 13.1 Bits and Words for Control Memory. Any given function will only use some of the values. The meaning of particular bits and words will be described later when discussing specific functions.