14 Replies Latest reply on Jun 8, 2013 3:45 PM by mhamel

    Calculate Hourly Counts from a PLC Counter


      In the system we are finalizing install on I have a need to setup what I thought would be a simple calculation, but it is not turning out that way.  I was hoping someone could give me some ideas on the best way to do this.




      PI - 2012, with AF (not relevant, but maybe if someone thinks I should use AF or Event Frames to solve the problem).


      PI is connected via OPC interfact to an OPC server that is reading data from a Rockwell ControlLogix PLC.


      The counter that I am dealing with a simple one.  It takes a photo eye and counts boxes as they pass by.  The value of this counter is read by PI.  So the number starts at zero (after a reset) and increments by 1 as boxes go by.  The scan time is set to 10 seconds, so most of the time it goes up by 1 every scan, but sometimes it might be 2 or 3 depending on which line and how fast it is.


      The operator has a reset button to reset the counter (start a new order)...actually there are two resets that are in paralell, either one does the same thing (reset the counter to zero and sets a reset bit for PI to read (holds it on for 10 seconds).  One reset button is hardwired to the PLC, the other comes as an output from PI set in ProcessBook (so the operator normally presses the button on Processbook, but if PI were down we could still run just using the hard reset button).


      Exception deviation is set to 1, compression deviation is set to 2.  Once a line is running steady, the boxes are failry consistent so compression does a pretty good job.


      Now the problem:


      I need to display to the operator the number of boxes made in the last hour (or any previous hour).  This would be easy if there were no resets...just take the count at the start of the hour and the count at the end and subtract them.  However, since the operator can reset the thing (multiple time per hour sometimes) I can't seem to figure a good way to get this data.


      For example, starting at hour 1 lets say the counter is 10, it runs up to 60 and is then reset. Runs up to 40 is reset and then continues to run and at the end of hour 1 is at 160.


      The math I need is:


      (60 - 10) = 50


      50 + 40 + 160 = 250 counts in hour 1.


      I tried setting a tag that looks at the difference between the previous value (PrevVal) and calculates difference to current value..thinking that tag would then hold a running count difference that could sum over the hour with a totalizer.  However, the exception and compression plays heck with that theory as PrevVal only looks at the archive and since these lines pretty steady, it only archives numbers every several mins or so on average.  I did try setting exception and compression deviation to zero...which worked fairly well, but then I got 8,640 archives a day per tag (there are currently 19 tags and it will go up as we add lines), so that seemed like hard work on the archive to store data that is easily compressable.


      Any ideas on how to accomplish this?  It seems such a simply thing that I must just be missing here.







        • Re: Calculate Hourly Counts from a PLC Counter
          Roger Palmen

          Although it's not an answer to your question, why don't you count the boxes in the PLC? 100% certain to work, and should be standard work for any PLC and/or PLC programmer.


          Within PI, the only solutions i know should use ACE or Totalizers. For a Totalizer you can set that to ignore events that reset the counter to zero. Refer to the PI Server Applications User Guide for details. I'm know very proficient with Totalizers, but i'm certain someone around the forum can dish out some settings for a Totalizer fairly quickly, as this is a common scenario.

            • Re: Calculate Hourly Counts from a PLC Counter

              Thanks for the reply.  That is an option I am considering.  I originally thought it would be pretty simple in PI to handle it, but I am finding out it's not.  The one issue I have is that the PLC times do not line up correctly (there is no system to maintain time syncronization on the PLC networks) and the further they get off, it becomes an issue lining up with the rest of the production tracking system (running in PI and AF).


              If anyone can give me some pointers on how a totalizer tag might be setup to handle this, I would give that a whirl (or any other ideas for that matter)



                • Re: Calculate Hourly Counts from a PLC Counter

                  Hello Eric,


                  PI Totalizer allows counting events (snapshots). For this purpose it maintains an own snapshot table (pilasttot_t.dat) for those raw data points used with non-forever totalizer tags.


                  I've created an example that I believe should work for your use case. There are so many screws to drive with PI Totalizer tag configuration that it usually takes some time to evaluate a good configuration. When applying a configuration change, it takes until the next reset until a tag is serviced with results.


                  I was using PI SMT Totalizer plug-in to create the tag and maintain the configuration.


                  To achieve that the counter reset is not taken into consideration, I have selected to count "Time when TRUE" with the following equation:




                  with 'Counter' referring your DCS counter.