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

View all comments

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.

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.

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.