The programmable controller’s ladder logic code for the
fill motor starter controls is shown in Figure 5.6c. It shows
how the start/stop station and the level interlock functions in
order to guarantee that the tank does not overflow.
Some programmers advocate the use of state-machine
representation as a planning tool and then implementing the
program directly in ladder logic. Sequential function charts
(SFCs) can be used the same way. The benefits are:
• Design decision are made before programming begins.
• Project engineers can review and make changes before
programming.
• Stakeholders can more easily understand and review
the state-machine representation.
• Once the diagram is finished, it is easy to program.
• The diagrams help document the ladder logic.
Another programming technique is based on the cycles
of a machine. The cycles for the machine are numbered in
sequence and are called states. The set conditions of coils or
a counter is used to indicate which step the machine is in.
All the actions that take place in that particular step are
executed and when completed, the condition is defined to
move to the next state. In addition to the cycle states, an
initial state and a default safe state should also be defined. If
the machine gets stuck in a state because of a malfunction,
this programming technique is easy to troubleshoot, because
only the logic in that step needs to be examined.
LADDER LOGIC ADVANCES
Section 5.2 discussed ladder diagrams and their generation
of commands that energize, latch, and unlatch coils. Other
ladder logic commands read live inputs, outputs, or internal
bits and perform instructions based on their state. Timers and
counters are other sources of ladder logic commands.
In most medium- and large-size controllers, these ladder
logic-style commands are augmented by assembler-style
instructions. Rather than working on bits alone, they operate on
entire words. Some ladder logic extensions take on the character
of high-level languages such as C or Basic.
The assembly language is a primitive computer language,
which Bryan defines as “a symbolic programming language
that can be directly translated into machine language instructions.”
While a particular assembly language is dependent
on the type of machine used, each of the ladder logic extensions
has its basis in some type of assembler language. For
a survey of the many ways of using assembler (and advanced
ladder logic), see the books by Knuth.
Table 5.6d lists some
typical assembler-style instructions along with their comparable
ladder logic instructions.
Program Flow Modification
Some of the ladder logic extensions shown in Table 5.6d
modify the program flow. Conventional relay logic commands
execute sequentially. In this case there are no changes
in program flow, because each instruction is executed in every
program scan.
A GO TO command, when invoked, dictates that certain
portions of the program will not be executed during the
particular (current) scan. It allows the program flow to jump
over the commands between the GO TO and the destination
that is indicated in the GO TO.
While the GO TO instruction is frequently used in general
programming practice, it can make programs difficult to
understand and maintain. A better device that serves the same
purpose is the subroutine. The subroutine has a beginning,
usually marked by a subroutine number, and an end, noted
by a RETURN. The subroutine is executed by a JSR (jump
to subroutine) or similar command (GOSUB, for example).
When this occurs, the program flow goes to the label indicated
in the command and executes the instructions that
follow.