PLCs in Your Browser

If your usual tools are the Arduino and the Raspberry Pi, you might find it surprising that the industrial world tends to run on Programmable Logic Controllers, or PLCs. You can think of a PLC as a very rugged industrial Arduino, but it’s best not to take that analogy too far. Some PLCs are very simple and some are quite complex, but one thing they do have in common is they are usually programmed using ladder logic. If you’ve ever wanted to learn how to program PLCs — a very marketable job skills in some places — you can now build and simulate ladder logic in your browser. [Garry Shortt] has a video walkthrough of the tool, that you can see below.

If you are used to conventional programming, you may find ladder logic a little frustrating. Originally, it was a documentation tool for relay logic but has grown to handle modern cases. It may actually help you to not think of it so much as a programming language, instead as a tool for drawing relay schematics. Contacts can be normally open or closed and in series or parallel to form AND and OR gates, for example, while coils can activate contacts.

In industry, ladder logic is well understood, and PLCs implement it in real time. It is also often very clear what the ladder is actually doing, more so than trying to read code, especially for people who are not necessarily coders.

Still, you may prefer normal programming. There was a recent post we did about a showdown between Arduino and a PLC. If you read the comments, a lot of people think the playing field favored the PLC, but it is still an interesting comparison. If you want real hardware, there are inexpensive options from the usual China sources and even an open source PLC.

