Cumulative running time for an output

I want to measure and collect the running time of an output, for a day/week/month.

I tried this:


when the output is ON, it adds the time as expected.

when the output is stopped,the running time is still in the P1R variable (set as a time), but if OUT1 is ON again, the time is reset

If I set the P1R variable as minutes or seconds or unused, the result is the same, self reset when OUT1 becomes OFF

How can I add running times to running times to obtain a cumulative value (for maintenance schedule btw) ?

Good application Mike, this program should do it:
10 IF INTERVAL(0:0:01) AND OUT1 THEN P1R = P1R + 0:0:01

The INTERVAL statement triggers once every second, if output1 is on at that time then the run timer will be incremented. Otherwise the line doesn’t fire at all and the timer stays where it was. The P1R variable should be in the units of time.


Thanks again Maurice.
I created 1 (time) variable and 3 virtual counters (seconds, minutes and hours) to memorize the running time, in case the T3 reboots or loses power. If I understand correctly, variables are erased but not counters. Few code lines and voilà, it works as expected.

1 Like

Actually if you use the TIME range for the units on the variable you can store the hours minutes and seconds in a single variable instead of the three separate variables.

Maurice Duteau

1 Like

Indeed. But I separated them because I had problems to send the time value to my plc and node-red (int16). I’m a lazy guy, so I made those 3 virtual counters to retrieve the important one (hours of working) and poll directly that float with my plc / node-red, without any strange conversion :slight_smile:

Please confirm also that variables could be erased in case of T3-xx reboot but values are kept if stored as counters

The vars are stored through a power cycle, yes. The unit stores intermittently so you might loose a few minutes of logging is all.

Maurice Duteau

1 Like