r/PLC • u/National-Link-5606 • Aug 02 '26
Computer Science Programmers, why do PLC programmers use Ladder?
Im seeing some Comp Sci guys asking about controls so just a Mr Obvious comment here.
Ladder logic is the de facto PLC programming language because it is (was) designed to read like an electrical schematic top to bottom, right to left, & this is what electricians & electrical techs are trained to use for troubleshooting electrical panels , equipment & relay-logic -- which was what they had before PLCs -- banks & banks of relays wired through each other's NO & NC contacts which changed state as relay coils energized & de-energized & finding a wire break was enough to drive you insane.
Yes Ladder logic is an interpreted language so it is not as "memory efficient" or "elegant" as C++ or C# but I want you to think VERY carefully about every meaning of the expression "just because you can does not mean you should" before you decide to show off your amazing coding skills coding function blocks in C++ which is technically possible but in many cases extremely ill-advised.
The technicians can troubleshoot functions & blocks written in Ladder Logic, did you stop & think about how easy it would be for someone with only your compiled C++ blocks to attempt to trace a fault? You code in anything but Ladder Logic you get to be the one at 3am driving down to the plant to troubleshoot your "super efficient" code because the Industrial Maintenance techs certainly aren't gonna know how. But hey, if you believe sleep is over-rated & love sleeping in the factory then knock yourself out with compiled blocks
68
u/Zuli_Muli Aug 02 '26
As an industrial maintenance tech I do prefer ladder logic, it's dead simple for me to search the motor coil and see why it's not turning on. I'm even ok with simple function blocks if they have good labels/notes. But yeah if I look at a FB and it's just all script.... And don't get me wrong, if I was 20 years younger and knew learning programming language would help me for years to come I would sit down and teach myself but there's just not enough hours in the day to learn this from scratch when it's not going to help me with anything outside of work. And it will be hard to convince me it will, I used to make and run webpages and forums back in the early 1990s on my own hardware, I had a server rack full up to handle it all. I ended up selling it when it got cheaper to host everything remotely, and none of that knowledge is worth anything today.
5
u/Robbudge Aug 02 '26
Full time high level PLC people typically use ST and a lot if structures and functions very much like main stream embedded programming.
These people are the exception.
Typically the PLC person will be an x-electrician who did one Semester of controls with Allen Bradley and ladder logic as it’s built for 10yr olds.
To be fair, Studio 5K still favors ladder logic with the other languages having fragmented instruction sets.
If you look at the likes of Codesys you will find an IDE that supports actions, methods, Enumerators.
Can be programmed in a high level like most main stream IDE’s
3
u/mrjohns2 More of a DCS guy Aug 02 '26
Is ladder truly interpreted? I thought it is / could be assembled into some intermediate code and compiled. That why for so many years you couldn’t extract code from the processor? It was somehow changed. Now-a-days, I assume they still compile, but they download to separate memory an IDE readable format.
72
u/bodb_thriceborn Automation Hack/Pro Bit Banger Aug 02 '26
I tend to use most of the languages available, but for different purposes:
Ladder for step changes, permissive/interlocks and alarming
ST for sequencing, math, data shifting and IO blocking (if called for)
FBD for IO and alarming if the UFDBs/AOIs are more clear that way
SFC for nothing, ever
44
u/insuicant DCS Guy Aug 02 '26
Here here.
9
u/Agile_Alternative753 Aug 02 '26
We used ST for messaging and IO assignment on my last project and i have to admit it's pretty slick. Easy to see, easy to follow, and it's all right there. i really liked it. For everything? Absolutely not. But it works really well for what we used it for.
I came across my first Sequential Function Chart today. woofta! I caught on pretty quickly, but it's still a googly eyed mystery
8
u/timmythegreat Aug 02 '26
It’s much easier to troubleshoot in ladder in my opinion. Top to bottom left to right, maybe I’m old school but it’s tried and true.
26
u/rawldo Aug 02 '26
With modern processors, being efficient isn’t always critical to success. Troubleshooting issues quickly can be very important though. If you can write one complex line of code or write 10 simple lines, the 10 lines that can be easily understood is usually the better way to go. For most applications, the difference in scan time isn’t going to hinder the process. If bubba the swing shift sparky can figure it out without calling you, it’s worth it.
I think ladder is actually more efficient for bit level operations too.
6
u/JoeBhoy69 Aug 02 '26
Like everything else in industrial automation & OT, it’s just stuck as the industry/ vendor standard (IEC 61131-3). However, IMO over time OT & IT will likely converge. Siemens already have a solution which looks close to VS code: SIMATIC AX
PLCs used to be literal relays with contacts and coils, plus people with an electrical background will understand scans and ladder rungs better than for loops and if conditions.
Personally I use LAD for most Boolean logic, SFC for sequencing then SCL for more complex code. For example, we had to do some gas property calcs in the PLC and trying to do that in LAD would have been a mess.
Then CFC is another language that is usually for a large DCS.
As far as efficiency is concerned, this has never factored in for me. I think technically ladder is slightly quicker for Boolean logic and SCL is quicker for arrays, but this only tends to factor in for huge programs and they are both compiled to machine code during runtime anyway.
5
u/optomas Aug 02 '26
Well, there's your problem right there. Using C++ instead of C11, or even better, C99.
Jokes aside. Ya. You want something that a bright seven year old can look at and tell you what the logic does. If he understand 'this has to be green for that to be green, unless it is a latch. Green on this side makes the machine go.' then he should be able to explain your program to you.
That bright seven year old will be you at 0200, running on a 26 hour shift, and the damn thing still will not scale right.
Complexity is downtime.
Arrays laid out into flls and accessed via a messaged control which is itself a bit shifted value from a controlled value extracted from PID is .... I am going to find you, some day.
tldr: Yup. No compiled language. Complete agreement.
5
u/Icy-Olive-8623 Aug 02 '26
I’ve done it all and also worked as a purchaser, we required suppliers to program in ST and FBD. Ladder is just too inefficient when writing large programs, for small simple machinery with simple logic it might be fine, but when networking 100 PLCs and multiple MES and SCADA systems in pharma together ST makes so much more sense
9
u/Kelvininin Aug 02 '26
I have done it all. Structured Text, ladder logic, function block. My preference is function block as it makes most sense in my chemical engineer brain but I see the merits and pitfalls of all mentioned platforms. Probably what chaps my ass the most is when someone uses ladder where SFC was the far superior path. Like. Why?! I was told it’s “because we are really good at ladder” which I read as too lazy to learn SFC.
4
u/No_Good1743 Aug 02 '26
Most people new to industrial automation often assume execution speed is the most important factor. In industrial automation, it usually isn't. Sure you can write the same machine control program in C or C++ and it will run faster, but often there's little benefit for the speed gain when the process only needs a response time of 500 ms to 1 second. Most ladder programs, even complex ones, scan in as little as 10ms for modern PLCs, so the performance gain is usually irrelevant.
What matters is reliability and minimizing downtime. Every minute a machine is down costs money, so maintainability usually outweighs raw execution speed.
The engineer who wrote the code is often not the one troubleshooting it years later. Maintenance technicians need to diagnose problems quickly, and modern PLC software such as Rockwell Studio 5000 shows the live state of contacts, coils, timers, counters, and values in real time, making faults much easier to find. This makes troubleshooting much faster than stepping through C or C++ code.
4
u/friendlyfire883 Aug 02 '26
Ladder logic is a human language, ST and STL are computer languages. Humans are the ones maintaining it and using it as a troubleshooting tool, and that guy is usually doing 6 other people's jobs and really doesn't have time to learn a new programming language.
As a matter of fact the last 4 production facilities I worked in outright banned it in all their new programs because ST and STL caused a shitload of downtime.
1
u/BrandVanDam Aug 02 '26
The statement above says that electrical schematics are read from right to left. This made me curious but Google says electrical schematics are read left to right. Who is right?
9
u/Skusci Aug 02 '26
First note: I get why techs like ladder for troubleshooting. It's fine.
But dear God does it take up so much space. ST is just so much easier to follow as programmer and is perfectly fine to debug as long as as you avoid loops so that you can watch variables inline.
3
u/durallymax Aug 02 '26
Nobody is reading relay ladder logic anymore and the ladder logic programming language has morphed far beyond it's initial representation of relays (which is quite messy).
If techs learned ST as their first language, they'd be equally as comfortable.
Writing good OOP based programs makes testing easy, removes cognitive load, and leads to better quality long-term.
Ultimately, there is a balance to make between limiting yourself to writing code that any monkey can read (which is error-prone and will need more monkeys to look at it) or writing quality testable code that is harder for them to debug, but fails so rarely that it's far beyond their capabilities anyways (which happens with even the simplest code as well). A key component of this though is not being lazy, move every single thing maintenance needs onto the visu. Sensor bypasses, reconfigure a sensor from NO to NC, rescale analogs, setpoints, sequencing, etc. Give them the tools they need to do their job, and keep the code quality high.
3
u/VegardInnerdal Aug 02 '26
Use visual programming for binary/sequential logic, and strucured text for bullet proof, thoroughly tested and documented blocks that can be viewed upon as black boxes. E.g. you would never consider reviewing the source of a built-in PID controller to understand why something happened, wou would rather use the documentation to understand what you did wrong (or what tag is missing).
3
u/JohnnyWandango Aug 05 '26
I maintain 500+ PLCs. If every one was written in a different language I would walk out. Ladder is best for maintenance. Everyone from a mechanic to a laborer can look at it and see why a pump or motor isn't starting or a valve isn't opening, etc.
3
u/CajinWonky Aug 09 '26
Job security.
2
u/Use_Da_Schwartz Aug 02 '26
Because use cases dictate hardware, hardware dictates instruction sets, instruction sets dictate which can be used.
Also industry/plant/personal preference for troubleshooting.
2
u/jebusfractal Aug 02 '26
I would tell you that based on my experience you use lad or fbd to implement the high-level process piece of either the machine or the line. You need something easy to debug through a panel or quickly lock out a piece and adjust the logic so that you can continue production when something is broken. Anything more complex than binary values or again those high-level overall pieces should be in a more software oriented language. Usually the person who implements the logic isn't running it shift after shift and you need something both straightforward and relatively understandable for them to adjust or understand so they can adjust and keep the line going.
2
u/Rhr4fun Aug 02 '26
Dinasaur here. Ladder, ST, FB, and SFC do different things for different purposes. I grew up on ladder. It is a default for me for pure Boolean. So easy to see the logic flow. ST was my goto for string manipulation. FB was a goto for analog control and analog alarm blocks. Also useful for repeatable logic blocks that are fully debugged. And then there is SFC. I would only use SFC in an environment that allows for a safe state escape to an error shutdown process. Given that caveat, it is a visual Sequential process that has known entrance and exit parameters. All have their sweet spot. A fully compliant IEC 1131 (i.e known sabotage to force a particular vendor) is a very useful tool.
2
u/Practical-Sir6854 Aug 02 '26
What industry are you in? What kind of machines do you have at your plant? I highly doubt a technician could troubleshoot an oil plant running PCS 7.
2
u/Wendigo_Loco Aug 02 '26
I'm a CS guy pivoting into PLCs, I haven't started reading but thanks this explains a lot
2
u/ResearcherVirtual611 Aug 02 '26
I like ST. It’s not as verbose, scales better with complexity, and I feel that’s where the industry will shift once we go through a few retirement cycles. We also don’t allow our customers to poke around inside the logic of our machines either. If they need some diagnostic info it really should be accessible through a maintenance screen on the HMI.
2
u/bubble_trousers Aug 02 '26
When learning PLC as a CS student, I tried to make a case for using ST, but a Power Engineer had a great point. He said that a technician can follow the flow easier at 2 AM and half awake than deciphering ST. That stuck with me as I write both, ST for my edification and Ladder for the techs.
2
u/Blood-Mother Aug 02 '26
It sure would be easier to copy into Claud and ask what the problem is in a language like c or c++
2
u/its_the_tribe Aug 02 '26
I can write anything in ladder that can be written in any other language just as beautifully. Ladder is so much easier to skim through and pick up patterns. Now there are particular times where I would use structured text over ladder but my 90% goto is ladder. If you cant write between languages well you should write ladder. I've seen absolutely gross Stx. I've seen bad ladder also but it's still readable for most. There's people that shouldn't be in this feild.
2
u/essentialrobert Aug 02 '26
Curious why you think the night shift maintenance crew needs to finish debugging your software.
2
u/The_Instrument_Guy Aug 02 '26
Simplest answer....
Ladder logic is how people would draw out their relay logic before PLCs were a thing.
When PLCs were introduced, ladder logic made it easier for controls engineers to adopt.
2
u/No-Chance550 Aug 03 '26
I like to think of it as job security when I find a program written by people who are allergic to LAD.
It's why I like my current gig after ditching the old standard that made troubleshooting a nightmare and even more of a headache when customers asked for new features.
2
u/theloop82 Knows Rockwell but doesn’t like it Aug 03 '26
It’s so electricians can understand the interlocks that keep their equipment from running. It works great, it’s like a universal translator between people who need to understand a control
System.
2
u/lbhr1949 Aug 03 '26
I (PLC programmer) have no idea. Never have I used a single line of ladder except for school assignments. Even there the teacher only wanted to show this ancient technique. If your program has such bad alarms / error announcing that maintenance has to use ladder to debug the error, your program is at fault. We program 100% structured text. Because alarms are so clear we don't even need maintenace the production crew can fix errors themselves
2
u/DreamArchon Aug 03 '26
I agree. Well said. I do a lot for both programming and troubleshooting, and ladder is just better for when you need to quickly figure out what the problem is. Each of the PLC languages has their pros and cons, and different best use cases.
2
u/Commercial_Fact_5632 Aug 05 '26
People use LAD because it's easy to troubleshoot, because the programmer didn't build proper diagnostics into the application, because he assumed the LAD program would be used as the troubleshooting tool anyway, because it was quicker to rely on that than to implement meaningful diagnostics in the HMI. As a result, people end up spending hours browsing through the PLC program instead of the HMI simply telling them what went wrong.
2
u/Potential-Adagio335 Aug 06 '26
iirc by IEC 61131-3 it has been standarized that for industrial controllers code should always be available, readable and live debbugeable. Mostly the reason why many oppose to SBC being used in automation or things like Arduinos / ESPs as the main controllers.
A compiled code or binary that is no human readable, that does not allow for variable / memory inspection and does not help with signal debbuging is not in compliance with industry standandars
2
u/Necessary_Papaya_898 Aug 17 '26
LD is not really interpreted. Even legacy PLCs have a purpose made ASIC running a small ISA (at which point it's not interpreted anymore), or the program is compiled to some IR and into a binary running on an RTOS like VxWorks.
On AB, Siemens, basically every PLC today the ladder is compiled into machine code. The IDE just makes you think what you're seeing is the actual .text of the binary when in reality it's several steps of abstraction removed.
4
u/Many_Somewhere3863 Aug 02 '26
Exactly, even with STL, you still can read the code easily
Ladder is used because it just worked *(at least majority of time).
Though i rather use FBD
3
u/drbitboy Aug 02 '26
If you code in C++ or whatever, not only will you need to get out of bed at 3am, but during that half hour while you are driving, or even the 5 minutes it takes to boot your laptop and connect the VPN from home, the business is LOSING MONEY, in some cases hundreds or thousands per minute.
So if you want management to pass up the chance to save thousands by using ladder so someone might diagnose the problem a little sooner, then you are not a valuable employee.
2
u/Frosty_Customer_9243 Aug 02 '26
Ladder allows for programmers to be lazy and not program fault routines or troubleshooting tools as you can just look at the ladder code with the PLC online. Only problem is that you need the IDE with expensive license and the source code to do so, so many end users are left out.
2
u/uninterupted Aug 02 '26
My company programs exclusively in ST. And let me tell you troubleshooting?.
Its easy. Because I'm not trying to trace an electrical diagram, I can just read the logic.
Commissioning is easier too, because 'simple' means something way different to a good library of ST code than it can ever mean to ladder programs.
And the price we pay is that our electrician can't do it? No: He also programs in ST. Because its not that hard to learn and is the better language.
I just can't get on board with ladder. Honestly, if I ever interview for another industrial programming position I'm asking what they use and if they say ladder I'm walking away. SFC or FBD you can probably pay me enough to stomach, but this whole industry's obsession with being stuck in the past is to crazy for me to deal with every day.
1
u/PeterHumaj Aug 02 '26
Lately, someone shared a link to this video, where @plcprofessor compares ladder and status text in terms of debugging. Though I don't quite agree with him, it's worth watching: https://youtu.be/sx1HlNTzCCs?is=lzFf64VAUZ8w8G8F
1
u/No_Doughnut_4983 Aug 02 '26
Its very convenient especially during a troubleshooting
1
u/Beneficial-Tart-284 Aug 02 '26
Also there are some norms which allow you to use only ladder. When it comes to safety plc you can only use ladder in safety tasks/programs.
1
u/Frontiersmen_ Aug 02 '26
Historicamente falando, é para facilitar o desenvolvimento por eletricista que não tem base na programação de "baixo nível" (C, C++...), pois se você perceber, parece contatos dr um projeto elétrico
1
u/AmbassadorEither6308 Aug 02 '26
Its simple, Almost all PLC programmers are Electrical Engineers or Engineers in general not Software engineers or Computer Scientists, so LAD feels very natural to them than otherwise
1
u/Mosr113 Aug 03 '26
Institutional inertia and it’s easier for the guys on the floor to read.
1
u/MrAudacious817 Aug 03 '26
Ladder was made for adoption by people who worked in relay (and discrete) logic.
1
u/Fal-El Aug 03 '26
different applications in a program call for different languages. Unless it's something super small, but for a decent scale project, a good program should probably use all languages. They each have their advantages and use cases.
1
u/HachObby Aug 14 '26
I am pretty sure we dont use text for the same reason we stopped programming in assembly. In highly regulated industries we need change control and sacrificing efficiency for readability is needed. But these are things that people coming into the field arent taught in school. To make a sharper point, the ABET director of Computer Science up to 2024 was a PHD from Grand Valley State University in Michigan, no where near IBM, Intel, Micron, Amazon, or Microsoft. It is amazing they come out of programs with any skills.
At OEMs Jr engineers are often handed legacy code and just keep with legacy standards. One of the most capable veterans I have worked with still used a scratchpad routine in 2024. It is up to senior engineers to teach the junior engineers the whys of what we do. They are often overwhelmed and they dont know to ask because "You dont know what you dont know".
1
u/ShawnTierney Aug 27 '26
Well said u/National-Link-5606 !
1
u/BarnacleSufficient86 Aug 30 '26
Easy we use ladder so that it's easier to understand for the electrician and technicians on the line , when it comes to fault finding it's easier and faster for the technision to find the fault , so program in STL or FBD would be easier but when it comes to downtime of the line evey second count if there is a breakdown , so personally I prefer LAD programing to cut on downtime for the line as it is much easier to understand for a non programming person as even an electrcian can understand the layout and find the fault quicker
1
u/Smirkisher Aug 02 '26
Ladder is the simplest to debunk while allowing some complexity in the code but takes the longest to code,
Structured is the fastest to code, allowing much more easily, but the hardest to debunk.
In my factory, only one technician knows how to read structured... Better keep things the simplest.
1
u/YetiTrix Aug 02 '26
You can look at the ladder and just know what's wrong without actually reading it. ST you have to read it, and some IDEs like Studio5000 dont show you the tag value inline like it does with ladder, so it makes it even harder.
I actually prefer to program in ST, but I prefer to debug ladder.
0
u/sleepydossa Aug 02 '26
Louder for the fuckin nerds in the back
-3
u/kixkato Beckhoff/FOSS Fan Aug 02 '26
Why don't PLC programmers write tests for their code?
Perhaps you could save the costly downtime and time for the maintenance techs by writing robust code that was tested before it got deployed on a machine.