30 thoughts on “PLCs in Your Browser

  1. I design electrical system schematics for industrial control systems, and write quite a bit of ladder logic.
    For those that may not know, PLCs vs Arduino is about the same as Marauder vs Kia Sorento.

    1. I’d say PLC’s would compare more to an “Industrial RasberryPi” than an “Industrial Arduino”. They are full blown SoC’s with a whole stack/kernel between the hardware/io’s and your ladder program.

      And there is an alternative that makes up for the lack of “re*laiar*bility” touted by PLC’s manufacturers; https://revolution.kunbus.com/ have 2 in production and 1 on my desk… work great.

      1. Surely the most expensive box for a raspberry.
        Linux in a PLC ?!!
        How do they address SD card corruption, unattended power failures, boot time …
        Modbus is so yesterdays, as 100Mb Ethernet, where is my CAN, my Ethercat

        1. Admittedly expensive if compared with a RasbPi from the shelf. They do the work of giving you the necessary surge protections, 24V on IO etc… so not entirely comparable. And though you might be able to solder and 3D print-encase the whole thing together yourself for much less, its not your primary priority if you have 300k+ USD of iron waiting to be automated. Still much cheaper than a Siemens (what is usually forced onto you). Quite the contrary, your value generation is the automation, which by far outweighs the little money you save by building the rig yourself.

          Yepp, a RT patched Linux. Might not be your VxWorks in term of vetting in critical environments, but does a great job. Arguably no less so than anything running as OS on commercial PLC’s. I’d be surprised if Siemens/AllenBradley transpile ladder to a native firmware PLC…
          And you get the full ecosystem to do many things you just cannot on commercially available PLC’s. As well as the ability to choose not to use ladder at all. Have you tried to have program a Siemens S7 to quack via TCP over network? Its a feature added as an afterthought at best if compared to native. Won’t deny that native languages have substantial pitfalls in being used in this domain when compared to the simplicity and elegant modelling ladder provides. As well as the risk of programmers misusing this very flexibility to build outright insecurely networked devices.

          Corruption on SD is a job for the FS and not for the SD itself. If you are saving state beyond of what is already readable from the pieces involved in the process on the PLC itself, its on you. Statefull systems in automation as well as in software in general are a bad idea. If you have an expensive value chain automated its also your responsibility to have a spare on the shelf prepared for quick provisioning and swapping on failure. Now if the PLC’s keep failing like ticktacks, well I’d have to agree with you on them not being fit for the task.

          You’d be surprised how much modbus is still around. Kunbus supports pretty much every bus type out there, since it is their main business to begin with. They do that through “gateway” modules, much like all other vendors.

          I for one welcome the chance to actually build something with open tools for once in automation. I’ve being feeling like with the Microsoft straitjacket I wore until 8 years ago. And I could not care less about whether it is an open source VxWorks touted for reliability or just a Linux RT stigmatized to be “insufficiently professional/reliable” for critical infrastructure. I just want to have the full power of the hardware at my disposal, instead of a patronizingly restrictive environment, walled and build to get you hooked on more. If I screw up, well that’s on me and my incompetence, but then again that is another story that does not necessarily reflect on a RaspberryPi Compute Module in an expensive box being a poor choice for the job ;).

    2. If you had said this 5 years ago, I would have agreed totally.
      Now, things are changing. As intended with open gear, people are making better systems from the basic system idea. Taking arduino as an example have a look at this:
      https://controllino.biz/controllino/maxi-automation/
      I have the predecessor to this sitting right next to an S7-300 and on cost and base functionality it crushes the Siemens gear. It is definitely more flexible from a programming stand-point as well, as evidenced here:
      https://controllino.biz/controllino/programming/

      Are we there yet? No, but we are working toward real freedom from vendor lock-in? Yes.
      Is the gear more repairable down to the board level? Yes.
      Are we building out equipment that, as an owner/operator, I can have real documentation for and knowledge of beyond just swapping out modules? Yes.
      That is something I can get behind.

  2. Ladder Logic is a standard but there are 6 other recognized standards in programming PLCs now and ladder is not used as much so wouldn’t say most are programmed in ladder logic. I work at a place where structured text and statement list are the main players and have seen programs from other machines that use these standards as well. Structured text will look much more familiar to anyone who has programed before and is fun to get into. In all though neat tip and a good learning tool for beginners interested in PLCs.

    1. Not true, most industrial machine tool and assembly applications are written in ladder logic. It’s easier for the maintenance folks to understand. Even if using function block most codee in the blocks are ladder logic. Get your facts straight.

      1. It depends on the location a lot. Old industry set the AB / ladder logic “standard” for much of the US. Many schools still teach this as a standard because it is what has been pushed for a long time and some companies still do not like change. As for easier to understand that is subject to the machine. Take for instance a machine with 6 different sequences and about 50 steps in each that is also communicating with another machine to avoid crashing and transferring data along with all that, not as easy to read through in ladder. For a basic pick and place machine I would agree that ladder is easier to see what’s going on when there’s not much going on in the first place. As for function blocks being coded in ladder refer to previous statements about some companies not wanting change.

    2. Depends on your geographical location and what type of industry your PLC is located in. For process-oriented tasks like HVAC, food/beverage/chemical production, and oil/gas, I’ve seen ladder (or ladder mixed with FBD) dominate because it is easier to visually see what is going on in the system live.

      You’ll also see ladder used more in the US then you will see in EU or other parts of the world. If you’ve ever had the chance to play with it and compare it to others, you’ll notice that Siemen’s ladder programming is horrible. Why? Because most of the manufacturers that use Siemens are in the EU and most of those use structured text.

  3. One other thing they also have in common is they are usually proprietary and considerably expensive and also subject to lack of support when they are inevitably discontinued. They have merit in some applications of course and they do tend to be robust but there are some considerable downsides as well, particularly for this user base.

    1. If you stuck with major brands like Siemens or Allen Bradley you should have access to loads of support. As far as how well they hold up I’m aware of a processing plant in Nevada that was using PLC-5’s from Allen Bradley up until 2013 and was only looking to upgrade because of plant expansion. As a reference the first PLC-5 came out in 1988.

      1. Support? Yes. But cheap hardware? No. Items do phase out even in PLC land as well and can be harder to find.

        “Our PLC-5 Control System is discontinued and no longer available for sale.”

        “The classic PLC-5 and its associated 1771 I/O platform are going to be classified as Silver Series by Rockwell Automation (AB).”

        “Shortly you will not be able to order new PLC-5 Processors and 1771 I/O, which means after your spares are used up you are left with eBay as your maintenance strategy! Yes, refurbished units will be around for a while but who knows who cleaned, repaired and tested them? It is getting harder and more expensive to find spare parts for the PLC-5s, so the question becomes is it worth the cost of unplanned downtime?”

        1. You don’t use PLCs because they’re cheap. You use them because they’re programmable Lego blocks that any competent electrician can plug in and program. When downtime costs you $1000 a minute you don’t care about $200 vs. $2000 for a piece of hardware, you just want the damn thing fixed as quickly and simply as possible so you can get up and running. Things do get phased out eventually but it’s not very common and it’s a bit of a big deal when it happens (as you point out with the PLC-5 example).

        2. Here’s one of the things I learned, most of the companies that use PLC-5s have a reasonable stock of replacement parts in inventory, and a number of schools have them hidden away in cupboards from when they got newer units. Beyond that, considering how old it is, and how most of the original parts have been superseded by newer ones at the component level, I can give them that they kind of have to discontinue the twenty nine year old designs.

          Seriously, considering that you can punch together a program that does exactly the same thing as the old one on a new one, and then hook it together relatively quickly from the printouts(You could build the new one such that it can use the same program, but it costs more).

      2. I still See PLC-5’s in operation regularly, i can currently access 2 running PLC-5’s, a large amount of SLC500’s and more modern stuff from where I’m currently sat. I Still see quite a lot of siemens S-5’s in production too.

  4. I believe the IEEE standard is only the following three langues for PLC’s. Ladder logic, which is the evolution of relay logic, structured text, and function block. While ladder logic and function block may not be as efficient as structured text I’ve found them to be the primary coding used in industrial applications. The nice thing about learning ladder logic is, if you can program one brand of PLC you can pretty much program any brand.

    1. 4 actually: https://en.wikipedia.org/wiki/IEC_61131-3
      Ladder Diagram (LD)
      Structured Text (ST)
      Function Block Diagram (FBD)
      Sequential Function Chart (SFC)
      It used to include Instruction List (IL) but that was deprecated.

      Personally I like FBD and SFC programming, which saves a lot of state machine building in ST. But anything that can be done in any of the other languages can be done quite quickly in ST. Most larger firms I’ve seen using PLCs nowadays do everything in ST by default.

      1. I prefer ST and FBD. I don’t particularly like LD.

        I did a system of 12 product feed rams, in ladder that would have meant writing out the logic 12 times. Or staging a common set of variables and using jump instructions, and that approach breaks timer functions.

        In ST I could keep everything in a clean set of arrays and run for loops on them for the logic. I don’t remember if they’d bought the SFC module for the PLC.
        (and then the electricians on the job, who never read logic anyway, put in extra LD sheets of the same arrays mapped to indicational contacts/coils so they could ‘see’ how the PLC was running online. I was happy to let them do that inane thing because they couldn’t muck around in the ST and change logic.)

  5. It’s about 20 years ago that I was forced to do something with ladder diagrams at school.
    We had to build some sequential logic with it.
    The Idea to have a plc (which handles instructions one at a time) and the “ladder logic” which tries to hide it’s doing things sequentially, and then build something which does things sequentially again is just mind boggling stupid.
    I ended up with coding a list of flipflops in ladder logic and squeezing the actual logic in between that list of flipflops.

    The “structured text” looks like a half decent (pascal syntax like) language.
    https://en.wikipedia.org/wiki/Structured_text

    But If I’m ever going to do more PLC’s (in a home/hobby setup) it is very likely going to be some fx2n clones from Ali, and I won’t bother with https://en.wikipedia.org/wiki/IEC_61131-3
    I’ll just use the most standarised programming language there is: C (or C++).
    There are loads of variants of fx2n clones on Ali / Ebay and most (all?) have an stm32 on board.
    They seem decently built:
    – Common mode filter on power supply.
    – smps power supply.
    – Opto inputs.
    – Relay’s or transistor outputs.
    – decent connectors (lots of different options here).
    – Some come with housings, others just bare pcb (cheaper).

  6. I am partial to ladder logic. Trouble shooting hardware in ST is painful. So if you like downtime use ST. I prefer almost any PLC to Siemens. SIEMENS while electrically solid are a big pain to troubleshoot. So if you like downtime use siemens.
    On the expensive end I prefer Rockwell and Schneider aka Mdicon. On the cheap side you can’t beat Unutronics.

    1. ST is not what makes a PLC hard to troubleshoot. The software itself is. The Siemens version that I have used is a pain no matter what it is programmed in. Using s5 for windows. On the other hand the newer Siemens PLCs in some parts of the company have better software and are easier to troubleshoot. Beckhoff PLCs on the other hand are very easy because the software is set up well in general so saying the language is what makes it hard to troubleshoot is not entirely true.

  7. I am working in Hungary for one of the biggest vehicle manufacturers and I can tell, I program 99% of my time in Ladder Logic on PhoenixContact PLCs. Electricians cant understand a single line of Structured Text so far I noticed, so to write a program of a robotic cell purely in Ladder is an insane thing to say. Btw most of the logic is written in ST and it is horrible slow to pin-point the problem in it.
    Btw I purely hate Ladder, but for troubleshooting it is one of the best solutions if your code is freakin huge and there are multiple layers of logics, devices accross the cell.

  8. Hi Al,
    Thank you for posting the information on PLC Fiddle.
    Modern PLC’s can do allot more these days. I have worked on the Click PLC that comes at a very inexpensive price. (Starting at $69 USD)
    https://www.automationdirect.com/clickplcs/index
    Team this up with a Human Machine Interface (HMI) like AdvancedHMI, and you have a good industrial system.
    AdvancedHMI is a VB.Net application that is open sourced. Since it is in Visual Studio you can write additional code to communicate to databases, etc. using a variety of languages. Allot of the common protocols are included in this package for a majority of PLC Manufacurers.
    https://sourceforge.net/projects/advancedhmi/

    Here is a guide for beginners to learn PLC Programming:
    http://accautomation.ca/programming/plc-beginners-guide/

    Regards,
    Garry

  9. I like the flexibility of modern PLC’s. And some languages are better for certain applications. For complex data manipulation and logic I use structured text. For timers, counters and digital I/O I use ladder. For analog I/O scaling and PID I use function block.

  10. Veddy interesting. Back in ’83 I was working for GE in Charlottesville. They were developing a line of NC controllers and a programmer that ran on a PC, and used Ladder Logic. An interesting concept. Our only problem was that the program was being written in Microsoft Pascal, and the programmers were computer scientists, not embedded software types. Some of them tended to use nested procedures many levels down.

    So in the end, the program did work, but was so maddingly slow it was impossible to use on a real project.

    Not sure anyone’s mentioned it here, but in real-world ladder logic, implemented in actual switches, relays, etc., it’s easy to design in sneak paths that break everything. The computerized ladder logic doesn’t have this problem.

    1. At least with Arduino you have enough documentation to make an attempt at failure rates (hardware and software), good luck verifying (or generating, at the lower price point) the closed system numbers.
      Just cracking open the case on to look inside on some systems might get you jail time, depending on the EULA.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s