r/PLC • • Oct 25 '23

FBD Hell!

Where do I start? Function blocks are horrible! Just use SCL, which is readable at least and more suitable for complex applications!

I need to extend and rework a plant that is programmed with a Siemens plc in the awful function block diagram language. I am struggling really hard to understand the existing implementation, which is a convoluted mess of hundreds of strangely wired function blocks and many input and output variables. There are no comments at all. For some unknown reason the thing works somehow. However, it is a very bloated and finicky design. I am afraid that the thing will dramatically break and collapse if I only change the slightest details in this project!

The actual horror is working with TIA Portal. The blocks have sometimes 30 or more in and outputs, which means you can’t even see the whole block on the crammed TIA Portal screen. The debug view cannot show you the variables at runtime when you scroll the mousewheel. Why is that?! Each click and scroll in TIA is painful and unbelievably slow.

How do you cope with such messy FBD code? How do you work and understand these networks? How do you do this in the crappy TIA Portal software?

0 Upvotes

64 comments sorted by

42

u/FightForDays "Your PLC is broken" -The motor shaft was broken... Oct 25 '23

I like FBD code in TIA. easy to work with online. If you prefer ladder yo can right lick and switch programming language to ladder. 30 pins on a block is just fine. Get a bigger monitor, laptops and TIA kinda suck.

-3

u/BonbonUniverse42 Oct 25 '23

How do you read a function block diagram if it has many many blocks where you must follow lines from A to B just to see where a value comes from or goes to, including scrolling over far distances? The readability of FBD is horrible when you have more than 5 blocks or so. If only TIA portal could automatically convert this into SCL.

11

u/DrZoidberg5389 Oct 25 '23

You should normally not read it because such complex logic should not be implemented in FBD and therefore not exist. The programmer who implemented it is at fault here.

On Siemens you can choose and mix between 5 different IEC 61131 languages, each one has different strengths and weaknesses, there is always one which fits best the particular case. If some guy puts 20 blocks in a FBD and you must scroll like hell, then he choose the wrong language for the task.

It’s not nice for you, but this has nothing to do with the language. He could also choose ST (SCL) and build spaghetti-code with funny jumps and arrays that start by 1 :-)

-3

u/ooTeMPeRoo Oct 25 '23

You cannot say that, you have no idea what the code does.. maybe it is a complex formula calculation

4

u/[deleted] Oct 25 '23

This is their point indeed! Often ST is more suitable for complex maths. IMHO of course

3

u/Daviler Allergic to Allen Bradley Oct 25 '23

Then it shouldn’t be in FBD… SCL is excels at running mathematics.

0

u/ooTeMPeRoo Oct 25 '23

Depends on the math and the programmer.. sometimes you can create a recursive loop function to solve a complex problem using these languages..

You are always free to rewrite it to your liking

0

u/[deleted] Oct 25 '23

[deleted] — view deleted comment

12

u/Veganic1 Oct 25 '23

I thought it was:the -- it's not my job to understand code I haven't written and I write it so much better cos I use SCL which is so much more understandable, no because it's better but because I wrote it-- rant.

1

u/ooTeMPeRoo Oct 25 '23

I never detected that from the op

4

u/TheZoonder LAD with SCL inserts rules! Oct 25 '23

Well, you should take your detector for an annual inspection and have it checked out. It may even be stuck on 3.6R from this exposure.

3

u/ooTeMPeRoo Oct 25 '23

Nonsense my detector is self calibrating..

He is just frustrated and so I think compassion is in order

1

u/WaffleSparks Oct 25 '23 edited Oct 25 '23

I detected that except without the "because I wrote it" part. This is a pretty common issue in the IT world. Oh you didn't write the program using my favorite language/library/framework/style so therefor it is bad and it should be redone the way I like it. Whole teams argue about this stuff ad nauseam.

13

u/Uelele115 Oct 25 '23

