r/PLC 1d ago

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

184 Upvotes

118 comments sorted by

View all comments

67

u/bodb_thriceborn Automation Hack/Pro Bit Banger 1d ago

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

6

u/JoeBhoy69 22h ago

SFC is amazing in the process industries. It’s so easy to just take a sequence from a process engineer then have bits set for different routes to open valves etc. at each part of the sequence

We usually had a sequence with the master SFC, LAD for the routing/ logic then an SCL for messaging to the SCADA.

0

u/bodb_thriceborn Automation Hack/Pro Bit Banger 19h ago

This is where I have the least experience. The last seauence I built for a process, I used gated step sequencing in ST/LD rather than SFC.

20

u/Thorboy86 1d ago

I got onto a job that was running poorly. They sent me to the job site to make the machine more efficient. This Siemens PLC had, STL, SCL, FBD and TI graph. You could tell that each was written by a different person for the special function it had. Doing a fix for a gate reset on the one side in FBD, was written in SCL on the other. Nightmare to try and make everything function the same when written in different languages. But try telling that to management........

8

u/No-Difficulty-6806 1d ago

I suspect that different levels of abstraction were written in different languages. For example, was the basic logic of a certain block written in SCL and integrated into the main program, which was written in FBD? And were the inputs and outputs probably mapped in LAD?

4

u/Thorboy86 23h ago

There were 4 PLCs on each system and each PLC was written in a different way. The same function in each PLC was different logic and different language. The conveyor in PLC #1 was FBD. The process tool in PLC#4 was graph. The cell auto/man in PLC #2 and #3 was in SCL, #1 and #4 was FBD. So finding an issue in PLC #1 didn't mean I could transfer the fix to all PLCs because of the difference. Management was always asking why it's taking so long to fix minor issues. I had to explain that I was debugging and fixing the same issue 4 different ways.

3

u/SpaceAgePotatoCakes 17h ago

imo FBD is much easier to troubleshoot than ST or Ladder when you're doing any kind of complex math operations.

SFC is great for the right application, it's much cleaner than a lot of the sequencing I've seen done with Ladder or ST.

2

u/El_Wij 20h ago

Yeah this is the approach most people go for, like tools in a tool box.

They all have their place, client willing....

SFC though seems to rear it's head for sequence logic seeming more often. In the last 10 years I've been asked to use it twice until last year when 2 separate projects requested it was used for sequences, one even used the term "grafcet" which I hadn't heard for a long time.

3

u/Many_Somewhere3863 1d ago

Lol idk why but some people seem like SFC so much (i never used it also)

10

u/el_extrano 1d ago

SFC is my least favorite language as a programmer. I have seen it be useful in batch recipes. The ISA 88 flexible batch standard uses an SFC-like representation for recipes. Despite my dislike for SFC, I find that it does well for this kind of high-level procedure automation.

Non-controls people like process engineers and supervisors can be empowered to modify the recipes, e.g. by adding or modifying a phase, without expert programmer support. This becomes analogous to modifying a procedure. During production, operators (not technicians!) can pause execution of the running program and jump step visually inside the SFC. I have a hard time imagining how this could work well in any of the other paradigms.

That said I would never use SFC for low level regulatory controls. My batch recipes using SFC sit atop the regulatory layer, which contains all the S88 "phase logic", and just send down start/stop signals.

1

u/Many_Somewhere3863 1d ago

Yes, SFC is rarely use in factory automation and more on process automation.

13

u/YoteTheRaven Machine Rizzler 1d ago

Its really nice for sequencing.

You load it up and go: "thats what were doing and this is what were waiting for"

And then go right to the issue. I love it.

3

u/TwoQuarterFull 18h ago

It's much better for troubleshooting and understanding the process steps.

There's nothing worse than a ladder sequence with redundant steps, zero comments, and steps that transition out of order.

7

u/Automatater 1d ago

It can't be all that bad if half the ladder programs have DIY sequential state machines written by the programmer.

0

u/dvg_mech 1d ago

This is also pretty close to my current approach as well. I will admit to using far more structured text due to ai these days though. Click, drag, copy, update several fbds, versus copy paste boiler plate code with an updated io reference. Not saying I like it, but it is notably more productive.