Learn to Write Ladder Logic

For those who are just starting to learn how to write ladder logic, writing your own template is simple. Here’s a great way to start practicing:

  1. Write some mutually latching/unlatching rungs for maintenance/manual mode and auto mode.
  2. Write a few either latching or numerical register comparison fault rungs — say a generic timer rung for an actuator and a generic E-Stop rung.
  3. Create a system fault bit resulting from the fault rungs and place it into your mode logic in the proper place.
  4. Write a few generic input and output buffer rungs using your mode logic in the output rungs. Your inputs that drive some sort of tag, such as InX_status, can establish your input buffer rungs. Separating these into separate subroutines (or function calls/blocks) makes them simple to copy into other programs later. Even a simple auto sequence with a first step, last step, and a single generic middle step using some of your generic I/O bits can be valuable. Be sure to keep them in separate sections or routines, which will be useful later.

Typical Timed Motor Fault Logic

Figure 1-Typical Timed Motor Fault Logic

PLC Project Planning & Design Procedure

Outlined below is the general procedure Automation Consulting LLC typically follows for its projects:Start with a kick-off meeting and a discussion with the design team.

If there is a machine layout available, use that and mark it up by hand. If a machine layout is not available, use a piece of graph paper and draw a layout. Use solid dots for valves, open circles for motors, X for a prox or limit switch, E and a dotted line for a photoeye and arrows for direction of movement. Then, use this drawing to generate an I/O list.

Create a timing diagram.

Excel can be used for this. This spreadsheet will have a list of actions with a column for actuation time and bars for “on-time” for the actuators. It resembles a Gantt chart with actions starting where others end. This is used as a basis for sequences.

Develop the I/O list.

Again, Excel is a great tool to use here. This list should follow naturally from the previous two steps; however, it is important that the names of actuators and devices are firmed up here. Use concatenation to generate tag names that stem from the original device names here (i.e. Device_pb, Device_ind, Device_extpx, Device_retpx, Device_fault, etc.) If the controller doesn’t use tags, the same thing can be done by assigning bit addresses and comments or descriptions. The same spreadsheet can be used for fault lists, messages and data collection tags.

Establish a flow chart.

The IEC 61131 Sequential Function Chart can be used as a basis and create the chart in either Visio or AutoCAD programs. The components are Steps with their associated actions, transitions with their logic conditions, and directional links between steps and transitions.

Create the program template.

The program template is simply a base program with some simple mode logic (Auto/Manual/Step), a single sample input rung, output rung and fault, which can be replicated from your I/O list. The sequences are created using the flow chart, which was, in turn, generated using the timing diagram.

Depending on the programming software, tags can be copied directly from the I/O list. Some software even allows XML imports, which means you can use Excel macros to generate Instruction List code, which can be converted to ladder logic. This can be handy with duplications, like I/O and faults.

Machine-Zone-Cell Hierarchy

Pictured above is a flow chart that illustrates the machine level layout process. This shows a Machine-Zone-Cell hierarchy – a standard for line and machine layout.

Establish a Standard Method

sample plc programming layout template

Pictured above is a sample layout template that can be used for programming. In this example, the Zone designation is almost entirely safety related. Everything starts and stops simultaneously, and a fault within the zone issues a cycle stop for the entire zone. Cells within the zone offer convenient ways of organizing mechanisms and devices that act as units. They also typically have one main sequence that operates the cell actuators; however, some have more. Generally, each cell also has its own homing routines, fault structures and I/O.

The names used for these organized elements will vary. For example, cells may be called stations and processes or zones may be called workcells. There are also many different ways to organize programs and machinery, so it is important to find which method you prefer. Just make sure you have a method and standardize that method as a template so all employees in an organization can easily work on each other’s’ machinery.

There are many different ways to organize programs and machinery, people tend to like one method more than another but it is better to have some method rather than none at all. Machine builders usually standardize on a template so that other employees within the organization can easily work on each other’s machinery.