Differences Between PLC Programming Languages

There are a few different methods of programming for a Control Logix processor, listed here in the order of most common to least common:

  • Ladder Logic (Most common, Preferred)
  • Function Block Diagram
  • Sequential Function Charts
  • Structured Text

In this tutorial, I will go over the different methods and describe how they work. Hopefully, the differences between programming methods will be clear.

First Things First

Each method has its own instruction set. Some are very similar between methods but some instructions are only available in one method versus the other. For example, the PIDE instruction, which is called “Enhanced PID” is only available inside the function block diagram method.

In a Control Logix PLC, combinations CAN be used in conjunction with each other. The different routines can access the same tags regardless of method, meaning that a function block diagram can access the same tags as a ladder routine. It is good practice to use one method of programming, but if a different instruction is only available in the other method and it needs to be used it is possible to have two or three methods.

Programs

For this tutorial, a routine was created in each method that does the exact same thing. The routine takes in a “Trigger” tag and outputs a “Output” tag. The “Output” tag turns on for ten seconds, then off for ten seconds, then repeats until the “Trigger” tag it cleared.

Ladder

Ladder Logic
Figure 1: Ladder Logic

With ladder logic, you place different instructions on what are called “rungs”. Each rung has input instructions and output instructions. The input instructions are on the left and the output instructions are on the right. It simulates a “circuit”, with the left side being the power rail and the right side being the common rail. If the simulated “power” gets through the input instructions, it executes the output instructions. These routines are scanned from top to bottom, left to right. To elaborate, rung 1 will complete in entirety before rung 2 input instructions are evaluated.

In the case of the example above, the input instructions are normally open (XIC) and normally closed contacts (XIO). XIC and XIO are the formal names of the instructions. The output instructions are TON and OTE instructions. The TON is a “Timer On Delay” instruction and the OTE is an “Output Energize” instruction. As described above, when the trigger tag (LAD_TRIGGER in this case), the output will come on for ten seconds then off for ten seconds. The output tag, in this case, is “LAD_OUTPUT”.

Ladder Logic is the foundation of programmable logic controllers, and the most widely used. People argue that anything can be programmed using this method and the other methods are not needed, which I support, although I will go over the other methods.

Ladder Logic Pros:

  • Well-organized code on rungs
  • Supports online changes well
  • Comments are visible and organized
  • Instructions take up little memory.

Ladder Logic Cons:

  • Some process control instructions are not available
  • Scanning issues can be created
  • Difficult for motion programming
  • Difficult for batch programming

Function Block Diagrams

Function Block Diagram
Figure 2: Function Block Diagram

The above image shows an example of the exact same program written in a function block diagram. With the function block diagrams, the user places instructions on a “sheet”, and one routine can have multiple sheets. Input instructions and output instructions can be anywhere on the sheet. To connect the input and output instructions the user places wires between terminals. The sheet is scanned “continuously”, meaning there is no discernable start and end, but that sheet 1 is scanned before sheet 2 and so on. The user must keep this in mind when using this method.

In the case of Figure 2, the input instructions Input Reference (IREF), and the output instructions are TONR (Timer On with Reset) instructions. TONR instructions are available in Function Block and Structured Text, but not available within the Ladder or Sequential Function Chart.

This is a good method to program motion controls. The user can setup ramps and s-curves for a VFD or servo motor.

Function Block Pros:

  • Good for motion controls
  • Good for low level signal processing
  • Visual method may be easier for some users
  • Wide instruction set

Function Block Cons:

  • Code gets disorganized
  • Sheets stack up and it gets tough to debug
  • Instructions take up more memory than in Ladder

Structured Text

Structured Text
Figure 3: Structured Text

This image shows the exact same program but written in structured text. The user writes every line of the routine(s) by hand. The keywords and instructions are blue, and the tags are colored red. The routine is scanned from top to bottom, left to right. The instruction set is similar to the instruction set for the function block diagram. As seen in Figure 3, the TONR instruction is used. Like function block, tags can be “wired” up to instructions by setting them equal. For example, in the above image, “ST_OFF_TIMER.TimerEnable” is wired to “ST_ON_TIMER.DN”. When this executes, that line of code will start “ST_OFF_TIMER” after “ST_ON_TIMER” is complete.

