This article explains a possible way to determine the amount of time taken between the start and end of an event. The event doesn't have to start and end within the same job using this method.
The following example tracks the time it takes to complete a task using an Output which is turned ON at the beginning of the task and turned OFF when the task is completed.
#15057 = Cycle Time Output
M250 = Cycle Time
M251 = Timer Set Value (units of 0.1 seconds)
M252 = Timer Current Value
STR #15057 PLF #76001 | When Output (#15057) is ON, Pulse the Auxiliary Relay (#76001) for one scan of the ladder whenever the Output (#15057) transitions from ON to OFF |
STR #76001 MOV M252,M250 | When Auxiliary Relay (#76001) is ON, Register M252 is outputted to Register M250 |
STR #76001 SUB M251,M250,M250 | When Auxiliary Relay (#76001) is ON, Subtract M251 by M250 and store the result in M250 |
STR #15057 TMR M252,M251 OUT #76000 | When Output (#15057) is ON, M252 counts down from M251 to 0. If the time expires the Auxiliary Relay (#76000) turns ON. |
Breakdown of above logic:
When Output (#15057) turns ON, the Timer Current Value (M252) will count down from the Timer Set Value (M251). When Output (#15057) turns OFF, Auxiliary Relay (#76001) will be pulsed for one ladder scan. In this ladder scan, the Timer Current Value (M252) is outputted to Cycle Time Complete register (M250). Then the Cycle Time Complete (M250) is set to Timer Set Value (M251) - Cycle Time Complete (M250).
Reasoning:
After the MOV instruction, M250 contains the counted down time from the Timer Set Value (M251). To get the time it took from the Output turning ON to OFF from 0, M251 is subtracted by M250.
Note:
- The Timer Set Value (M251) needs to be initialized to a value big enough to capture the cycle time of the task. The largest value accepted in the TMR Set Value is 6553.5 seconds (65535).
- Auxiliary Relay (#76000) is not being used in this example, but could be useful in determining if the the event time took longer than what was recorded.
Comments
0 comments
Please sign in to leave a comment.