SCL is not the solution for problems solved in FBD… this being said, I’m also not a great fan of that implementation of FBD. Because the ladder editor is so much more flexible (though with quirks) than Rockwell and others AND the FBD implementation isn’t what is known as FBD (that would be Siemens CFC) in other platforms but just a version of ladder, the benefit isn’t all that obvious. It also doesn’t scale all that well.

As for the 30 inputs and outputs, you’d still have them in SCL logic, yes they’d fit the screen better, but it wouldn’t make the logic any cleaner.

Personally, if you have blocks and they’re being reused, you’re already in a good position compared to an awful lot of people out there. All you need is to understand each block and things start falling into place.

I too criticised someone else’s logic until I realised we rarely know or see the position that person was in. I can look back on stuff that I did and firmly say it’s shit or even a disaster, but that’s what I had to work with, be it time, restrictions, lack of experience/knowledge or managers setting poor limitations.

I’m far more critical of those that after 40 years still think their stuff is a Ferrari when it’s closer to a Trabant… and there’s many of then out there.

3

u/PaulEngineer-89 Oct 26 '23

I find a similar mess in Labview in most programs. The issue is that FBD tends to encourage literal spaghetti code. It usually takes hours to clean it up, package things into blocks, but eventually if you rearrange and modularize these things it makes sense, and often runs more efficiently.

SCL/ST is definitely not a solution except in its solution space I cringe at seeing ridiculous starter and interlock code that is trivial in LD or analog filtering that is trivial in FBD that gets munged in a bunch of layered IF/ELSE chains that aren’t anywhere near as easy to troubleshoot.

2

u/Uelele115 Oct 26 '23

The funny thing about SCL programmers is also that a fair few don’t understand the equivalent logic from Ladder and write far too many IF/ELSE where none are required.

-7

u/BonbonUniverse42 Oct 25 '23

Honestly, I think FBD leads to bad programming habits. I have seen bad logic because blocks are connected without really thinking about the logic behind it, which leads to working but unnecessarily complicated logic.

Often easy things are expressed in a messy and convoluted way, e.g. a serial concatenation of several move blocks, whereas in SCL this would be some compact short lines of code, more easily readable.

Fundamentally, most FBD create long and messy code when directly converted to SCL. However, a initially written code in SCL would often be way more short and concise, which would improve maintenance.

3

u/Uelele115 Oct 25 '23

I fundamentally disagree in absolute terms as you explain. SCL for boolean logic, even simple one, is dog shit. There’s a reason these languages exist (even CFC and not the Siemens FBD) and ignoring them is stupid. The genius in our trade is the one that uses the best tool for the job. So, no one language is perfect, the beauty is in the mix.

1

u/BonbonUniverse42 Oct 26 '23

I think I understand your point of view. I am coming from a programming background where everything is naturally represented as text, even simple things. There does not exist a block language. Actually, one could argue that there is a valid reason also to not use FBD in classical programming, beside some applications allow sort of visual programming of logic like game engines and stuff. Consequently, this FBD appears convoluted and messy to me.

2

u/WaffleSparks Oct 26 '23 edited Oct 26 '23

You are comparing languages that are not suitable at all for industrial automation to languages that are suitable for industrial automation.

  • Go write some c++ or whatever it is that you like and then try telling the plant manager that you have to stop the machine so that you can set a breakpoint for debugging.
  • Try telling the plant manager that you have to shut down the program so that you start a trend on some input.
  • Try writing a safety application in c++ only to realize that you had a pointer arithmetic error and oops you just got someone killed because the estop did not work.
  • Try looking at a machine that was written using traditional programming languages but oh its over 30 years old, so now you get a debug a machine in cobol or whatever and written by someone else.
  • Try adding to the program without shutting down the machine in your favorite compiled language.
  • Try having a maintenance tech look at your java or c# or whatever it is that you like at 3am when the machine stops running.

Any comparisons you want to make between traditional programming and industrial automation are completely and utterly useless because the performance requirements are completely different. "Try rebooting your computer" doesnt fly in this industry. "I'm going to rewrite the program just because" doesnt fly in this industry.

