Sign in to follow this  
Followers 0
waterboy

String Array History

14 posts in this topic

Using Compactlogix... I have a Tag of String[50] that timestamps a series of events. I need to create a 20 element history of these Arrays so I created a tag like StringHistory[50,20] The FFL/FFU instructions look more like a stack, pushed and popped as needed. I just need to push, never pop. Using that analogy, what I need is to push stuff in the top and let it fall out the bottom i.e. push something into element 0 and the previous contents get pushed to element 1 etc. This will give me a 20 event history of these timestamps. Is there a command I am not seeing that will do this or will i need to do this in a for/next type of loop ?.

Share this post


Link to post
Share on other sites
MAVE kind of does that except that I can never tell where in the array that it's going to start. MAVE is moving average. To create the moving average it grabs data and puts it in a an array. It's probably not going to work for you but that was the first thing that I thought of. Couldn't you do what you want to do with compares and a pair of MOVW?

Share this post


Link to post
Share on other sites
MOVW ? Can't locate that instruction. Not in Compactlogix (v17) perhaps?

Share this post


Link to post
Share on other sites
I use the FFL/FFU instructions for that sort of thing. I just monitor the ".LEN" element of my control, and when the stack is full, I pop a value before adding one. Since it's a FIFO, the popped value will be the oldest datum, which you can discard.

Share this post


Link to post
Share on other sites
Can you show me that?

Share this post


Link to post
Share on other sites
I'll try to get something together shortly.

Share this post


Link to post
Share on other sites
Thanks, doesn't have to work, I just need to see the idea.

Share this post


Link to post
Share on other sites
How often do you intend to push new items into the stack? The problem I see is if the stack is always full you have to unload an item first (FFU) then all the items get shifted up one. This could be the equivalent worst case of moving ((82 SINT's for the string data) + 1 DINT for string length) * 50) = 2100 DINT's This means the equivalent of 2100 DINT's have to be shifted up 1 slot in the stack 49 times to make room for the new data. I think it may be better to implement a circular queue so you are only overwriting the oldest data with the newest.

Share this post


Link to post
Share on other sites
A Circular Queue sounds like what I am after. Its a lot of data moving around, This might wind up being a bad idea because of all the processing involved, but it only happens once every couple days. I need to give it a shot.

Share this post


Link to post
Share on other sites
I didn't pay attention to the quantity of data, and I'm inclined to agree that a circular queue would be more efficient. It should be pretty easy to implement, just create an tag that is your pointer, and use two instructions each time you want to add a new piece of data: COP TimestampCurrent[0] TimestampHistory[0,Pointer] 50 ADD Pointer 1 Pointer Your Pointer tag then provides the location of the newest timestamp. This method is more efficient for the processor, though it would be more difficult to display the array on an HMI because of the moving target of which data is the oldest. By the way, note that in RSLogix 5000 you aren't stuck with 82 character strings. You can create user defined string data types of any length up to 82. I had an application where we had so many strings we started running out of room in the processor. I switched everything to 20 character strings, and suddenly everything fit again!

Share this post


Link to post
Share on other sites
Actually 1 to 65535 characters..

Share this post


Link to post
Share on other sites
I got this done with a loop and COP. it works well enough for my needs. Thanks for the feedback guys.

Share this post


Link to post
Share on other sites
@daba Thanks for the correction. It makes sense that they'd allow longer than 82 characters. Since I have never needed more, and usually need far less, I didn't double check!

Share this post


Link to post
Share on other sites
JRoss has a better way. MAVE is Moving Average. I don't recall if it's in V17 or not

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0