Structured text is only useful for a large amount of calculations. It is not recommended for anything other than setting tags to values. Sometimes, when editing online, the edits do not take and the user must download again.

If the user is familiar with programming languages such as Matlab, then they should be comfortable within this environment. Like in Matlab, the “:=” is to set “something” equal to “something”, and the plain equal sign is to compare a variable equal to a different variable or a constant.

Structured Text Pros:

  • Code is organized
  • User controls operations
  • Good for large calculations

Structured Text Cons:

  • Very abstract
  • Difficult syntax
  • Hard to debug
  • Hard to edit online

Sequential Function Charts (SFC)

Sequential Function Chart
Figure 4: Sequential Function Chart

The next figure shows an example of a sequential function chart. This is the same concept as a traditional flow chart. There are conditional objects (in this case called transitions), and action objects (in this case called steps). The transition objects appear like so:

Transition Objects
Transition Objects

and the steps like so:

Steps
Steps

 

The user places these at any point on the chart, and the chart size is variable unlike the fixed sheet size in function block diagrams. Each step can have a set of actions, which looks like this:

Step Actions
Step Actions

In that case, there is only one action, but each step can have multiple conditions. The user can split the sequence using branches of steps or transitions. The user wires the steps and actions using wire similar to the method in function block diagrams. A step HAS to be wired to a transition and vise-versa. Steps can’t be wired together in series neither can transitions. Steps and transitions can be wired in parallel to split sequence.

Each transition is a statement, not just a tag, and will allow the sequence to the next step when the transition yields true. Here are some examples:

Example 1
Example 1
Example 2
Example 2

The steps have built in timers using the configuration for each step. Look at the example here:

SFC Step Properties Window
Figure 5: SFC Step Properties Window

During online mode, the SFC shows the position of the sequence by putting a green box around the step that is executing. As seen in figure 4, step_000 is active.

The SFC in figure 4 does the exact same thing as the other programs do: it turns on and off the output tag for ten seconds if the trigger is pressed.

If the user is familiar with OPTO-22 programming, then they would be comfortable in this environment, as it is the same flowchart style programming.

SFC Pros:

  • Online mode offers easy debugging
  • Built-in timers for steps
  • Actions attached to steps in user specified order

SFC Cons:

  • Abstract code can get disorganized
  • Syntax can be difficult
  • Complex sequence to do simple tasks
  • Online editing is a challenge

Conclusion

Each method has their application and their strengths. Ultimately, the user must decide what environment they want to be in for the task they want to accomplish. It will depend on the user, and it will depend on the task. Luckily, AB controllers support all three.

 

For more information or to purchase a PLC module, please visit our home page here.

dosupply
Posted on:
DO Supply Inc. makes no representations as to the completeness, validity, correctness, suitability, or accuracy of any information on this website and will not be liable for any delays, omissions, or errors in this information or any losses, injuries, or damages arising from its display or use. All the information on this website is provided on an "as-is" basis. It is the reader’s responsibility to verify their own facts. DO Supply Inc. is not an authorized distributor and is not in anyway affiliated with Rockwell Automation. DO Supply Inc. makes no representation as to your ability or right to download, obtain, or use any firmware provided by the product's manufacturer. To the extent you wish to use such firmware, it is your responsibility to comply with the terms of any applicable license or other such agreement related to the download, installation, or use of the firmware. DO Supply makes no representation that the version of the firmware that is installed on any product it sells is appropriate for your needs or use. Further, DO Supply Inc. does not sell, re-sell, or license software that may be needed to operate certain hardware and customers must obtain any necessary software licensing, maintenance, or upgrades from the manufacturer or other authorized source. To the extent any of the products sold by DO Supply requires software for operation, you acknowledge that DO Supply does not sell or license such software and that it is solely your responsibility to obtain the software or a proper license to use it from authorized sources.
Post author

Leave a comment

Your email address will not be published. Required fields are marked *