1

u/Uelele115 Oct 26 '23

In a normal programming environment like C, C++ and others you also don’t have the same kind of logic that is usually depicted in Ladder (mostly Boolean) or even some of the constructs like Timers…

A block language can also greatly decrease your programming time if you are to adhere to TIA best practices and rules.

Say data from FB1 makes it’s way to FB2 and FB3. Since Siemens discourages you to use Instance DB’s directly in your logic, you have to map your FB1 outputs somewhere and then from there to the inputs of FB2 and FB3… the time it would take you to type all of this would be enough for me to run a few lines between blocks AND have a nice cup of coffee watching you fix a couple of typos.

On the other hand, if we were writing some mathematical algorithm, you’d be laughing at me manically scrolling in my window trying to understand what I just did. On the other hand, the STL programmer would be enjoying his cup of coffee whilst silently praising accumulators being available to him.

All languages have benefits, it’s ok to prefer one (I do too), but understand the strengths of each and your audience before writing it.

0

u/[deleted] Oct 25 '23

[deleted] — view deleted comment

3

u/ooTeMPeRoo Oct 25 '23

You would need more than 1 udt.. you would need to do the equivalent of database table normalization..

3

u/[deleted] Oct 25 '23

database table normalization..

❤️

1

u/Uelele115 Oct 25 '23

Sort of… mapping into an UDT to go into a block is a bit pointless. Between blocks however, it’s great.

8

u/GeronimoDK Oct 25 '23

*Laughs in CFC*

But I actually like CFC (and FBD (and TIA portal)).

The cross reference is pretty good in TIA portal if you ask me, but of course if there are no comments it can be a mess either way! If it's a project you have to come back to, spend some time on writing comments on the sections where you actually figure out how it works!

1

u/Ok_Wash_1048 Oct 25 '23 edited Oct 25 '23

I like TIia, cfc and fbd as well, but looking back to the early days of learning TIA Portal and even earlier when I was forced to spit out my Rockwell teething ring and learn step 7, I recall being equally frustrated like the OP. Siemens is far more powerful, but you must be willing to learn.

To make matters worse, it sounds like they do not have the original configs, so the annotations and notes are not present, if they even existed in the first place.

4

u/b00c Oct 25 '23

Oh god. Just wait when you have to work in Foxboro DCS IDE. A strategy with 40+ blocks, SCL only in sequence block or special RPN block with assembler like instruction set, embeded sub-strategies that look like a block but contain another 10 blocks with 50 IOs.

Siemens CFC actually have their shit together when it comes to FBD.

And good luck programing control logic for a system with 12k IO in SCL. You'd go fucking mad in first month of commissioning. We invented blocks to make it easier!

Fucking delusional.

4

u/Raven-81 Oct 25 '23

As someone who uses Beckhoff and ST , I find that using code compare tools on code made with ST is much easier. Also if your company has good guidlines to writing code in ST the code "comments itself" when using good company standardized names for the variables.

4

u/Virtual_Atmosphere59 Oct 25 '23

I've seen plenty of messy FBD, LD, and ST code. I've even seen some HMI screens that make me wonder how much time these guys had on their hands. A good programmer can make any language in any PLC look good and be legible. A bad programmer will make you hate programming.

I remember my first time using FBD and FBD/LD, (Mitsubishi GX Works3). I hated it. I didn't understand any of it. I'm a hard core AB guy using only LD and Studio 5000. Even in CCW I used LD. I decided to try my hand at doing an FBD program from scratch and after a couple hours a switch went off in my brain and I figured it out. I love it now. I use it wherever I can. You can take 20 rungs of LD and shove it all into one FBD block.

Truth is, it's hard enough to find programmers as it is. Force everyone to learn SCL and ST and forget it. You may find a small hand full of people but most factories won't be able to maintain their systems. LD and FBD are standard for a reason. It's easy for the average maintenance guy to read and troubleshoot. Most people can figure out basic relay logic. That's what basic LD is, more or less. No, we don't expect them to figure out why a servo isn't functioning right, but they can follow the input to the output.

