Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
Understanding Data Types in Studio 5000 and RSLogix 5000
Beginner

Understanding Data Types in Studio 5000 and RSLogix 5000

Allen Bradley
PLC Programming

Introduction

Many early and even more experienced PLC programmers may struggle with troubleshooting issues that arise from a lack of understanding of how data types work. This tutorial will explain all the data types in Rockwell Studio 5000 (formerly known as RSLogix 5000). We will review the definition of a data type, some common data types in Studio 5000 and when they may be used, and some programming and troubleshooting examples. 

Let's begin with the definition. What is a data type? It is a classification of what kind of data a PLC tag can hold. For example, do you want your tag to only have a value of 0 or 1? Then it should be a BOOL data type. Do you want your tag to be able to have a value of 0.62? Then it should be a REAL. 

Some common data types in Studio 5000 are BOOL, DINT, REAL, and TIMER. As mentioned already, BOOL (boolean) tags can only have a value of 0 (false) or 1 (true). For example, let's say you create a tag that indicates the status of whether a valve is open or closed. This tag would have a BOOL data type.  

DINT (double integer) tags are used for numbers that do not take decimal/fractional values (0,1,2,3,4,5... etc.). For example, let's say you want to count how many times a day an operator presses a certain pushbutton. A tag of DINT data type can be used. The DINT data type consists of 32 BOOL bits. This also demonstrates an important concept that a tag of one data type can consist of elements that have another data type. This is explored further in Example 5. 

The REAL data type is for numbers that may have decimal/fractional values (for example, 47.38). Let's say you want to read the RPM of a motor. Use a REAL data type for this. 

The TIMER data type is used for any kind of timer, such as TON, TOF, or RTO timers. In general, timer instructions are used to track how much time has elapsed. For example, let's say you want to know how long a pump has been running so that after a certain run time, an oil change can be performed. The specific type of timer (TON/Timer On Delay, TOF/Timer Off Delay, RTO/Retentive Timer) is selected based on the application, but all Studio 5000 timer instructions have the data type TIMER. 

Of course, there are many other data types besides the ones mentioned above, but these are some of the most common ones. 

Now that you understand different data types, let's review some examples and discuss some issues that may arise during programming and troubleshooting. Beginner programmers may not realize that some of the errors they encounter can arise from a lack of understanding of data types. The examples below show some common scenarios. 

Example 1: Errors on failure to create a tag, creating a tag with the correct data type 

Look at the two images below. The first one shows a basic latching circuit. The rung indicates that there are errors. Why? Because none of the tags have been created yet. Right click on the tag name and you will get a popup window as shown below. You must select the desired data type (in this case, all tags in this rung must have the BOOL data type). 

Figure 1 - Data Types in PLC Programming | Latching Circuit Ladder Logic
Figure 1 - Data Types in PLC Programming | Latching Circuit Ladder Logic
Figure 2 - Data Types in PLC Programming | Latching Circuit Tag Creation
Figure 2 - Data Types in PLC Programming | Latching Circuit Tag Creation

Example 2: DINT vs. REAL

In the image below, there are two very similar rungs. Note that the DINT tag shows "100" while the REAL tag shows "100.0". The presence of a decimal point indicates whether a tag is a REAL. All REAL tag values will show a decimal point, even if the value is 0.0. 

Figure 3 - Data Types in PLC Programming | MOV Instructions DINTs and REALs
Figure 3 - Data Types in PLC Programming | MOV Instructions DINTs and REALs

Example 3: Mistakenly using a tag with the incorrect data type

The image below is very similar to the one in the first example, except that the first instruction incorrectly uses the tag "Dint_1" (which is of type DINT)  instead of "On_PB_1" (which is of type BOOL). The XIC (Normally Open) instruction can only take on True or False values, and therefore can only be used with BOOL tags. Because it was incorrectly used with a DINT tag, Studio 5000 shows an error. 

Figure 4 - Data Types in PLC Programming | Latching Circuit Ladder Logic using Incorrect Data Types
Figure 4 - Data Types in PLC Programming | Latching Circuit Ladder Logic using Incorrect Data Types

