PLC Interview Question - Array FIFO Logic Programming Example Average Rolling Mean RSLogix 5000
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.
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.
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.
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.
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.