In industrial automation, there arises an occasion where you are required to measure the time taken for a particular event and show it to the operator. This helps in realizing how a process is working and how much time it is taking.
Troubleshooting improves a lot due to this logic. In PLC programming, structured text is a language which is used in many applications for high-level troubleshooting and ease of writing. In this post, we will learn how to write a PLC program for measuring the time taken by an event using structured text.
PLC Program for Measuring Event Duration
Let us understand the case scenario first. There are two sensors on a conveyor, one mounted on the left and the other on the right.
When an object passes the first sensor, it means the timer should start to count. When that object passes the second sensor, it means the timer should stop to count, as the object has passed now. The time taken to travel from sensor-1 to sensor-2 is the event to be measured.
Structured Text PLC Program
Now, let us write the PLC program. Refer to the below image. There are only two PLC digital inputs – sensor-1 and sensor-2.
When sensor-1 is sensed, we set a bit named Start_Timing by moving value 1. We will now require two elements – one timer for giving one second pulse and one counter for counting the time traveled. The timer will give one second pulse to the counter, so that it can count the timing in seconds.
For this, we first write the timer logic in the third part as shown. The timer input will be the negate of the timer done bit. The timer set value will be 1 second. Due to this, the timer will continuously be on and off for every 1 second. We can then use it’s output for our next part.
In the fourth part, we write the counter logic. The counter input will be the done bit of the timer and start_timing bit. Means, the counter will start counting only when this bit is set first.
The counter set value will be 32767 (based on our conveyor design which will not go beyond this much time as per sensor positioning). It means as per our design example, the travel time will not be more than 32767 seconds. As long as the bit is set, the counter will increment every second.
Now, coming to our most important part of counting the counter value. As you can see, we have written this part in the second block, above timer and counter logic. When sensor-2 is sensed, we reset the bit of Start_Timing by moving value 0.
But before that, we move the counter current value in the register where we show the accumulated value. This is because if this line is written afterward, then the counter would have been reset already and we will not get the value. So, in the third line, we reset the counter at last by sensor-2. So, the sequence goes as – first we move accumulated value, then stop counting, and then reset counting.
As sensor-2 will come in a pulse, the counter accumulated value will be holded in the register and not become zero. Due to this, the operator can every time view the last traveled time.
It is thus important to note that the sequence of lines is written properly for timely execution. Any mistake in ordering cannot run the logic properly.
In this way, we saw how to write a PLC program for measuring the time taken by an event using structured text,
Read Next:
- Traffic Lights Ladder Diagram using Timers
- PLC Programming With a Move Instructions
- PID Controllers in Closed Loop Control Systems
- Motion Detection based Street Light PLC Logic
- PLC Programming for Pumping and Draining System