Bit Shift but for Arrays?

Visinedrops

Member
Join Date
Dec 2023
Location
Grayland, WA
Posts
2
Hello. I've been using the answers in this forum for a while now, so thank you. Usually I can find the answer I'm looking for with a basic Google search, but this one has me dumbfounded:

Logix Designer - L83, V35.11
Tags: REAL-type: Array[0] through Array[47] & Level_Sensor

I need to have the value of Level_Sensor registered in Array[0] to track dryer bed depth every 2 minutes. However, the value in Array[0] needs to be moved to Array[1] and the new value of Level_Sensor to be deposited into Array[0] all the way through to Array[47]. After 47 the values can disappear.

Picture attached: Pink and White blocks are the places I need to move data into from left to right to track the level of the bed depth through the dryer.

Is there a simple way to do this?

Dryer_Piano.jpg
 
Structured text loop.

Make sure the index works in descending order

[47] = [46]
[46] = [45]
..
[2] = [1]
[1] = [0]
New value into [0]
 
Another option is to load the new value into Array[47] then do a COP Array[1] Array[0] with a Length of 46.


Copying to the same array is problematic.



It's best to use 2 COP instructions, copy the used array to a temporary array, then have the second COP copy from the temp array to the final destination.
 
See Example 5 here for why you cannot COP data from 0..47 to 1..47.

@I_Automation's answer is the simplest based on what you have now.

Another option, as noted by @chelton, would be to reverse the meaning of the indices into the array, so the most recent value is at index 47, and the oldest value is at index 0 and is also the one that disappears at each trigger. You could then use the COP command. The FFL/FFU* instructions encapsulate that for you and were more or less designed for what you are trying to do in the first place

* only execute the FFU when the control's .DN bit is 1 i.e. when the FIFO is full
 
Code:
FOR I := 47 TO 1 DO
  Array[I] := Array[I-1];
  Array[0] := Level_Sensor;
END_FOR;
Done.


..unless it doesnt support decreasing FOR loops.


In that case:
Code:
(* Note to self; highest array value is newest *)

FOR I := 1 TO 47 DO
  Array[I-1] := Array[I];
  Array[47] := Level_Sensor;
END_FOR;
But at the end of the day i would recommend Corsairs solution, brute force is best. You can even bulk it in excel in less than a minute.
 
I would look at FFL/FFU instructions. Your FFU should only happen once the array is full, then it needs to happen with each FFL.

chelton's solution with a "backwards" array and a COP instruction will also work well, with the newest data in the highest index register. I've done that multiple times with no issue. If any register in the array can be changed asynchronously (by an HMI, IO device, or interrupt), use the CPS instruction instead of the COP.


I would first look at the FFL/FFU arrangement. I've used the COP method when I needed the data facing the other direction (like for an HMI).
 
Corsair, thank you for that. I tried it that way and it works.

Others, thank you for chiming in. I really appreciate the help and info. I don't know enough about structured text in Studio 5000 so I wasn't able to try that scenerio. I program Arduino, so I understand what was being portrayed.

Again, thank you all for your help. Everything is working as it should now.
 

Similar Topics

Hi All. I have a very specific question about tracking using an encoder and bitshift register. We would like to use a Compact or Control Logix PLC...
Replies
40
Views
1,732
Hi, I need some help write a PLC instruction. I am using Proficy Machine Edition 6.5. Our indexing rotating table has 3 nests that are equally...
Replies
15
Views
3,987
Good morning (EST), I am trying to implement the code below in on an S7-1200. It's barely half a dozen instructions, but I am stuck; I have not...
Replies
26
Views
5,670
I have a program I need to work out for a client and I'm having trouble figuring out the correct logic to do it. Let me see if I can explain it...
Replies
27
Views
6,543
I am having trouble figuring out how to track a product using a BSL instruction. The way that I have it set up is: I have an infeed eye that...
Replies
10
Views
2,748
Back
Top Bottom