Contact and Coil | Nearly In Control

Step

The Step pattern is a Ladder Logic Programming Pattern that is the basic building block of a machine’s Automatic Mode. The logic for each Step is simple:

Step

Step

You can combine any number of steps to form a Sequence. The steps will execute sequentially. When the Step In Progress coil turns on, this should be the signal to actuate a mechanism somewhere else in the program. For instance, if the Step is “Extend Cylinder” then a contact from the Step In Progress coil could be used to turn on the pneumatic valve to extend the cylinder. The Step stays active (i.e. the Step In Progress coil stays on) until the Step Done condition is true. In the example of extending the cylinder, the Step Done condition could be the Cylinder Extended input.

Consider that you might have several steps where you need to extend that cylinder. If you need to extend the cylinder in both Step 3 and Step 8, then your Extend Cylinder logic could have contacts from both Step 3 In Progress and Step 8 In Progress in parallel.

Here is an example of a two step sequence. Step 1 is “Extend Cylinder” and Step 2 is “Retract Cylinder”:

Two Steps

Two Steps

The Sequence Start condition is what initiates the sequence. This should be something like “the machine is in Auto Mode, an Auto Cycle is running, a part is present, and the part hasn’t been processed yet”. When the sequence is complete, then the Seq. Complete coil turns on. This can be used in combination with the Set/Reset pattern to latch a memory bit to indicate that the part has been processed. Presumably this causes another sequence to begin, such as an Unload Part sequence. Alternatively we might just wait for the operator to remove the part.

The Step pattern is frequently used with the Mission pattern. In this case the Sequence Start will be the Mission (in progress) coil and the Seq. Complete coil will signal the end of the mission.

Note that if the Sequence Start condition drops out during the sequence, then the entire sequence will reset (all the Complete coils will turn off, as will the Seq. Complete coil).

Also note that if the sequence starts and the cylinder is already extended, then the Step 1 In Progress coil will never turn on. It will jump directly to Step 2. In this case that might be what you want. If it’s not, you can consider putting the condition “Cylinder not Extended” in the Sequence Start condition. Another alternative is to force the Step In Progress coil to turn on for at least one scan before moving to the next step. This is relatively simple:

Step: Variant

Step: Variant

By adding a contact for Step In Progress before the Step Done condition in the first rung, we make sure that the Step In Progress coil has to turn on for at least one scan before the step is complete. You can even take this form of the pattern and remove the Step Done condition:

Step: One Shot

Step: One Shot

In this variant of the pattern, the Step In Progress coil turns on for exactly one scan. This makes it a “one-shot step”. A one-shot step is useful for doing part tracking and data logging since those things typically only require a single scan (such as set a bit, take a measurement, or record a value to the part history).

More Patterns of Ladder Logic Programming.


