2 Replies Latest reply on Dec 19, 2012 9:48 PM by MIPAC

    Lifetime Counters

    Steve Boyko

      One of our clients has a set of PI tags that count the total amount of electricity consumed (in kWh or MWh). They reset occasionally to zero and we want to have PI tags that contain a non-resetting value, e.g. they keep accumulating even after the source tag resets to zero.

       

      I built some Performance Equations to handle this, and they work pretty well, but not perfectly.

       

      The basic algorithm is:

       
      if 'source' = PrevVal('source', '*') then    ' no change
         NoOutput()
      else
         if 'source' < PrevVal('source', '*') then   ' reset
            'lifetime' + 'source'
         else    ' normal accumulation
            TagVal('lifetime', PrevEvent('source', '*')) + 'source' - PrevVal('source', '*')
         end if
      end if
      

       

       

      The problem is that the 'source' tag will reset to zero for a few minutes when they update the PLC that is generating these values. This causes the lifetime counter to reset and then jump ahead when the source value returns to a normal value.

       

      Am I overcomplicating this? Is there a better way / better tool for this in PI?

        • Re: Lifetime Counters
          Roger Palmen

          Steve,

           

          I'm not good at all in PE, but i can read pseudo code...

           

          I would change the algorithm to add the difference in values between the current and previous value of the source tag to the lifetime counter. But only if the current value fo the source tag > the previous value.

           

          As such (and removing code that do not add functionality):

           
          if 'source' > PrevVal('source', '*') then ' normal accumulation
             TagVal('lifetime', 'lifetime' + ('source' - PrevVal('source', '*')))
          else
             NoOutput()
          end if
          

           

          • Re: Lifetime Counters
            MIPAC

            Steve,

             

            Normally I would see this as a job for a Totalizer tag, using the InFromTotalizer option to handle the source tag accumulation reset ("Source tag is a DCS integrator" option in the Totalizers plugin of PI System Management Tools). You can achieve a similar result using Performance Equations or PI-ACE code, but I think Totalizers are the better option for this type of task.