How to create FIFO style function in Omron CP2E (Ladder)

Wiresplus

Member
Join Date
Sep 2021
Location
Auckland
Posts
17
Hello!
I have a network of conveyors bringing raw product to 4 machines.

A sensor in the hopper of each machine calls for more product.
I'm struggling to get my head around how to do the function of "this one asked first so it gets supplied first"


I'm usung a CP2E PLC and CX-Programmer and working in Ladder
 
Perhaps a sort of shift register but not in a normal sense of 4 elements i.e. 0-3, a machine requests a product, the machine number is put into register 0, if the preceeding register is 0 then the data is moved from 0 to 1 repeat this until it is at register 3 or the preceeding one has data, when a product is loaded into a machine from register 3, this is put to 0, next scan move the data down putting a 0 in register 0, this again then allows the next machine to populate register 0
There will need to be a hierarchy initially or when all machines request product or a machine is idle etc. A little hard to get your head around all possible combinations but there is always a way to adjust it to suit.
so in effect you have an array of registers that puts the machine number in order of request, the conveyors then take the first one populated (Register 3) then this shifts the data down, when register 0 becomes empty, it allows the next machine to populate it. you will need to cater for first up machine if two or more are requesting product at the same time but this can be achieved by programming populating the register 0 with the order of the program code i.e. code the logic from machine 1 to 4 in that order in the program.
 
What is needed is a FIFO. I think the Omron CP2E instructions to do that are

  • MOV and [+], when a hopper asks for product (edge/one-shot)
    • MOV to add a new item (conveyor ID integer word) after the end of the FIFO
    • [+] to increment the current length of (number of items in) the FIFO, which is also the index to the end of the FIFO
  • MOV, WSFT and [-] when the conveyor supplies or has supplied product to a hopper (edge/one-shot)
    • MOV to get the oldest (i.e. earliest requestor) item from the head of the FIFO.
    • WSFT to shift the subsequent (newer) items in the FIFO to the head of the FIFO
    • [-] to decrement the current length of the FIFO
 
As you only have 4 machines for simplicity you do not need a shift register as such, hard code it if you are not comfortable so for this purpose it is shift array 0-3, there are a few things to consider.
1. initially perhaps all will request a product so keep it simple program it in order i.e. if machine 1 wants product this takes priority & so on as your program if written in that order will put the machine 1 into the fifo, this automatically moves down on the same scan if the other registers in the fifo are 0, Then on next scan because machine 1 has put its request into the fifo & a bit has been set to say it's in there then machine 2 will do the same & so on down the line.
2. What if you take a machine out of auto, need to remove the machine number out of the fifo from the position it is in.
This is achieved by checking the 4 registers for that machine number & clearing it as well as the request bit etc, this then moves the others down the fifo.
3. When the conveyors look at position 3 it sets a bit to say it is moving to the machine x determined by the value in the register & resets the request bit zeros the register 3 to allow the next machine number in registers 0-2 move down & so on. Here is some code & a simple HMI screen to simulate it the code also contains some timers purely for simulation you would have to do the code for the conveyors.
Note: My last work on Omron was nearly 20 years ago & they have moved on so do not have the IDE or knowledge of their functions but this should give you an idea, I would normally do this by loops & indirect addressing but it could be hard to follow so hard coded it just to give ideas on how it could work. This is a quick go at it so perhaps could be simplified a bit.

Machine Queue.png
 

Attachments

  • Machine Queue.pdf
    99.8 KB · Views: 25
As @parky notes, with only four hoppers a brute force approach is more than adequate.

Here is an alternate non-FIFO algorithm:

  • Register each hopper's fill request with a non-zero timestamp for that hopper
    • Caveat: each hopper can have at most one pending fill request
  • Find the hopper with the earliest non-zero timestamp
  • Redirect conveyor toward, and then fill once conveyor outlet arrives over, that hopper
    • Caveat: assumes there is a way to know when the conveyor is positioned over a given hopper
  • When a hopper's fill request is satisfied (detected after the conveyor adding material), stop filling and write a zero timestamp for that hopper
The attached MicroLogix prototype implements this approach in a baker's dozen of rungs, using a hopper weight measurement (which could be level)

  • to initiate a fill request when the weight drops below a low limit, and
  • to satisfy a fill request when the weight goes above a high limit.
It includes a simple model to simulate the behavior.

Adding things, such as auto, run, and hopper-disable switches, is left as an exercise for the user.
 
As Brian stated, something I did not think of was how the product is fed i.e. filling hoppers, however, the logic I produced uses a similar approach but no time stamps just first in queue i.e. machine number, again as Brian has indicated how you control the logic of the conveyors is something you will have to sort, perhaps some interaction between the conveyors & machines regarding filling & hand shaking, I just had a bit from the conveyors stating it's route i.e. filling machine x, Here I noticed that I reset the fifo last variable to 0 & the machine in queue to allow the fifo to increment, this is fine providing the filling conveyors lock out the check for next machine until it has finished filling the current one.I do not believe there is a need for time stamps unless there is some logging going on as the machine number is in order of "Time" if you like, however, it's worth a thought for future enhancements.
 
