Walkthrough: Problem 5: Air Cylinder 2

Difficulty

Target behavior

Extend the rod with a button, hold it at the extended end for 3 seconds, then retract it automatically

What you will learn

  • Timer (TMR) instruction
  • Automatic operation triggered by sensors

Problem

Let's continue learning ladder logic with the air cylinder model!


This time, reproduce a motion where pressing the Piston button extends the rod, holds it extended for 3 seconds, and then retracts it.

For this ladder, you need a new instruction: the timer instruction (TMR).


Here is how to use the TMR instruction.

When using TMR, specify a timer device T and a preset time (in units of 100 ms).

In the example below, when N.O. contact X3 turns ON, T1 starts counting.

When X3 has been ON for 3 seconds, T1 turns ON and the Y3 coil turns ON. T1 stays ON while X3 is ON, and its contact opens when X3 turns OFF.

If X3 turns OFF before 3 seconds, the T1 count is reset, and when X3 turns ON again it starts counting from 0.


Now let's write the ladder using TMR!

Target behavior (video)

Approach

Do "extend", "wait 3 seconds at the extended end", and "retract" in order. Extending is triggered by the button, the wait uses a timer, and retracting is triggered when the timer completes.

Based on this approach, try writing the ladder yourself first.
In the simulator, you can create the wiring and ladder and actually run the 3D equipment model.

Try it in the simulator
Show the sample ladder and explanation(click to open)

Devices used

DeviceComment
Inputs
X0Auto switch (extended)
X1Auto switch (retracted)
X2Piston button
Outputs
Y0Cylinder solenoid valve
Timers
T0Dwell time at extended end

Ladder explanation

The row numbers in the figures match the row numbers in the simulator's ladder window.

1Extend with the buttonRows 001–002

On the rising edge (LDP) of X2 (Piston button), SET Y0 (solenoid valve) only when the rod is at the retracted end X1.

LDP is used here so that if the button is held down, the rod does not extend again right after retracting.

2Wait 3 seconds at the extended end, then retractRows 003–005

  • Row 004: while Y0 is ON and X0 (extended end) is ON, T0 counts. The preset 30 is in units of 100 ms, so it is 3 seconds.
  • Row 005: after 3 seconds, when T0 turns ON, RES Y0 to retract the rod.

When Y0 turns OFF, the condition on row 004 is no longer met and T0 automatically returns to 0. On the next cycle it counts 3 seconds from 0 again.

The sample wiring and ladder data can be downloaded fromGitHuband loaded with "Load wiring" and "Load ladder" in the simulator.

Key points

  • The key is to count 3 seconds "after reaching the extended end". If you count from the moment the extend command is given, the stop time at the extended end becomes shorter by the time the rod takes to move.
  • The timer contact (T0) is ON from when the count reaches the preset until the input turns OFF.