10 comments

  • Gary Flinsenberg · July 26, 2015 at 9:18 pm

    Great article for new ladder logic programmers or even a quick refresh for programmers who have been out of the loop for quite a while.

  • Author comment by Scott Whitlock · July 27, 2015 at 7:21 am

    Thanks Gary! 🙂

  • Andrei · June 6, 2016 at 11:30 am

    Interesting article, thank you!
    But what do you think about integer step pointer, like “Step_number”? This way we have only one variable to manage all the sequence.

  • Author comment by Scott Whitlock · June 6, 2016 at 1:24 pm

    @Andrei – I have several reasons for not using a step number:

    You can insert an unlimited number of steps between any two steps using this method, but if you use a step number you would have to leave step numbers between them (such as step 10, 20, 30) and then you might run out of numbers and have to re-number.

    Having a contact called StepOpenGripper is easier to read than an instruction where you say “if step number is 8”. Particularly for a technician troubleshooting it. If you have step numbers you need to document what each step number means.

    This pattern allows you to have parallel branches, so I can tune my machine by overlapping steps. For instance, I’ve often had a sequence where you had to do one step, and then I had two sub-sequences (execute steps A and then B in parallel with steps C, then D, then E) and then after both sub-sequences were done I could execute another step. This is more difficult with a step number variable, because then you need step number variables for each sub-sequence, and that affects the things that are driven from the steps, such as trigger rungs elsewhere.

    Also, this is “patterns of ladder logic”, so contacts and coils are more canonical than variables, move instructions, and equals instructions.

    If you use a step number variable you’re basically making a state machine. The step pattern is more flexible than a state machine for the reasons I’ve described above.

  • Andrei · June 7, 2016 at 10:51 am

    Thank you Scott for such a comprehensive answer.
    What do you think about “step mechanism” (what step actually does) place?
    Do you put it in the same subroutine or you make different subroutine for it?

  • Author comment by Scott Whitlock · June 7, 2016 at 11:42 am

    @Andrei – the step “in progress” coil is typically used to do one or more things during that step. The normal place to use a contact from an “in progress” coil is in the trigger rung of a Five Rung pattern.

    In general, each physical part of a machine has a routine or program controlling just that part (so one routine for each motor, cylinder, etc.). A contact from the “in progress” coil should show up in that routine or program.

    In addition to thinking “what does this step do” also think about “when does this such-and-such (e.g. motor) turn on”? From the perspective of someone troubleshooting a machine, they typically know what’s supposed to happen next (“why isn’t the motor starting?”) so they’re going to crack open the motor routine, find the Motor Start output and follow the ladder back from there.

    On the other hand, they don’t necessarily know that you’re in the Turn on Motor step of your sequence (there could be more than one Turn on Motor step anyway) so they’re not likely to look there to start with. Since any given action/output can have more than one step affecting it, then putting the actions with the step tends to spread the logic related to a single output over multiple places, and that makes it harder to troubleshoot.

  • Andrei · June 8, 2016 at 4:05 am

    Thank you Scott, you have a really smart attitude for logic parts location. I appreciate your fast answers!

  • Raphael Vogt · January 9, 2017 at 8:57 am

    Hey,
    I agree if you’r willingly only to use Ladder Logic Programming.
    Sure these tutorials here are about Ladder Logic Programming patterns!
    But as additional note: if you can handle some structured text, you should also consider using statemachines. You might underestimate the power of a finite statemachine (switch-case in combination with enums) (coded in structured text).

    – enum = no instruction needed (like X = stepnumber 8)
    – enum = no problem to add steps between
    – enum = no reserve steps needed
    – You don’t have to think about blocking other steps.
    – branches can be handeld by splitting into to multible statemachines.

    You spoke about Anitpatterns, I personally consider these old step patterns as kinda outdated, if you can use structured text.
    But if I would be limited to Ladder Logic Programming, I would do it like you sugessted, (without step numbers, screw them!) .

    Btw. Much Thanks for your tutorials!
    Thanks mate.

  • Author comment by Scott Whitlock · February 5, 2017 at 10:04 am

    @RaphaelVogt – if you’re working in structured text, then the equivalent is a state machine. I’m sure you can appreciate why I’m not going into structured text patterns in my “Patterns of Ladder Logic Programming” page. 🙂

    I would also like to point out, as I did above, that this Step pattern gives you more flexibility than a state machine. Consider a sequence where you perform Step 1, and then you branch into 2 parallel sequences of steps, such as 2A1, 2A2 on one side and 2B1, 2B2, and 2B3 on the other side. When both sub-sequences are complete, then you execute Step 3. Not only is this easy with the ladder logic Step pattern, but it’s actually easy to change from a completely linear sequence to a partially parallel sequence later.

    State machines, on the other hand, aren’t this flexible. A state machine, by definition, can only be in one stage, so it can’t simultaneously be in the 2A1 and the 2B2 state at the same time, at least not in an easily comprehensible way. You’d need to have 3 different stage machines – an overall one, and then two “child state machines”.

    State machines, as I’ve said elsewhere, were at their heyday back when electrical engineers designed hard-coded logic with TTL chips using boolean gates. They used tools like Karnaugh Maps to express their state transitions and then reduce them to the minimum number of state bits so save on chip count. Therefore they suffer from the big-design-up-front anti-pattern. State machines are the anti-pattern, not steps. (Sometimes people confuse the Step pattern with Sequencers, and sequencers are definitely an anti-pattern – even more inflexible than state machines.)

  • Tom · February 21, 2017 at 10:53 am

    Does this method allow a simple way to go back a step, or to skip steps?

    For example, let’s say I want to run step 1, then 2, then 3, then go back to 2. Or if I want to go from step 3 to step 5, then 4, then 6.

Leave a Reply

Theme Design by devolux.nh2.me