Function Block Diagrams

Dec, 3 2009

Electrical

We've been busy with PLC training all fall. This edition of Newsletters that Teach is for the E and I gang, and anyone working with PLCs.

Function block diagrams (FBDs) in Programmable Logic Controllers (PLCs) are an alternative to ladder logic programming. When they are well designed, a FBD may be more readable than ladder logic, especially when dealing with large and complex programs. Using a FBD may also allow you to skip intermediate coils and registers that could be necessary work-arounds to ladder’s limited format.

Function block programming is not inherently better or worse than using ladder logic; a lot depends on your own preference and experience. However, both styles of programming are in use in most modern PLC environments, often within the same company, so a basic understanding of both is valuable.

Don't be afraid!

The ladder rungs that you knew so well from the days of relay programming have not disappeared; FBD is just a new graphical interpretation of the same old logic. Many PLC programming environments let you use ladder and function block routines within the same controller project. The two different types of routines can communicate and share data with each other without issue.

A few FBD basics

  • Function Blocks are always read from left to right.
  • Inputs are always on the left side of the block, and outputs are on the right.
  • Unfortunately, a comprehensive visual standard has not yet been adopted, so most programs have some unique elements. It pays to review the basics of the program you are working with to avoid confusion.

Let’s look at a simple start/stop diagram with seal-in functionality.

wiringnothingon thesamefunction

Believe it or not, these two diagrams create the exact same routine. When the start button is pressed (TRUE), AND the stop button is NOT pressed (FALSE), System_Run is energized (TRUE). The OR functionality creates a seal-in, and System_Run remains energized (or TRUE) until the stop button is pressed (System_Run = FALSE).

Lets have a look at the components of a FBD, and how they translate from Ladder format.

Tags (Variables)

examvariables

It is a good idea to make your tag names as informative as possible, to save yourself and others time if you need to review that routine down the road. In our example, this tag is named Start_SW_B. It's not much of a stretch to realize that this refers to the state of the Start Switch for routine B. You may already have your own vocabulary and abbreviations for naming tags; remember that remaining consistent will save trouble.

In our example, red = FALSE, so the red tag name indicates that the Start Switch is not powered at the moment.

Boolean (BOOL)
(A.K.A Bit Level Instructions)

exambool

If you’ve ever written a true or false test, you are already familiar with booleans. Boolean operations mean that there can only be two states, which could be called true/false, on/off, open/closed etc. For example, a classic light switch that you can only flick on or off has just two states. But if you were to swap that lightswitch with a dimmer, it is no longer an example of boolean operation.

BOOL across the top of these Function Blocks reminds you that there is no "halfway" state; the operation must be true, or false.

Function Block

examblock

A function block simply takes input and provides output as determined by the operation specified at the top of the block. The input(s) are always what is evaluated by the function, and the output always depends on that evaluation.

In our example, we have an OR_BOOL. Think of it as saying," If IN1 (Input 1) OR IN2 is active, make OUT (Output) active." And that's all there is to this very basic function block.

Some simple boolean functions include:

    OR
  • If any or all inputs are true, the output will be true. Only when all inputs are false does the output become false. This is an "inclusive OR."
  • XOR
  • This is an "exclusive OR". It follows the same rules as the regular (inclusive) OR, except that the output will be false if more than one input is true.
  • AND
  • AND requires all inputs to be true in order for the output to be true.
  • NOT
  • NOT simply flips the input; true becomes false and false becomes true. Like a normally closed ladder instruction, NOT only accepts 1 input and has only one output.
  • NAND
  • NAND is like combining an AND function with NOT, or a pin inversion. If your inputs are all true, then your output would be true, except that the NOT part of the function inverts the output. So, all true inputs = false output. Mixed true and false input = true output. And all false input = true output.

In Plain English, Please

Now that we have a basic understanding of some boolean function blocks, lets talk through the diagram that we saw earlier.

Pre-existing knowledge: This program uses RED to indicate FALSE, and GREEN to indicate TRUE.

wiringnothingon talkitthrough1

And the same diagram, at the moment you press the Start button (not shown) to turn Start_SW_B true.

wiringstartswitchpress talkitthrough2

The arrow points out that that System_Run_B is the same variable as is used in the OR condition check. This variable has now been turned true (green) by pressing the start switch; it will be true (green) in both locations from the moment the start switch is pressed.

So after the start button has been pressed and then released (above), the seal-in condition looks like this.

wiringsystemrunon talkitthrough3

The seal-in condition is broken when the stop button is pressed.

wiringstopbutton talkitthrough4

Once again, it's important to remember that the output variable that we have just turned false is the same variable that we use in the OR function at the beginning of the routine. This breaks the seal-in condition, and we return to the original state of the circuit.

wiringnothingon talkitthrough5