The image above is an example of how software prevents you from making a programming mistake. However, Studio 5000 will not catch every kind of data type misuse issue. Take a look at the image below: 

Figure 5 - Data Types in PLC Programming | Using MOV to send a REAL to a DINT Data Type
Figure 5 - Data Types in PLC Programming | Using MOV to send a REAL to a DINT Data Type

The rung doesn't show as errored, so what's the problem? Notice how Dint_4 is "0" while Real_3 is "0.0". The data after the  decimal point gets lost when moving a DINT to a REAL, making the value less accurate. When troubleshooting in the field, if you ever notice that a tag has no data after the decimal point, it's a good idea to check whether the tag data type is set to REAL. Typically, when performing  operations with tags having the REAL data type, you will want to have the result stored in a REAL tag as well, so as to prevent the loss of data after the decimal point and thus maintain accuracy. 

You may be surprised that Studio 5000 does not prevent the transfer of a REAL value to a DINT value. If a REAL is ever attempted to be stored in a DINT, the REAL value will be rounded up or down, according to the following rules:

  • If the data after the decimal point is greater than 0.5, the DINT result will round up.¬†
  • If the data after the decimal point is less than 0.5, the DINT result will round down.
  • ¬†If the data after the decimal point is exactly 0.5, and the integer portion of the REAL value is an odd number, then the DINT result will be rounded up. For example, 23.5 becomes 24. If the integer portion of the REAL value is an even number, then the DINT result will be rounded down. For example, 18.5 becomes 18.¬† (If you have access to the Rockwell Knowledgebase, you may want to look at Tech Note ID: QA2297 which explains this further.)

There are situations where this kind of rounding is acceptable, but for the most part, the results of any kind of operations performed with REAL tags should be stored in destinations having REAL data type as well. 

Example 4: Creating a tag in Controller Tags

In Example 1, you saw how the data type of a tag is selected when a tag is created in the ladder editor window. Another way to create tags is by going to Controller Tags > Edit Tags. In the image below, a new tag "test_tag" is created. The data type of any tag created this way is automatically set to DINT. If a different data type is desired, click on "DINT" and use the popup window to select a different data type. 

Figure 6 - Data Types in PLC Programming | Creating Tags in Controller Scope
Figure 6 - Data Types in PLC Programming | Creating Tags in Controller Scope
Figure 7 - Data Types in PLC Programming | Creating Tags in Controller Scope specifying Data Types
Figure 7 - Data Types in PLC Programming | Creating Tags in Controller Scope specifying Data Types

Example 5: Data type elements

As mentioned before, data types can be "nested". For example, the DINT data type consists of BOOL elements. The images below show how tags of one data type (in these examples, TIMER and TOTALIZER) consist of elements of other data types. For example, the TIMER data type consists of DINT and BOOL elements. 

The TOTALIZER data type has even more elements than the TIMER data type, including BOOL, DINT, and REAL. In fact, not all of the elements even fit in the screenshot.

Figure 8 - Data Types in PLC Programming | Creating Timers
Figure 8 - Data Types in PLC Programming | Creating Timers
Figure 9 - Data Types in PLC Programming | Creating TOTALIZERS
Figure 9 - Data Types in PLC Programming | Creating TOTALIZERS

You may be wondering, can I create my own data type, which consists of whatever elements I want? The answer is yes. More experienced programmers may have heard of UDTs, which stands for User Defined Data Type. Just like the name says, it allows the programmer to create their own data type, which is often more specialized or complex than the data types available by default. 

Conclusion

Hopefully, now that you have finished this tutorial, you realize the importance of understanding data types. You have now seen some common issues that stem from using an incorrect data type and know how to troubleshoot them. We covered definitions, common data types and when to use them, and some typical data type - related programming mistakes and how to fix them. Interested in learning more about data types? Further topics to investigate are arrays and UDTs. Search for "array" or "UDT" on the SolisPLC tutorials page to find tutorials on these topics.