You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old February 9th, 2018, 11:57 PM   #1
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 204
Any other alternate of FIFO

Hello Guys,

I am just wondering if there is any other alternative of FIFO. I am trying to record the value which changes after a couple of seconds and I want to keep the record of last 10 values. What other option do I have? Any suggestion and I will write a logic then and can show you.

Thank you,
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old February 10th, 2018, 12:35 AM   #2
bernie_carlton
Lifetime Supporting Member + Moderator
United States

bernie_carlton is offline
 
bernie_carlton's Avatar
 
Join Date: Apr 2002
Location: Yakima, Washington
Posts: 6,172
A FIFO seems like the most logical choice. If you want to store a new value in the FIFO only when the value changes then proceed the FIFO rung with one that compares the present value with one stored previously. If they are unequal then turn on a bit and store the new value in the 'previous' location. Use the bit to trigger the shift/store of the FIFO with the new value as the data.
__________________
Controlling outputs is the PLC's way of getting its inputs to change.

www.thePLCguy.com
  Reply With Quote
Old February 10th, 2018, 06:12 AM   #3
janner_10
Supporting Member
United Kingdom

janner_10 is online now
 
Join Date: Dec 2014
Location: Tewkesbury
Posts: 470
You can roll your own using a pointer to an array, as above, the FIFO is a great choice.
  Reply With Quote
Old February 10th, 2018, 06:54 AM   #4
Aardwizz
Member
United Kingdom

Aardwizz is offline
 
Aardwizz's Avatar
 
Join Date: Dec 2017
Location: Swindon
Posts: 73
It all depends on what your're trying to do.

A FIFO is great when you have a variable number of data points, and/or the trigger to unload data is different from the trigger to load data.

But it sounds like you just want to smooth out a signal by averaging the last bunch of data points. For that, you don't need a FIFO, simple shift logic works.

The timer isn't strictly necessary, if you want to capture data every scan, or if the logic is in a periodic task.

