FiFo register to store numeric values

Hi,
Is there anyone who made a chart for using an FiFo register and could share the code?

Regards / Lennart

Any reason not to use the built in command?
Shift Numeric Table Elements
It will FiFo the table for you, either up or down.
From the manual;

•For positive shift counts, entries shift toward the end of the table. For negative shift counts, entries shift toward the beginning (index zero) of the table.

•Entries at the beginning or end of the table are lost when shifted beyond those limits.

•Zeros are written to entries left empty by shifting.

For small fixed sized queues, shifting the table is simplest. If the length of data in the queue changes, then you will need to keep track of the index for the end of the queue.

If you need a larger queue then performance would be best to use a circular buffer where you keep track of the beginning and end positions and don’t do any shifting. This method is only slightly more complex and if someone were to make a subroutine to handle a queue, this is what I would recommend.

Thanks! Beno and Philp for these tips.

I’m not used to work with opto22 yet. I have done more programming with Siemens system.

But I will try this.

Regards / Lennart

No Shift command for String Tables??

It is always worth doing a search in the forums if you don’t find a pac control command you need… In this case, the top result for a search of ‘shift’ finds this forum post from OptoMary;

Mary’s code should work, but if you don’t want to use the scratchpad area - or you don’t have one available, you can do this in a string table in four lines:

for i = 63 to 1 step -1
  st[i] = st[i-1];
next
st[0] = new_string;

st is your string table
new_string is the string you want to add at the top
This is for a string table of length 64 (indexes 0 through 63) like Mary’s example.

1 Like

Hi Philip,

Right, exactly what I did. And it went fine. But still curious why they did not decide to make a command for it.

philip
In ideal situations, how long do you think it takes to execute your example code and add the new string? (for this example, let’s say the max string length is 120 characters and each string has exactly 120, using an R1 Brain) Any guess on that?

2nd post, I replied to the wrong person.

I would need to test it, but I would think it would be around 10ms or so.