How can I time taken between 2 events

245 views Asked by At

I am trying to record the time taken between 2 sensors being activated

I am using ladder logic for my university project although struggling with code to record time taken between two events so as to store the information

1

There are 1 answers

0
dwpessoa On

It would be interesting if you included which PLC you are trying to use as the timer block can vary a little between some brands of PLCs, below I will put an answer that works for Codesys, Twincat, Omron, Delta and others similar, but some blocks may vary from format or in the name of the inputs and outputs, but the concept is the same.

You also didn't specify if you intend to measure between the rising or falling edges of the sensors, this could influence the measured time. Let's assume you want to measure between the rising edge of S1 and the rising edge of S2.

The idea is to start a TON timer (fbTimer) when sensor S1 is turned on and keep this timer running even if S1 is turned off and, when S2 is turned on, capture the elapsed time (fbTimer.ET) on the timer and store it in a variable (using the MOVE block) before restarting the timer (when the elapsed time is reset).

Some notes:

  • Because the PLC program is cyclic, the order of the Networks (ladder lines) will matter, as you need to capture the timer time before resetting it in the same cycle.
  • You must use sensor S2's rising edge capture when recording the time, or the value will be overwritten in the next cycle, as the timer will have been reseted.
  • Problems can occur in this example if the order of activation of the sensors changes in time, or if S1 is activated more than once and you want, for example, only the time difference in the last activation of it (in this example a second pulse of S1 before S2 being triggered will be ignored).
  • Note that there are other ways to do this, including using other types of timers such as TOF and TP.

enter image description here

enter image description here