Ladder Logic 302: Data Tracking and Structure Data Type
Today’s post is the second “advanced” topic I have covered on PLC ladder logic, The first being toggle circuits.
It is often necessary to track data on individual parts through a machine or production line. If using devices like barcode/datamatrix scanners or RFID tags, tracking parts or pallets is as simple as reading the ID number as it arrives at a station. If it isn’t feasible or economical to use part identification systems, the method shown above is common.
This logic assumes four stations on an indexing conveyor or chassis. The logic itself is quite simple; as the chassis or indexer moves the part it creates an event using a one-shot. This event shifts a Structure (more on that below…) from station 3 to 4 (array element  to array element ), station 2 to 3, 1 to 2, and finally moves an empty record (NULL_DATA) into station 1 (array element ).
It is very important that a one shot is used in the trigger. If not, the data shifts continuously as long as the sensor is made (see scanning…) and the entire array clears in 4 scans (about 50 milliseconds or so depending on the size of your program).
In this example, the data only shifts if the system is in Autocycle. This can be dangerous if the system can be indexed in Manual Mode, since the parts would certainly move if indexed. At the same time, if the trigger were something like a Part Present sensor, inadvertantly making the sensor while doing maintenance could also be a problem.
This example also uses an Array. Arrays are groups of the same type of tag; an array of integers is thus a group of integers dimensioned by the programmer. As an example, a ten element array of integers consists of Integer through Integer.
A Structure is a data type defined by IEC 61131 as well as other computer languages such as C++. TypeIn computer programming these can also be called composite data types. In PLC programming languages they are sometimes called UDT (User Data Type) or UDDT (User Defined Data Type).
These are groups of different types of elements placed into the same tag for ease of manipulation. In the logic example at the top of the post it only takes 4 instructions to move all of the product data. If this had to be done by moving strings, reals and integers and setting bits it would take 60 instructions!
If you look carefully at the UDDT you will see that there are 3 more stations mentioned; a robot, a reject station and an outfeed conveyor. Because these stations do not move together like the indexer, the data moves have to be done with different events. An example might be when the robot picks up the part from the Vision station, the data from  is moved to  and NULL_DATA is moved into . At the same time the UNLD_RBT bit is latched in  showing that this part has moved into the robot gripper position. All of the first seven BOOL tags in the structure are used in this way to show where the parts have been. Data such as PROD_NUM and HSNG_NUM can be used as a method of program selection for the vision system and leak tester, while LEAK_RATE might be used for pass fail status or data collection by a SCADA system or PC. l
It is also important to ensure that the “at station” bits that are set in the data structure (the first seven) are unlatched after the data movement. It is important that they are not inadvertently set in the arriving array element before you want them to be.
On a personal note I am well under way on the design of a new simulation and software training program for ladder logic. My intent is to be able to be able to run it in various simulation “modes”; my own generic language similar to what you have seen above as well as Allen-Bradley, Siemens. Omron, Mitsubishi, GE, Modicon and Koyo. If you have any suggestion or want to know more about this project, let me know!