Good morning,
I would like advice on how to calculate the availability of a tool on a monthly basis.
The variable to monitor is a bool related to the state of a switch (Switch1_ON). The calculation should be
Availability=(Tempo_ON/Tempo_Tot)*100
How would you do it?
Thank you very much and sorry for the bad English
Hello!
As I could understand, you try to deal with calculating of working hours for some equipment…
Take a look at attached project for IDE 2023.0.3 LST
MONTHLY_OPH_CNT.7z
Best regards.
Perfect thank you very much. The only thing I saw that your program starts with a low value and towards the end of the month in theory if the machine is always on it reaches 100%. I would need to start from 100% and if the car stops for 1 hour or 5 hours the value must decrease for example to 98%, how do you advise me to do?
Of course, I forgot about division by zero in case of began of the month…
So you have to modify code in the next manner:
But nevertheless, I’m sure, that this implementation works exact you need, after fix it…)
You can see for yourself in two days, July is coming) Or change time settings of the test plc to the time close enough to month change date.
Accu time will be equal to time diff of month point begin and current timestamp, if switch always on since new month began. You launch test at the moment of end of the month, and result is tiny. But it starts from 100%. This realization is sensitive to state change at the first hours of new month, I mean percents can jump while measured time gap are small. But this is the most precision manner.
MONTHLY_OPH_CNT_v2.7zIf you need something more rough take a look at WH_MON_v3 FB
MONTHLY_OPH_CNT_v3.7zBest regards.
Thank you very much I used the initial version by making the correction you recommended (+1). I would like to start studying the programming Text but I can not find anything, do you recommend some links? In addition I should do a simple function that counts how many times in a month the switch opens and closes… could you help me? Now I’m doing it with a CTU only that once reached the PV stops. If I can try to start from your own code.
Hello!
My pleasure)
Unfortunately, I don’t have ready-made links for ST Text studying resources… Possibly other members will assist you in this case. Bat the most proven and reliable way is to solve work tasks day by day)
CTU is good enough, but it’s limited to INT datatype values range -32768…32767 for PV and CV, and if your process is intensive, CTU can easely go to overflow… Use R_TRIG/F_TRIG with INC UDINT/ULINT to solve the problem.

Perfect we thought in the exact same way! I used a TP to activate the ADD only that I noticed that every time I download the software you add a +1. I try with your R-trig , obviously OPN_position will have to be retain right?
OPN_accu have to be retain. Other don’t
To avoid inc during startup, I think you can use first cycle trigger. Variable init_done with false startup value. It will allow to skip this issue.

I tried but it does not always work, I opted for n TON with delay 1Sec now works fine!
Maybe now I’m asking too much!! I would like to calculate the MTBF using as a variable the same Switch ON for the time it is active and Switch OFF to calculate failures. Do you have any advice?
Please, give more expand explanation, what you need to do.