Back to tutorials
Advanced

PLC Interview Question - Array FIFO Logic Programming Example Average Rolling Mean RSLogix 5000

By
Vladimir Romanov
|
September 30, 2019
Table of Contents

Introduction

PLC Interviews aren’t very complex. Within a short period of time, you may be asked to implement a simple logical structure such as a Motor Starter, a stack light system or a basic FIFO set of rungs. By practicing implementing such structure, you will build your knowledge of PLCs, the software package of your choice and you’ll become a more proficient programmer.

Today, we’re looking at an example which involves a FIFO Implementation and results in a way to store data based on short periods in order to compute a rolling average of such data. In other words, the logic can be used to report a rolling average of the number of products made in the last hour. At first glance, it may seem that such systems already exist, but from our experience, most will report the quantity produced at every hour. The nuance here is that as you walk up to the production line at 7:43AM, you should be able to see how many cases were made from 6:43AM to 7:43AM. A traditional system will give you the number of cases from 6AM to 7AM and sometimes a rolling number starting from 7AM.

FIFO Logic in RSLogix 5000 PLC Programming

Since our logic will require a time-stamp, we need to leverage the internal clock of the PLC system. This is achieved through the first rung in our routine which can be seen below.

PLC Interview Question - Array FIFO Logic Programming Example Average Rolling Mean RSLogix 5000

In “Rung 0”, we’re using two basic instructions which we’ve seen before (SUB Instruction, MOD Instruction). The SUB instruction is applied on the FIFO and allows us to scan the first 11 values. This will become relevant in a future rung. The MOD instruction is critical to breaking down a minute into 6 chunks of 10 seconds. This is achieved by dividing the seconds clock by 10 and taking the remainder. In other words, we’re truncating the seconds timer to give us the least significant digit at all times. This allows us to have a counter for each chunk of 10 seconds.

In “Rung 1”, we have a CTU Instruction which will count the number of boxes flagged by a certain sensor. This counter will increment as boxes go by and will be reset by the logic below every cycle. Note that this application can be repurposed for many different applications and the counter can be converted to a timer.

PLC Interview Question - Array FIFO Logic Programming Example Average Rolling Mean RSLogix 5000

The FIFO relies on two critical instruction: FFL and FFU. The FFL will transfer an element into the array while shifting everything else by a specified step size. The FFU will remove an element at the end of the array into a specified tag. The rung above has many instructions; let’s examine them in detail. The EQU instruction is used to execute the logic when the time is equal to 0. In other words, we want to record the number of cases every 10 seconds since this “SecTime” register will cycle from 0 to 9 and repeat.

The ONS isntruction will perform a single cycle of the instruction. This means that we’re only going to move the array once as the time is at zero. The FFL will load the element which is computed by the counter into the array. In this case, we’re loading into the 12th element as the length specified is 13. We’re also required to specify a control structure which is common between the FFL and the FFU instructions.

We have a few interesting instructions following the FFL: RES, CLR, FOR and DIV. The RES will reset our counter. The FOR Instruction is used to compute a rolling sum. Lastly, the DIV instruction will give us an average by dividing the sum we compute by the number of time slots which results in a rolling average.

PLC Interview Question - Array FIFO Logic Programming Example Average Rolling Mean RSLogix 5000

The last rung contains the FIFO Unload or the FFU Instruction. As briefly mentioned above, this instruction will remove a single element from the specified array and transfer it into a specified register. The FFU is required for a “rolling” effect of the FIFO implementation.

Understanding the Logic of a FIFO

The logic above contains few instructions, but may not seem obvious to new programmers. The goal is to count the number of boxes with a sensor, transfer this value into an array every ten seconds and compute the sum of the last 10 values. By using a FIFO, the system will automatically write the new counter into the array and remove the oldest value thus achieving the desired result.

Although we’re using the FIFO implementation for a speicific problem, it’s extremely versatile and can be the solution to many challenges. It’s a common application for systems which have indexed movements. In other words, you’re producing a single product at a time and the system needs to track the location of said production. An inexperienced programmer may use a timer in this situation which will often fail as the system is started and stopped, is changed, etc.

Conclusion

Going through an example which utilizes a FIFO implementation through FFL and FFU instructions is an excellent step toward becoming a better programmer. The concepts outlined in this short piece of logic are straightforward yet often misunderstood by many programmers. As you implement your own FIFO, make sure to experiment with different ranges, values and ways to store the data.

Back to tutorials

Got a question or comment?

Related Tutorials

Beginner

Opto 22 groov RIO Getting Started

The groov RIO module from Opto 22 has been released only a few months ago. The groov RIO is a feature packed piece of hardware that is easy to install, configure and deploy for many different field applications. The module comes pre-loaded with an array of software tools used across the industry and is ready to hit the floor running out of the box. Furthermore, the module is equipped with user configurable input and output nodes that have the capability unlike anything else on the market.

August 2, 2020
|
By
Vladimir Romanov
Beginner

Micro800 PLC Programming Getting Started

The Micro800 Control Systems by Rockwell Automation provide a cost effective solution for small to medium automation systems. The controllers within this family are typically used on stand alone machines or small process applications. The family offers five distinct controller types that are further customizable through add-on modules: Micro810, Micro820, Micro830, Micro850 and Micro870.Micro800 Programmable Logic Controllers Getting StartedUnlike the other Rockwell Automation controllers, this line of PLCs is programmed through a dedicated software: Connected Components Workbench. From within this tool, the programmer can flash the firmware, load the program and monitor the state of the controller. Furthermore, Connected Components Workbench (CCW) is often used to program other non-PLC Rockwell Automation devices such as Variable Frequency Drives (VFDs) and certain Safety Relays.

July 26, 2020
|
By
Vladimir Romanov
Beginner

An Introduction to DeviceNet Industrial Networks

In this tutorial you will learn about the DeviceNet industrial network, go over a basic offline configuration, and explore some advanced features.

July 24, 2020
|
By
Jacques Venter