Patterns of Ladder Logic Programming

If you’re familiar with PC programming in languages like Java or C#, then you’ll probably know about the books Design Patterns: Elements of Reusable Object-Oriented Software and Patterns of Enterprise Application Architecture. These books are about Software Design Patterns.

As a long time ladder logic programmer, I thought one way to share my experience with newer programmers is to organize a list of common patterns used in ladder logic programming. This list of ladder logic programming patterns serves two purposes: first, each pattern is a tool for solving a common problem using ladder logic, and having these patterns in your toolbox will allow you to program faster and spend more time focusing on the higher level structure of your program. Second, since these are common patterns, you’ll start to find it easier to read other people’s ladder logic, and other experienced programmers will find it easier to follow your logic.

  1. The Sealed in Coil pattern
  2. The State Coil/Fault Coil pattern
  3. The Start/Stop Circuit pattern
  4. The Set/Reset pattern
  5. The Flasher pattern
  6. The Debounce pattern
  7. The Input Map pattern
  8. The Step pattern
  9. The Mission pattern
  10. The Five Rung pattern
  11. The Mode pattern

23 thoughts on “Patterns of Ladder Logic Programming

  1. LKH

    Very nice idea for people just starting out!
    You should include an Anti-Tie Down pattern 🙂

  2. Bob

    Very nice. I hope you keep adding new sections to this. Naming conventions, Fault – Acknowledgement pattern, Messages/Warnings/Alarms ect.

    I will be sharing this with my colleagues.

  3. azetou

    Thank you sir for your efforts. Just one question, when you show the timing diagram shouldn’t we see the clock in it? it means you have to add at what intervals the CPU updates the inputs and outputs. Thanks for clearing this up for me.

  4. Scott Whitlock Post author

    @azetou – A clock signal would make sense for combinational logic with internally clocked registers, but a PLC is just simulating combinational logic with a sequential program. In a TTL circuit, the clock causes the registers (flip-flops) to update their outputs, which then changes the downstream logic from those elements. In a PLC, every instruction potentially causes the update of internal state, but the logic that depends on that state change doesn’t actually change until those instructions execute. Example if you have two rungs: A := A + 1, and the second rung is A := A – 1, then during the scan A both increments and decrements. A program with 100 rungs could have potentially hundreds or even thousands of “clock pulses” every scan.

  5. Scott Whitlock Post author

    @Allan – yes, as long as you provide a prominent link from the translated copy back to the original. Also, please send me the link to your translation so I can post a link to it from here.

  6. Pingback: Designm̦nster f̦r ladder РAutomat Etta Nolla

  7. Aliazzz

    Dear Scott,

    I took the liberty to translate the patterns into CODESYS v3 ladder logic as FB’s. Offcourse kudo’s got out to you, the original poster. I also linked to this page for future reference.

    Just a remark;
    Some ladder patterns are considered obselete in CODESYS v3 (on which TwinCAT3 is based). I implemented them anyway for educational purposes but I suggest to adhere the IEC 61131-3 standard solution.

    I tried to stick as closely to your examples as possible but took some liberties in naming variables etc.

    With kind regards and thanks for sharing!

    Ps you can find my git at: https://github.com/Aliazzzz

  8. Scott Whitlock Post author

    @harinder – controlling a stepper motor directly from ladder logic is rare. Traditional PLC scan times aren’t fast enough to step the motors at a reasonable speed, and you require special output hardware to drive the stepper motor coils without inducing too much current, and giving you improved control like microsteps.

    If you want to control stepper motors from a PLC, you normally buy a separate stepper motor controller / drive as an add-on unit. For the Allen-Bradley world, I’ve used AMCI products. For Beckhoff TwinCAT, I’ve used the EL7041 card. You can also buy stand-alone stepper motor systems from Automation Direct.

  9. Timothy P Hannagan

    I am trying to learn how to set up and use analog input and scale analog output in Beckhoff twincat 2 , help please

  10. Scott Whitlock Post author

    @StefanLindgren – I learned a lot by writing SoapBox Snap, but it just created a steady stream of complaints to my email address due to bugs and feature requests. Every time I tried to involve one of those people in tracking down a bug, they wouldn’t send me a way to reproduce it, or any log files or events from their Windows event log. I couldn’t reproduce any of the bugs on my end. Plus, I didn’t use the software myself, so I didn’t want to spend time on it.

    So I’ve just decided to abandon it. It was costing me money every year to host the site.

    What I learned, in general, is that open source works well if you either (a) use the software yourself, or (b) the software is used by developers who program in the language it’s written in, so they can help contribute. Since I was the only developer and I wasn’t getting anything out of it, it just felt like I was working for free for other people. You can only do that for so long before it gets old. 🙁

  11. Beck Wang

    Hi Scott Whitlock,

    Read your blog does help a lot to me.

    I would like to thank you very much for your great sharing.

    You makes the world better.

    🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.