# 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 12 posts - 1 through 12 (of 12 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

``````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.

#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

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