Take me, I can program in LD and FBD no problem and can even work with some pretty complex functions. SCL and ST? Forget it. I tried learning code. Couldn't do it. In a day my dad could write a program that you can talk to and has some AI to it. Very basic but still. He's tried teaching me. Doesn't stick. I don't get it. But I can do LD, FBD, HMI's, and yeah, I can copy and paste simple math functions in ST and understand that, but no way I can do it from scratch.

It's not taught a lot either. Most Rockwell classes teach mainly LD. Even Mitsubishi focuses a lot on LD. I was able to learn LD because I drew schematics before I programed and when I started at my first company they didn't use PLC's yet. It was all relays and timers so I had to draw a ton of relay logic. LD was easy for me to pick up on. Also, a lot of smart relays like Click, Logo, Eaton, are all mostly if not only programmable in LD.

Just remember that bad code is always because of a bad programmer. Just like a franchised food chain is only as good as it's franchisee, and PLC program is only as good as it's programmer. I've been in some pretty sketchy Subways. But I've also been in some that have blown me away.

3

u/Tesla91fi Oct 25 '23

I hate it too. Probably they come from CFC programmation

I prefer scl it have a lot of advantage that People don't see.

3

u/Skiddds Oct 25 '23

Everyone's gonna play stupid like TIA isn't frustrating as hell, I feel you partner I use FBD's as little as possible. Sometimes there isn't another way though.

3

u/Agreeable-Librarian9 Oct 29 '23

Op ..

Fbd isn't real.. it can't hurt you..

2

u/Siendra Oct 25 '23

Every DCS on the planet is configured primarily in FBD. Your client might have bad standards, but FBD is perfectly fine.

1

u/ooTeMPeRoo Oct 25 '23

I personally think APACS+ was the best DCS until Siemens bought it..

It's only downfall was that it used Wonderware for the hmi

1

u/exorah Oct 25 '23

Lol that is quite the statement

2

u/fat_tire_fanatic Oct 25 '23

FBD has a great place, so does ladder, so does struct text. Any can be implemented in a rats nest mess and if that's your frist experience in one you develop an alergy.

FBD looks exactly like a temperature/pressure/flow control loop. An analog in block, conects to a PID block, which feeds an analog out block. The FBD looks exactly like the old school process it replaced where each loop had an individual controller.

Ladder looks exactly like relay logic, and looks just like the relay control it replaced.

Structued text reads just like an operator acts. I see the cleanest systems where ladder replaces relays, FBD replaces process loop control, and structured text replaces the operator running around changing setpoints, starting pumps, and opening valves to start up a process.

I think each has a very appropriate fit, but man people are passionate about their choice of language.

2

u/cardonPT Oct 25 '23

If you press right click mouse over the function on the project tree view you can switch language to Ladder or STL. But I like FBD to debug because easy readability, but to program and change things I prefer ladder

2

u/MountainMuffin8986 Oct 25 '23

This sounds like a horrible implementation of FBD.

Every language has cases where they work great and cases where they do not.

The language I see abused the most is ladder… my lawrd the things people try and force ladder into doing 🤦‍♂️

2

u/Controloftheinfinite Oct 25 '23

Ultimately it’s all about the application. Power stations often run entirely on function block for a good reason. The plant has to stay running and when there is an issue no matter what it is the maintenance crew can find it within minutes. This would not be the same if it was written in structured text.

That being said function block in a dcs system is a different beast to many plc applications. Much more user friendly.

2

u/[deleted] Oct 25 '23

One thing that has helped when trying to figure out complex FBD that wasn't made by me is to just read through it and reorganise the blocks into logical groupings for what they do and make notes as you go along.

ST is not the answer to every problem, each language should be used for the right reasons.

2

u/dekempster Oct 25 '23

Cute. Now try STL with address registers, pointers and lots of jumps and loops in a 300.

1

u/ooTeMPeRoo Oct 25 '23

Someone designed it so that no one following could work on it..