The Array can be much bigger than 10; then by adjusting the value of the "Len" tag, you can set how many data points you want to collect, without having to edit the logic. (Caution: make sure that Len < the size of the array, or the PLC may fault). (Caution #2: increasing the Len on the fly makes the result unreliable until the array has gotten fully populated).

An alternative technique is, instead of shifting all the data, is to use indirect addressing, and increment a pointer each Update, resetting when it reaches the maximum sample size. It's arguably a better technique in terms of PLC speed, but I like being able to watch the data shift, rather than see new data appear somewhere in the array, and my processes generally don't need millisecond precision.
Attached Images
File Type: jpg FIFO.jpg (27.9 KB, 122 views)
  Reply With Quote
Old February 10th, 2018, 08:52 AM   #5
AustralIan
Member
United Kingdom

AustralIan is online now
 
Join Date: Jan 2013
Location: UK
Posts: 597
10 move instructions will roll your own FIFO, but it is still technically a FIFO.

If the values were every second, you could install a mirror every 150,000km and just use those to check previous values. Either a very bright screen or operate in space. You might need a lens also.

You could also make up random values, and say they are 'close enough for what we use it for'.

I am about out of ideas.
  Reply With Quote
Old February 10th, 2018, 01:30 PM   #6
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 601
It looks like you just want to store the last 10 values
a FIFO will work very well for that but with a FIFO you need to both load and unload it. So with every load you must have an unload or the array file will fill up.
try a file shift just 2 rungs of code and you don't have to unload it the old data just rolls off the top as the new data is loaded
i hope the attached pi will help to understand it
i have used this a few times and it works good.
the one shown is much larger then the 10 entries you need but with a littler modification it should work for you

File Shift.jpg
  Reply With Quote
Old February 10th, 2018, 02:24 PM   #7
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 9,520
Quote:
Originally Posted by Aardwizz View Post
It all depends on what your're trying to do.

A FIFO is great when you have a variable number of data points, and/or the trigger to unload data is different from the trigger to load data.

But it sounds like you just want to smooth out a signal by averaging the last bunch of data points. For that, you don't need a FIFO, simple shift logic works.

The timer isn't strictly necessary, if you want to capture data every scan, or if the logic is in a periodic task.

The Array can be much bigger than 10; then by adjusting the value of the "Len" tag, you can set how many data points you want to collect, without having to edit the logic. (Caution: make sure that Len < the size of the array, or the PLC may fault). (Caution #2: increasing the Len on the fly makes the result unreliable until the array has gotten fully populated).

An alternative technique is, instead of shifting all the data, is to use indirect addressing, and increment a pointer each Update, resetting when it reaches the maximum sample size. It's arguably a better technique in terms of PLC speed, but I like being able to watch the data shift, rather than see new data appear somewhere in the array, and my processes generally don't need millisecond precision.
+1

This guy nailed it...
__________________
It's not all the variables I am most concerned with, it's the undiscovered constants.
  Reply With Quote
Old February 10th, 2018, 02:41 PM   #8
Mispeld
Member
United States

Mispeld is online now
 
Join Date: Feb 2017
Location: VA
Posts: 239
Quote:
Originally Posted by OkiePC View Post
+1

This guy nailed it...
Yeah. One follow-up question: Why the reset immediately before the AVE instruction? While I am a fan of defensive programming, I am wondering what unintended situation this reset prevents.
  Reply With Quote
Old February 10th, 2018, 02:47 PM   #9
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 9,520
Quote:
Originally Posted by Mispeld View Post
Yeah. One follow-up question: Why the reset immediately before the AVE instruction? While I am a fan of defensive programming, I am wondering what unintended situation this reset prevents.
Yes, that part of his example is redundant. The RES would be necessary if the timer was retentive. His description of when and why to use a FIFO is spot on though.
__________________
It's not all the variables I am most concerned with, it's the undiscovered constants.
  Reply With Quote
Old February 10th, 2018, 03:48 PM   #10
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 204
Quote:
Originally Posted by bernie_carlton View Post
A FIFO seems like the most logical choice. If you want to store a new value in the FIFO only when the value changes then proceed the FIFO rung with one that compares the present value with one stored previously. If they are unequal then turn on a bit and store the new value in the 'previous' location. Use the bit to trigger the shift/store of the FIFO with the new value as the data.
Thank you for the reply, I ended up using FIFO and I agree with you FIFO is the best solution but I was just wondering If I can learn a technique to store last 10 or whatever values of my tag.

Thank you again.
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old February 10th, 2018, 03:50 PM   #11
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 204
Quote:
Originally Posted by Aardwizz View Post
It all depends on what your're trying to do.

A FIFO is great when you have a variable number of data points, and/or the trigger to unload data is different from the trigger to load data.

But it sounds like you just want to smooth out a signal by averaging the last bunch of data points. For that, you don't need a FIFO, simple shift logic works.

The timer isn't strictly necessary, if you want to capture data every scan, or if the logic is in a periodic task.

The Array can be much bigger than 10; then by adjusting the value of the "Len" tag, you can set how many data points you want to collect, without having to edit the logic. (Caution: make sure that Len < the size of the array, or the PLC may fault). (Caution #2: increasing the Len on the fly makes the result unreliable until the array has gotten fully populated).

An alternative technique is, instead of shifting all the data, is to use indirect addressing, and increment a pointer each Update, resetting when it reaches the maximum sample size. It's arguably a better technique in terms of PLC speed, but I like being able to watch the data shift, rather than see new data appear somewhere in the array, and my processes generally don't need millisecond precision.
Great! Thank you! I will give it a try when I will go back to work.

Thank you again,
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old February 10th, 2018, 03:52 PM   #12
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 204
Quote:
Originally Posted by GaryS View Post
It looks like you just want to store the last 10 values
a FIFO will work very well for that but with a FIFO you need to both load and unload it. So with every load you must have an unload or the array file will fill up.
try a file shift just 2 rungs of code and you don't have to unload it the old data just rolls off the top as the new data is loaded
i hope the attached pi will help to understand it
i have used this a few times and it works good.
the one shown is much larger then the 10 entries you need but with a littler modification it should work for you

Attachment 46838
Thank you
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old February 10th, 2018, 03:52 PM   #13
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 204
Thank you everyone for the reply and suggestions. Daammmnn you guys are very supportive
Thank you
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old February 10th, 2018, 08:57 PM   #14
Aardwizz
Member
United Kingdom

Aardwizz is offline
 
Aardwizz's Avatar
 
Join Date: Dec 2017
Location: Swindon
Posts: 73
Quote:
Originally Posted by Mispeld View Post
Yeah. One follow-up question: Why the reset immediately before the AVE instruction? While I am a fan of defensive programming, I am wondering what unintended situation this reset prevents.
File instructions (FAL, FSC, AVE, etc.) set a .DN bit, and don't re-execute until the bit is reset, typically by a true-to-false transition. The timer .DN bit does that, so yes, as written, the RES is not needed.

But I also suggested that the TON could be removed if one wanted to capture data every scan, or if the code were in a periodic task. In that case, there'd be no true-to-false transition, so the RES of the AVE control word is needed.

Side note: many people don't realize that you can use an RES on file control elements ('R' data types in PLC5/SLC). They do the same thing there as in timers & counters: clear the various bits (.DN, .FD, etc.) reset the accumulator (.POS), while leaving the preset (.LEN) alone. Clean technique.
  Reply With Quote
Old February 11th, 2018, 10:20 AM   #15
Pete.S.
Member
United States

Pete.S. is offline
 
Join Date: Mar 2016
Location: Fl
Posts: 417
The alternative to the FIFO buffer is called a ring buffer or circular buffer.

It's much faster to execute for the CPU so it's the standard type of buffer for almost everything that has a CPU (PLC, computer, phone etc).
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
FIFO Reset ASF LIVE PLC Questions And Answers 2 March 10th, 2015 04:14 PM
FIFO dilemma jakeemon LIVE PLC Questions And Answers 21 August 6th, 2013 09:22 AM
fifo for 2 machines James Mcquade LIVE PLC Questions And Answers 64 September 14th, 2011 08:38 AM
Fifo ssrmr2 LIVE PLC Questions And Answers 3 April 19th, 2006 05:08 PM
FIFO Check The_Wanderer LIVE PLC Questions And Answers 1 October 15th, 2003 06:44 AM


All times are GMT -5. The time now is 08:02 AM.


.