Tags And Constants

The basic building blocks of all ladder programs are variables and instructions.

With that said it’s important to understand variables, types and constants. All higher level programming languages utilize variables and constants. This is true whether programming in a language like C, or ladder logic. Variables are created in RSLogix 5000 using an editor and are called Tags.
When tags are created, the software associates the tag name to a physical memory location or address. An instruction executes logic referencing data addressed by a tag. Input instructions read data while output instructions manipulate data. Simple right?In order to define a tag you need to give it a name, define the tag type, define the tags data type, and define the tags visibility or scope.

There are a couple of rules when naming tags with RSLogix 5000.

  1. The name must be a minimum of  1 character
  2. Tags must start with an underscore ‘_’ or Alpha character ‘A-Z’.
  3. The character following the lead character may be an underscore ‘_’ , Alpha ‘A-Z’, or Numeric ‘0-9’ character.
  4. Lowercase alpha characters are supported and are not case sensitive. ‘A’  is equal to ‘a’ for example.

Tags names should be descriptive and purposeful.

Good example:  DOOR_OPEN.
Bad example:  FRANKS_BITS_02.
 

A quick glance at the tag named DOOR_OPEN and its obvious the tag is associated with a door being open or closed.  A quick glance at the tag named FRANKS_BITS_02 and the only thing that’s obvious is Frank has been here and he is making life hard on everyone.

Tip: Use revisions with good descriptions to indicate when and where changes have been made, not cryptic tag names.

When defining a tag there are four Tag Types to choose from:

Base Tags, Alias Tags, Produced Tags and Consumed Tags. The Base tag is the most commonly used tag type. Alias tags reference other tags. Produced and Consumed tags transfer data from processor to processor.

Base Tag– Directly addresses a memory location. No special functions.
Alias Tag– Points to an addressed memory location defined by another tag. Some common uses for Alias Tags are associating Base tags with Module Defined Input and Output tags.
Produced Tag– A directly addressed memory location that allows data to be broadcast to a foreign processor containing an associated Consumed tag.
Consumed Tag– A directly addressed memory location that receives its data from an associated Produced tag in a foreign processor.

When defining a tag a Data Type must be assigned.

The data type tells the processor how much memory needs to be allocated for the tag. There are several data types BOOL, SINT, INT, DINT, LINT and REAL. There are also structured data types such as Strings, Pre-Defined types, Module-Defined types and User-Defined types. RSLogix 5000 has several native data types which Rockwell refers to as “Atomic Data Types”, and are as follows:

Data Type            Description        Bits        Possible Values

BOOL                     Boolean or Bit         1           0 or 1
SINT                       Short Integer         8           -128 to 127
INT                         Integer                   16           -32,768 to 32,767
DINT                      Double Integer     32         -2,147,483,648 to 2,147,483,647
REAL                      Real Number        32         +/-3.402823E38 to +/-1.1754944E-38
LINT                       The LINT data type is a 64-bit integer used to store Alarm and Events time. The LINT data type is supported only with the GSV, SSV, COP, and CPS instructions.
 

Atomic data types are variables. Which mean what? They store variable data, or data that can change while the program is running. Keep in mind that the Atomic data types are the only variable data types that store data. Just as there are different data types there are instructions associated with the various types. For example the XIC instruction is a bit instruction which requires a tag that references a bit or BOOL type tag. If you were to reference an XIC instruction with a REAL type tag the software will throw an error.

Pre-Defined and User-Defined types are structured data types.

Structures are simply data types which are grouped together. It’s important to note that structures can include other structures, but I’m getting ahead of myself, more on structures later.

A timer instruction references a TIMER data type which is a Pre-Defined data type. The TIMER data type is essentially a group of Atomic data types as follows:

         NAME                   Description                        DATA TYPE

PRE                        Timer Preset                             DINT
ACC                        Timer Accumulator              DINT
EN                          Timer Enable                            BOOL
TT                           Timer Timing                           BOOL
DN                          Timer Done                               BOOL
 

If you create a tag named MY_TIMER and define it as a TIMER data type the tag would have the following elements:

TAG ELEMENT                                   DATA TYPE

MY_TIMER.PRE                                  DINT
MY_TIMER.ACC                                  DINT
MY_TIMER.EN                                     BOOL
MY_TIMER.TT                                     BOOL
MY_TIMER.DN                                    BOOL
 

Module-Defined data types are structured data types

which are defined when a module is added to the processor project tree. When hardware such as I/O cards or communication cards are added associated tags are created in the processor scoped tags.

Another important data type is the Constant.

A constant is data that does not change. It is hard coded. Rather than referencing a variable tag in a math instruction it’s possible to reference a constant. An example of a constant could be “123456”.

Tags can either be program scoped or controller scoped.

Controller scoped tags are visible to every program in a project. Program scoped tags are visible only to the program the tags are associated with. There are several reasons to have different scoped tags. I only mention it here because it’s necessary to define the scope of the tag, which warranted a brief although incomplete definition.