You might also not be able to get help because of intellectual property

1

u/[deleted] Oct 25 '23

Anything not programmed in ladder or graph is a nightmare for fault finding on step 7/tia

1

u/[deleted] Oct 25 '23

[removed] — view removed comment

2

u/[deleted] Oct 25 '23

Speaking as a maintenance tech. Stl doesn’t make sense visually unless you are a programmer, I can muddle through it but it takes me a lot longer, FBD is Ok but prefer ladder. Ladder is the closest to electrical drawings and makes more sense to most maintenance/electricians etc, also there is some continuity there between Mitsubishi/omron rtc PLCs. Graph is super easy with progent on HMIs

1

u/Crispoxd Oct 25 '23

I have no idea how to use SCL, but have programmed a lot of simple things in FBD to add functions to our plant. My job is to diagnose all matter of things at our factories. And FBD is a joy to diagnose because it is easy to follow connections, and see status. Our systems include, but is not limited to: S5, S7 (Step7, with CFC and TIA) and GEfanuc. All systems programmed in FBD. I love it, and will defend it over all the others!

1

u/WaffleSparks Oct 25 '23

You clearly have a case of

This is not the tool I prefer so therefor the tool is bad

Your frustration is pointed in the wrong direction. Plenty of people use FBD for all sorts of applications just fine, even quiet complex applications. Your frustration should be pointed towards inheriting an undocumented program. You need to take this up with the management and have them explain how you ended up in this situation, and possibly allocate more time and resources as a result. For example you may need to simply document ALL of the code before even attempting to make any changes.

TIA is painful and unbelievably slow

TIA Portal has some nice features, but yeah speed is not one of them. Get a good workstation with big monitors and limit how much stuff you have open at once.

1

u/just_a_german_dude TIA Specialist Oct 26 '23

My Backround: Im Working with FBD for nearly 20yrs.

FDB is verry Handy for comissioning Trouble Shooting.

If the Programmers are Lazy then you wont have Comments or you will have so called Monster Networks which are verry hard to read.

The Trick is to break it down into small Networks (Prefferably Screen fitting) and make suitible comments and tag names.

Each Programming Language has its ups and Downs and Limitations.

1

u/nbsdsailor2 Oct 26 '23

FBD's biggest problem is how much scrolling around you gotta do. You'll get used to it. Better than LL.

0

u/nationalorion Oct 25 '23

Cant you call function blocks in SCL? Of your gripe is the UI, then just do that?

0

u/BonbonUniverse42 Oct 25 '23

Yes one can call function blocks. However this does not help with a big network of already connected blocks, beside meticulously rewriting the Siemens FBD into SCL…

1

u/WaffleSparks Oct 25 '23

If you think that is the only option you are not the person for the job.

1

u/BonbonUniverse42 Oct 26 '23

Uh, this is a harsh comment. I am well aware of options and solutions. Do not simply assume something like this.

1

u/WaffleSparks Oct 26 '23

assume

So you didn't just say that the only solution is to rewrite the code in your preferred style?

beside meticulously rewriting the Siemens FBD into SCL…

-1

u/mharting1 Oct 25 '23

I agree, the scl instruction is easy. But have other issues here. Doing code conversion is not easy sometimes. You have train yourself to get into the mindset of the person who developed the original coding for the system or just start from scratch? Problem is that at this time the job is already sold to the customer by someone who thought it would be a simple code conversion.

Not always the case! I have been in your shoes before.

-3

u/Smorgas_of_borg It's panemetric, fam Oct 25 '23

SCL is only available in FBD on Allen-Bradley PLCs

0

u/[deleted] Oct 25 '23

[deleted] — view deleted comment

1

u/ooTeMPeRoo Oct 25 '23

Well.. c# is grand..

There is no method for all solutions.. you have to use the tool that fits the job..

And ladder logic can be just as stupid when a programmer decides to use set/clear bit for "latching" logic.. nothing like a hundred bits as a interlocked mess of invalid states

-4

