Forum Home › Forums › Understanding the Software › Using Formulas › Digital Counter and calculate elapsed time for a channel in certain state
- This topic has 16 replies, 5 voices, and was last updated 1 year, 10 months ago by gabeirinhas.
-
AuthorPosts
-
July 3, 2019 at 11:39 am #5663EyadParticipant
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.
July 4, 2019 at 6:25 am #5668MikhailModeratorHi,
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.
July 4, 2019 at 7:18 am #5674EyadParticipantHi,
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.
July 5, 2019 at 1:30 pm #5678MikhailModeratorHi,
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.July 5, 2019 at 3:28 pm #5679EyadParticipantHi,
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
July 6, 2019 at 10:22 am #5680MikhailModeratorHi,
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.
July 6, 2019 at 2:40 pm #5681EyadParticipantHi,
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
July 7, 2019 at 7:15 am #5684MikhailModeratorHi,
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.August 17, 2020 at 7:08 pm #7175OtavioFParticipantGood day.
Keeping on the same topic subject, there is a way to reset a Switching Counter type channel back to zero?
August 18, 2020 at 12:25 pm #7177MikhailModeratorHi,
Try the following:
Open Administrator – Server – Generator and send a new value to the appropriate input channel with status 1.
Does it help?August 18, 2020 at 6:52 pm #7179OtavioFParticipantYes! It worked. Thanks a lot, Mikhail!
September 1, 2020 at 1:43 pm #7227hethongscada62ParticipantHello 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 HoangOctober 22, 2022 at 9:45 am #11337gabeirinhasParticipantHello,
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
October 24, 2022 at 9:54 am #11356MikhailModeratorHello,
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.
October 24, 2022 at 1:17 pm #11373gabeirinhasParticipantOk,
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
-
AuthorPosts
- You must be logged in to reply to this topic.