FiFo register to store numeric values


#1

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

Regards / Lennart


#2

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.


#3

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.


#4

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


#5

No Shift command for String Tables??


#6

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;


#7

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.


#8

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.


#9

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?


#11

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.