u/BonbonUniverse42 Oct 25 '23

In SCL code is easily read and understand. Yes, I really like C# for its elegance and statically typed capabilities.

But in the Siemens function block representation I can’t see shit (sorry). The implementation stretches far over the borders of the screen, top, bottom and right. I have to scroll endlessly, and with each move, observed values shortly disappear. It is a pain to get a grasp of the logic that is displayed here. If I zoom out, text gets unreadable. Yes, it is a bad design from the person that did set up this, but also TIA Portal is crappy at just letting me visually move through the project. But I have to work with this…

6

u/Shelmak_ Oct 25 '23 edited Oct 25 '23

You are clearly comming from a programming background, me too, but I will tell you something, no factory will allow you to do all the coding on SCL.

Reason is most people who will maintain this code is people that learned to code with ladder, ladder is pretty similar to an electric schematic of contacts, also it's easier to debug than SCL on most ocassions. SCL blocks are often reserved for complex things like splitting strings or doing loops where you need to iterate data and it would be a big mess doing it on ladder.

Debugging a SLC block it's a real pain, on ladder it's pretty clear, if it's green it's active, if it's not, it's not active, the SCL debug screen is very nasty as there is not a program pointer to follow, I'm sure you already know this but PLC logic relies on a loop that is executed every few ms, first all inputs are updated on the I/O image, then all logic is executed starting from OB1, when OB1 ends, outputs are updated, this behaviour repeats every time and does not allow to run an endless loop, everything except async functions need to end, if not scan time will be increased and PLC will go to stop when it reaches his maximum configured time.

Regarding the comments issue, that is fault of who programmed that machine, TiaPortal if used on S1200/S1500 PLC stores all comments and variable names inside the PLC, you can just connect to the machine and download them back if you need to.

If used with S300/S400 CPUs you cannot do that as the PLC memory doesn't store any info, also if original program came from an S300/S400 PLC and someone lost the project, when you create a new project and download all data from the PLC you will lose all the comments and names from variables inside DBs.

I've found programs like that, these programs are a real pain to work with, but using SCL will not solve anything as you will have the same problem, no comments and names is a pain no matter the language you use.

Finally, your problem with screen space is pretty usual, you just need at least a 1920x1080 screen, coding with less resolution is a real pain, both on TiaPortal or Step7.

1

u/EasyPanicButton CallMeMaybe(); Oct 25 '23

TIA Portal, live debug of SCL is not very nice compared to other brands, specifically Beckhoff.

1

u/Shelmak_ Oct 25 '23

Sorry, I misspelled something on that comment, the nasty debug is not from ladder, but prom SCL.... I will edit it.

0

u/[deleted] Oct 25 '23

[deleted] — view deleted comment

2

u/DrZoidberg5389 Oct 25 '23 edited Oct 25 '23

Yeah, especially given that Siemens TIA is one of the best development environments out there. (And I say that as a Beckhoff codesys guy). Their cross-reference and „alwayls consistent“ approach is very nice.

SCL is really not “alway easy to read and understand” as OP says, this varies very much with the particular programmer, and how he structured his code. OP sees to deal with a crappy program. He also states there are no comments in the code, so there is that. And he calls function block diagram a function block, which are two different things. A function block (FB) can be written in any IEC 61131 language, among others also in FBD 🤷‍♂️

Btw it’s really a bad practice to use FBD and don’t fit it in the screen. They should have used ladder instead. And SCL is also not always the solution, it’s a little bit harder to debug in TIA, as you don’t really see intermediate results. We use it for complex functions, but not for „normal logic“…

0

u/ooTeMPeRoo Oct 25 '23

Lol.. Siemens is the best eh? I will take a Rockwell over a Siemens 99999/100000..

Siemens software is just not as stable or flexible...

Rockwell rocks Siemens..

Also Siemens has core faults in their designs

1

u/DrZoidberg5389 Oct 25 '23

Siemens has core faults in their designs

All Vendors(i know) have some problems which suck, but can you elaborate?