Yes there is no need for timestamps: I only experimented with them as an alternative to a FIFO to keep track of the order of fill requests; the hopper-ID-ordered array of timestamps functionally replaces the FIFO comprising a time-ordered array of hopper IDs.

The code does a linear search on the timestamps because it only ever needs to "know" the hopper ID of the earliest pending fill request; it could be done in a loop but with only four hoppers brute force is probably cleaner.

The code positioning and running the conveyor is pure fantasy of course.

TBH I was surprised it came out as tight as it did, and I think @parky's code is probably easier to understand as it uses the well known FIFO approach.
 
Well here is a version that uses pointers, it took me a little longer than the brute force even though I used most of the code, looks a lot smaller but boy hurt my head to get it right, works exactly the same as the previous one.
But would it be worth it..... NO!!!!!... not really.
 
Ah, @parky, you're a genius! Pointers i.e. circular buffer, of course.

Here is my monkey-see-monkey-do version: only seven rungs, but

  • it's more like four because one rung is duplicated for each hopper,
  • it's more like twenty because that one rung has so much going on,
    • although that rung is simple because it is actually the canonical Start/Stop Circuit pattern.
As terse as it is, I think this one might be worth using because at its core it has one rung for each basic behavior, so it's actually not hard to grok. Although I don't know if the indexing would carry over cleanly to the Omron environment.
 
Yes, never done pointers etc. in Omron, many years since I used them, The population of the array was simple, however, I struggled with the delete a request in the array if that machine went out of auto, so did it sort of a bit of both, indirect and brute force, the populating & removal is only really one rung each with obviously rungs for setting the pointers & the for next instructions, the last four rungs were for simulation of simple conveyor control i.e. array[3] has a machine number so conveyors feed that & deletes the macine number, this allows the following machine numbers to shift down the array, also built in is a check, if a machine is already in the queue then it waits until the array does not have the machine number already, for example, if machine 1 was already in the queue and tried to put another one in it would mean that the array could be full i.e. 1241 so 3 if wanted to post a request it could not & would have to wait until there is a space, yes could increase the size of array, but that is a trade off with allowing all machines a reasonable go at sharing the availlable time slots. there is no advantage anyway as if there is a machine already in the queue as soon as there are no others in front of it then it becomes instantly availlable. I could have possibly incorporated all the functions within one loop, but then it becomes difficult to find problems & difficult to understand.
I might have a go just for fun, however, as some loops require 4 itterations & some only 3 & then add conditions so probably not gain much in reducing code.
 
Version 1.00

OK, so here's Version 1.0, I'll know by the end of the week if its good.
I used the methodology from @parky, but left it without FBD
 
I have had a quick look at your code, I'm assuming those "DOWN" instructions are oneshots based on the RLO of the contacts. It looks ok, I'm assuming then if a machine is switched off or stopped then the bin in Q or sensor goes false triggering the oneshot, however, it removes the machine that is in H014 so if for example machine 2 was switched off but Machine 3 was in H014 then it would reset Machine 3 which would cause a problem so perhaps it needs a compare in each rung i.e. machine 2 in H014 only then reset H014 & the Q bit.
But again if this goes off without machine 2 in H014 then how can you reset it for example let's assume Machine 3 is in H014, Machine 2 is in H013, but the machine 2 is Switched off, nothing will happen so machine 3 is filling, gets to full this resets H014 to 0, Machine 2 is next in-line moves to H014 but it can't because machine 2 is off-line, it will work fine (I think) if all machines are on & working but if one is disabled or swiched off then the whole thing comes to a halt.
I think you need two ways of deleting the queue one for when t is in location H014 & any time it has been put in the queue i.e. if machine 2 is in any of the array of registers it needs to delete the number out of that register to allow the queue to shift down.
That is why I did some tidying up logic I think you need to do similar but not sure on your control strategy regarding taking a machine out of service.
 
As I suspected, yes your code works fine, however, if one of he machines is switched off or disabled then it deletes not the machine number but the one that is next to be filled see picture here I put 4321 in that order i.e. 1234, 4 being the first in the queue, if machine 1 is switched off i.e. has a problem or power loss to the sensor then it deletes 4 which is first in the queue, not 1 then shifts them down maybe not a problem unless something goes wrong, so you either need to compare each register with the number & then delete it out or have some way of deleting them manually via an HMI or such.

In Order.png
 

Similar Topics

Hello, I've been trying to learn this a while now and still have not found out how this works. I have an Omron CJ2M PLC and an ABB ACS 355 VFD...
Replies
1
Views
248
Hello, I have to deal with iFix again and am looking at the most efficient way to create alarms to display in iFix, i.e. not creating an...
Replies
0
Views
157
Good morning to all, I have the following issue, I installed everything of intouch including the patch, it is the 2023 version. The...
Replies
0
Views
335
So, I finally got versioin 27 installed on my Windows 10 VM. However, now I can't upload a project from my lab controller. I have the above error...
Replies
0
Views
1,132
Hi all, I have few GB of logged data created by RS View 32 Works, it is all in .DBF format. At the moment, my company wants to shift all data to...
Replies
14
Views
1,462
Back
Top Bottom