Digital Counter and calculate elapsed time for a channel in certain state

Forum Home Forums Understanding the Software Using Formulas Digital Counter and calculate elapsed time for a channel in certain state

Tagged: ,

This topic contains 7 replies, has 2 voices, and was last updated by Mikhail Mikhail 2 months, 1 week ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #5663
    Avatar
    Eyad
    Participant

    Hi,

    I would like to know if we can calculate the elapsed time for a channel in state.
    for example, if a discrete channel changed from False to True then after sometime changed to False again. Can we use formula to calculate the elapsed time for the channel being in in True State?
    Also can we use formulas to make a digital counter so that we can calculate how many times channel changed from state to another state for example False to True? I mean when state changed from False to True, just count 1 and accumulate that counter.

    Thank you and highly appreciated your support.

    #5668
    Mikhail
    Mikhail
    Moderator

    Hi,

    Can we use formula to calculate the elapsed time for the channel being in in True State?

    How many times a day a channel may change?
    The simplest approach is:
    1. Create an input channel of Minute real type.
    2. Use a formula Val(101) > 0 ? Val() + 1 : Val()
    where 101 is the source channel that can be 0 or 1
    The formula is calculated every minute for this type of channel.

    But this approach is not accurate.

    can we use formulas to make a digital counter so that we can calculate how many times channel changed from state to another state for example False to True?

    Just choose Switching counter type of the input channel. And it will count.

    #5674
    Avatar
    Eyad
    Participant

    Hi,

    Thank you very much.
    the elapsed time calculation based on 1 minute interval will not be accurate but it is acceptable for us.

    for digital switching counter, how to decide the state change to trigger counting? i mean if we need from False to True to do counting as an example.
    as i understood, switching counter will count whenever there is a change in the state. Please correct if i’m wrong.

    appreciate highly your support.

    #5678
    Mikhail
    Mikhail
    Moderator

    Hi,

    A channel of the Switching counter type increases by 1 when the channel changes from 0 to 1 and from 1 to 0.
    You should check it using the Generator feature when Communicator is stopped. Please write here about the result.

    #5679
    Avatar
    Eyad
    Participant

    Hi,

    Let me first clarify what I have done.

    I defined a channel to show status of Pump of Type Real, signal 114, reading signal from controller using Modbus. I received the signal a,d I have no issue in that.
    To count number of pump starts, i created a new channel in the device input channels, name it as “Pump starts count”, Channel Type: switching counter and Signal selected is the same 114.
    Results, first channel to show status “which was working” become uncertain – grey color. Not updated, and new counter switching channel just counted 2 and never changed then despite pump started physically many times after that.

    Hope I didn’t do anything wrong or misunderstood you.

    By the way, i need the counter only to work when channel switch from 0 to 1 only.

    Thank you

    #5680
    Mikhail
    Mikhail
    Moderator

    Hi,

    Try the following:
    The new channel of the Switching counter type should have a formula Val(114)
    Its Signal field is not set.

    If the above doesn’t help, please provide a link to the screenshot of the Input channels table.

    #5681
    Avatar
    Eyad
    Participant

    Hi,

    Thank you for your support.
    I tried that, it s working fine. The only remaining issue is that, it counts when channel switch change from 0 to 1 and from 1 to 0.
    How can we limit the counter to work only when switch change from 0 to 1 ONLY.

    Thank you

    #5684
    Mikhail
    Mikhail
    Moderator

    Hi,

    Other approach is creating your own formula (in the Formulas table) like this

    function double CalcSwitch(int counterCnlNum)
    {
      if (Val() <= 0 && Cnl > 0 && Stat > 0)
      {
        SetVal(counterCnlNum, Val(counterCnlNum) + 1);
      }
      return Cnl;
    }

    Use this formula in the channel 114: CalcSwitch(115)
    where 115 is the channel for counting, its type is Calculated real.
    Note: I don’t test formulas on the forum. May be you need to fix it.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.