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: ,

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #5663
    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
    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
    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
    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
    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
    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
    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
    Moderator

    Hi,

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

    public double CalcSwitch(int counterCnlNum)
    {
      if (Val() <= 0 && Cnl > 0 && CnlStat > 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.

    • This reply was modified 1 year, 5 months ago by Mikhail.
    • This reply was modified 1 year, 5 months ago by Mikhail.
    #7175
    OtavioF
    Participant

    Good day.

    Keeping on the same topic subject, there is a way to reset a Switching Counter type channel back to zero?

    #7177
    Mikhail
    Moderator

    Hi,
    Try the following:
    Open Administrator – Server – Generator and send a new value to the appropriate input channel with status 1.
    Does it help?

    #7179
    OtavioF
    Participant

    Yes! It worked. Thanks a lot, Mikhail!

    #7227
    hethongscada62
    Participant

    Hello Eyad,
    Did you test the Switching Counter formula suggested by Mr. Mikhail?
    The formula was tested on my installation, but i can not get any result.
    Could you help me?
    Thank you in advance
    Han Hoang

    #11337
    gabeirinhas
    Participant

    Hello,

    I am trying to use this formula in the formula table,

    To have a counter each time it changes state 1 – 0

    I get an error on the server,

    The only way to get the server to accept it is to delete certain conditions but it still doesn’t work,

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

    Some formula available to make a counter that counts each time a channel changes state from 1 – 0, instead of using counter type, which counts both states,

    Thanks in advance

    #11356
    Mikhail
    Moderator

    Hello,

    The only way to get the server to accept it is to delete certain conditions but it still doesn’t work,

    The formula suggested above differs from the formula you posted. Try the original one. In case of errors, provide the error information.

    #11373
    gabeirinhas
    Participant

    Ok,

    If I use the formula

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

    “error CS1519: The token ‘double’ is invalid in a class, struct, or interface member declaration.”

    >

    If I use the formula

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

    Line 516, column 32: error CS0019: Operator ‘>’ cannot be applied to operands of type ‘method group’ and ‘int’.

    >

    Thanks in advance, best regards

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.