Announcement

Collapse
No announcement yet.

A Question on Finding Averages using Productivity PLCS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts


  • A Question on Finding Averages using Productivity PLCS

    I need to find the average of a changing analog input value over a period of time (In the case, the average current usage of a circuit over the course of a minute). After a minute, I would need that average value to be spit out on an HMI, whereupon the average would be calculated again and the previous value would be overwritten. In this way, I would be able to find an average present current usage by my application. Does anybody have any idea of how to accomplish this?


  • #2
    option 1:
    Put an "average" instruction in and the input would be your analog tag. Output is a tag you want displayed. Set the time to 60,000. This will just keep an average going constantly of the past 60 seconds and your HMI will read this value. It should be quite stable with such a long averaging time.
    If necessary, have a second average instruction with the same input and the same output tags. Set the time of this second averaging instruction to be only 2 seconds. Make a timer so that when your press the "run" button on the machine it starts a 60 second timer, when that timer is done it sets on a tag. That tag swaps between the 2 second average and 60 second average. Allowing you to use a quicker averaging time at initial start and initial stop, while using the long 60 second time that you want while the machine is running. You can see how to do this in the attached screenshot.

    Click image for larger version  Name:	averaging.png Views:	1 Size:	14.7 KB ID:	118428



    option 2:
    Put a flasher instruction in with a 1 second time. On the next line use a normally open edge contact on the rising edge with the tag being your 1 second flasher, and have that go to a shift/rotate array instruction. The input to this is your analog tag. Next line make a normally open rising edge contact with the 1 minute bit. Have that go to an array statistics instructions. The input is your array you are using, start column 1, end column 60. Output tag is the tag you want displayed on the HMI. With this instruction you can choose which type of averaging you want as well, a straight average or the median average. This setup will record the analog current value every second and then every 60 seconds will tell you the average of the last minute. See the next screenshot for what it looks like:

    Click image for larger version  Name:	image_3555.png Views:	1 Size:	13.0 KB ID:	118429





    Strengths of option1 would be that it is continuously updating, and shows you faster changes at beginning of machine startup when motors are typically drawing extra current. That will let you see this extra current draw more easily before switching to a long average.
    Weakness of optioin1 is that you are not keeping a data log, just displaying data. You cannot manipulate it or do things with the data as easily.


    Strengths of option 2 are easier to read logged data, you can make the array larger and keep a very long log, and send that log data to the office if needed. You can also see other types of averages that may give you a more clear picture of things.
    Weakness of option 2 is that it is only taking snapshots of the current draw, so you are missing small spikes or dips, and not seeing initial power draws and such.
    You can however mitigate option 2 weaknesses somewhat by feeding the data log every 250 milliseconds (4 times a second) and having a second array statistics that is set to display the maximum value within the array/log every minute. This will hopefully record initial power spikes and display that maximum draw value for you.
    Last edited by MikeN; 10-10-2018, 10:00 AM.

    Comment



    • #3
      MikeN, first I would like to thank you for your very detailed and thorough answer on this subject. Secondly, I believe that the 2nd option with the array is what I'm looking for - but I'm having an issue with the end index on it - it won't let me type in a number other than one - any fix for this?

      What I really need is something like this:

      sample once every (second, 5 seconds, set amount of time) during the course of a minute
      store these samples
      sum these samples
      divide by the number of samples taken over the course of that minute
      display on screen and hold that value until the calculation repeats itself
      then replace the value, and continue this cycle until the machine is turned off.
      Last edited by Cheeraxe1999; 10-10-2018, 09:30 AM.

      Comment



      • #4
        Originally posted by Cheeraxe1999 View Post
        MikeN, first I would like to thank you for your very detailed and thorough answer on this subject. Secondly, I believe that the 2nd option with the array is what I'm looking for - but I'm having an issue with the end index on it - it won't let me type in a number other than one - any fix for this?

        What I really need is something like this:

        sample once every (second, 5 seconds, set amount of time) during the course of a minute
        store these samples
        sum these samples
        divide by the number of samples taken over the course of that minute
        display on screen and hold that value until the calculation repeats itself
        then replace the value, and continue this cycle until the machine is turned off.
        When you created the tag for the array, you most likely did not tell it to be more than 1 column. It is tricky to remember. When you told the shift/rotate instruction its info and then clicked accept, a window pops up asking for the data the array tag should have. Way to the right of this box there is a section that says "columns" and it defaults to 1. This needs to be changed to 60+ to give the array for data columns to store the data in. 60 is all thats really necessary if you store data once a second and calculate the past minute. You can always go larger though if you want a longer history stored for any reason. To change the already created tag, look it up in the tag database and change the column number to something greater than 1.

        This array and statistics instruction will do everything you want, but another way to do it would be to use a math instruction that goes on once a minute. Insert all your column tags from the array for the past minute with them all added together, and then divide by the number of samples you took from the past minute. That is really just the long way of writing out what the array statistics instruction is doing though.

        Comment



        • #5
          That worked perfectly! Thanks you! I would never have seen the column instruction.

          Comment

          Working...
          X