News:

  • October 17, 2026, 07:55:57 PM

Login with username, password and session length

Author Topic: Retrieve Values from fifo  (Read 13409 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Retrieve Values from fifo
« on: March 22, 2021, 03:54:15 PM »
What is the best way to retrieve the 20 newest values from a fifo data block with 1000 values. It seems like i can't use fifo.head or .tail as a reference.
« Last Edit: March 24, 2021, 12:59:18 AM by PLCwannabe »

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6177
  • Yes Pinky, Do-more will control the world!
Re: Retrive Values form fifo
« Reply #1 on: March 22, 2021, 04:04:37 PM »
What is the best way to retrieve the 20 newest values from a fifo data block with 1000 values. It seems like i can't use fifo.head or .tail as a reference.

Look at? Or remove from the queue?
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3628
  • Darth Ladder
Re: Retrive Values form fifo
« Reply #2 on: March 22, 2021, 07:35:06 PM »
I ended up invoking NBH (Not Built Here), and did my own.   I always use the front of the range rather than rotating loading and unloading positions through the block and physically move the values, and I also include bubbling up past empty positions, so you can introduce new entries at any empty location and it will find the end of the line and stop (I do try to load directly to the correct location to minimize/eliminate the amount of required packing/bubbling)

With auto-bubbling enabled on detection of unpackedness, you can remove as many records as you want and the rest will just deal with it.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3628
  • Darth Ladder
Re: Retrive Values form fifo
« Reply #3 on: March 22, 2021, 07:38:34 PM »
Unpackedness is detected like this:

Assume you have a 100-slot FIFO, FIFODATA

Then V0 = COUNTIFNE(0, FIFODATA0, 100)

and  V1 = COUNTIFNE(0, FIFODATA0, V0)

If V0 == V1, then it's packed.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Retrive Values form fifo
« Reply #4 on: March 22, 2021, 08:45:30 PM »
I want to store the last 1000 values at all times, but then i need to display the 10 newest values on Hmi. So i don't want to remove the values, I just want to view them.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3628
  • Darth Ladder
Re: Retrive Values form fifo
« Reply #5 on: March 22, 2021, 08:53:49 PM »
I think Host's FIFO has a public member variable that tells you where the current load point is.   IIRC, .head and .tail are fixed at the limits of the range (I think).   Seems like that should work for you.   Look at the long form display of the FIFO control structure in Data View, and I think it will show the unload position, whatever the name is.

Sounds like for what you're doing, my way is more work than it would be worth.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Retrive Values form fifo
« Reply #6 on: March 22, 2021, 09:27:19 PM »
I want to store the last 1000 values at all times, but then i need to display the 10 newest values on Hmi. So i don't want to remove the values, I just want to view them.

Your Memory Block "FIFOValues" would be 1000 in size.  When the FIFO needs to load a new value, you will want to FIFOUNLOAD a value out (and "throw it away"), and then FIFOLOAD the new value in there.  Your most recent values should all be at FIFOValues0 ... FIFOValues10 if I see your scenario correctly?  These values can be displayed on your HMI.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3628
  • Darth Ladder
Re: Retrive Values form fifo
« Reply #7 on: March 22, 2021, 09:41:41 PM »
That's what I'd have assumed too, but I don't think that's how it works.  I believe that instead of moving the values they keep track of the offsets to the newest and oldest values (and the current count of values)
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Retrive Values form fifo
« Reply #8 on: March 22, 2021, 10:01:38 PM »
I stand corrected, I just checked.  Once the FIFO is .Full, you can reference FIFOValues989...999?  If not .Full, then some MATH V0 equals FIFO.Head-10, then FIFOValues[V0], followed by V0+1, etc.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Retrive Values form fifo
« Reply #9 on: March 23, 2021, 09:43:54 AM »
I was trying to indirectly address FifoValues[Fifo.head], but that didn't work. But I guess I can move the Fifo.head value to a v location and then use that as indirect reference.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6177
  • Yes Pinky, Do-more will control the world!
Re: Retrive Values form fifo
« Reply #10 on: March 23, 2021, 09:57:51 AM »
I was trying to indirectly address FifoValues[Fifo.head], but that didn't work. But I guess I can move the Fifo.head value to a v location and then use that as indirect reference.

It works in a MATH box.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6177
  • Yes Pinky, Do-more will control the world!
Re: Retrive Values form fifo
« Reply #11 on: March 23, 2021, 10:07:00 AM »
A few points about our implementation...

For LIFOs, the Tail always remains at 0.

FIFO's are ring buffers, so both Head and Tail move. Performance. I worry about it so you don't have to.

When FIFO is empty, Head/Tail always reset to 0. In a random Add/Remove FIFO, Head and Tail can wrap, but in a batch Add/Remove, it won't wrap.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO