An Introduction to PLC programming
A PLC or Programmable Logic Controller is an electronic or computer device used for industrial control systems. PLCs run a program that manages inputs and logically turns outputs on/off to obtain the desired control. This article will cover the general structure of a PLC program.

PLC programming
Instructions and programs
An instruction or job order is formed by two main parts: operation and function. The function is the complement of the operation and is divided into symbol and parameter. The operation determines the CPU’s job or the kind of instruction that it must execute, and the function determines the address. The address, in turn, indicates where the CPU should execute the instruction of elements such as counters, timers, I/O, and internal marks. Basic examples of instructions are:
LD: (4C) Loads the line
LDN: (42) Negation of the operation LD
AND: (41) AND logic
ANDN: (44) Negation of the operation AND
OR: (4F) OR logic
To write a program, other kinds of instructions called service instructions are required. These are used to elaborate and analyze the program, among other things.
Program Execution
When the PLC is set in RUN mode, the PLC takes a snapshot and the analog and digital inputs values are saved in a memory table, the CPU executes the program contained in the user memory from the address 000 to the last one, the resulting values from the logic instructions and operations go to the output memories and written in the output modules, then the PLC restarts the process and check for faults; this is called the scan cycle format. Most of PLCs follow the positive logic convention: True=Logic 1 = Input energized, False=Logic 0=Input not energized.
We can distinguish between the following programming structures according to the way the CPU executes or runs the program:
- Linear execution, where the cycle is run line-by-line. The instructions contained in the memory are read sequentially until the end of the program and the resulting values are written in the output memories.
- Execution with a conditional jump, where the program can alter the sequence based on a condition. If the condition is true, the program jumps to the line determined; then the program continues the normal sequence. This allows the possibility of reducing the execution time of the cycle.
- Execution with subroutines, where there is more than one sequence with the same instructions. It is easier to write the subroutine once and load or call it anytime it is required.
Programming Languages
Each manufacturer determines the unique characteristics of their equipment and the programming language that they use to provide the programmer with an easy tool and environment to solve industrial logic problems. In general, programming languages are textual, graphical, or both. Textual languages use instruction lists and structured text while graphics languages and graphic methods use networks of contacts or blocks that represent a logical or arithmetic expression.
- Ladder language or KOP.
Ladder language and contact diagrams use a network of relays or contacts, like an electrical circuit that represents a logical expression, which makes it easier to understand and work. The system is based on opening and closing the relays to give the system the ON/OFF control it requires for automation and manufacturing processes.
- Boolean or AWL
It is possible to implement complex algorithms and operations in AWL since it is a machine level language an offers more flexibility and freedom of programming. These expressions are based in Boolean or algebraic logic and instruction lists, for example:
LD: Loads an open contact or line
LD NOT: Loads a closed contact or line
AND (Y): Open series contact
OR (O): Open parallel contact
AND NOT: Close series contact
OR NOT: Close parallel contact
OUT: Output relay
MEM: Intern relay or memory
TMR: Timer
CNT: Counter
Program Elements Assignment
It is important to assign the proper names to the elements of the program in such a way that helps us to maintain order and structure and does not incur mistakes or repetitions. We can elaborate a table with the description of each element. For example, inputs should be named as IN1, IN2, IN3, etc; outputs should be named OUT1, OUT2, OUT3, etc; timers should be named: TIM1, TIM2, TIM3, etc; counters should be named CNT1, CNT2, CNT3, etc; and memories should be named MEM1, MEM2, MEM3, etc.
Considerations before starting programming:
- Programs are made from left to right and from up to down.
- The number of contacts that we can assign from the beginning of the main line until the output is unlimited.
- It is preferable to write a clear circuit with a higher number of contacts rather than a complicated program, even if it contains a lower number of contacts.
- We can not connect an output directly to the main line, as this would put a closed contact between the two.
- The number of open or closed contacts that we can use in a program is unlimited.
- The number of outputs is fixed, but the contacts associated with those outputs are unlimited.
- Although memories are not external outputs, they work in a similar way and are used as auxiliary relays.
Most PLCs are protected against power outage, so they do not lose their state; there are also other PLCs with more special functions like the change of time bases for timers.
For more information or to purchase a PLC unit, go to www.dosupply.com.
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.