Understanding PLC Programming: A Beginner’s Guide

1. Definition and Classification of PLC

PLC is a new generation of general industrial control devices based on microprocessor technology, integrating computer technology, automatic control technology, and communication technology. It uses “natural language” programming aimed at control processes, making it suitable for industrial environments, easy to understand, user-friendly, and highly reliable. PLC is developed based on relay sequential control with a microprocessor at its core.

Understanding PLC Programming: A Beginner's Guide

1. Definition of PLC

A programmable logic controller (PLC) is a digital operation electronic system designed specifically for industrial applications. It uses programmable memory to internally store instructions for executing logical operations, sequential control, timing, counting, and arithmetic operations, and controls various types of machinery or production processes through digital and analog input and output. The PLC and its related peripheral devices should be designed to easily integrate into an industrial control system and be easily expandable.

Understanding PLC Programming: A Beginner's Guide

2. Classification of PLC

There are various types of PLC products, differing in specifications and performance. PLCs are generally classified based on their structural forms, functional differences, and the number of I/O points.

2.1. Classification by Structural Form

According to the structural form of PLC, they can be divided into integrated and modular types.

(1) Integrated PLC

Integrated PLCs have all components such as power supply, CPU, and I/O interfaces concentrated in one chassis, as shown in the figure. They are characterized by compact structure, small size, and low cost. Small PLCs generally adopt this integrated structure. An integrated PLC consists of a basic unit (also known as the host) with varying I/O points and an expansion unit. The basic unit includes the CPU, I/O interfaces, expansion ports connected to I/O expansion units, and interfaces connected to programmers or EPROM writers. The expansion unit contains only I/O and power supply, without a CPU. Basic and expansion units are generally connected by flat cables. Integrated PLCs can also be equipped with special function units such as analog units and position control units to expand their functionalities.

Understanding PLC Programming: A Beginner's Guide

(2) Modular PLC

Modular PLCs consist of several separate modules for each component, such as CPU modules, I/O modules, and power supply modules (some included in the CPU module), as well as various functional modules. Modular PLCs are composed of a frame or baseboard and various modules, which are inserted into sockets on the frame or baseboard, as shown in the figure. The characteristics of modular PLCs include flexible configuration, allowing for the selection of different system scales as needed, and easy assembly, expansion, and maintenance. Medium to large PLCs generally adopt a modular structure.

Understanding PLC Programming: A Beginner's Guide

Some PLCs combine the features of both integrated and modular types, forming what is known as stacked PLCs. In stacked PLCs, the CPU, power supply, and I/O interfaces are also independent modules, but they are connected by cables and can be stacked layer upon layer. This not only allows for flexible system configuration but also keeps the size compact.

2.2. Classification by Function

PLC can be classified into low-end, mid-range, and high-end types based on their functionalities.

(1) Low-end PLC

Low-end PLCs have basic functions such as logical operations, timing, counting, shifting, self-diagnosis, and monitoring, and may also have a small amount of analog input/output, arithmetic operations, data transfer, comparison, and communication functions. They are mainly used for logical control, sequential control, or single machine control systems with a small amount of analog control.

(2) Mid-range PLC

Mid-range PLCs have all the functionalities of low-end PLCs, plus stronger analog input/output, arithmetic operations, data transfer and comparison, numeral conversion, remote I/O, subroutines, and networking capabilities. Some can also add interrupt control, PID control, etc., suitable for complex control systems.

(3) High-end PLC

High-end PLCs have all the functions of mid-range PLCs, plus features such as signed arithmetic operations, matrix operations, bit logic operations, square root operations, and other special function calculations, tabulation, and table transfer functions. High-end PLCs have stronger communication and networking capabilities and can be used for large-scale process control or form distributed network control systems, thus achieving factory automation.

2.3. Classification by I/O Points

PLCs can be divided into small, medium, and large types based on the number of I/O points.

(1) Small PLC

Small PLCs have fewer than 256 I/O points, with a single CPU and an 8-bit or 16-bit processor, and a user memory capacity of less than 4KB. For example: Mitsubishi FX0S series.

(2) Medium PLC

Medium PLCs have I/O points ranging from 256 to 2048, with dual CPUs and a user memory capacity of 2 to 8KB.

(3) Large PLC

Large PLCs have more than 2048 I/O points, with multiple CPUs and a 16-bit or 32-bit processor, and a user memory capacity of 8 to 16KB.

In the world, PLC products can be divided into three major schools by region: American products, European products, and Japanese products. The PLC technologies in the United States and Europe were developed independently in isolation, resulting in significant differences between American and European PLC products. Japanese PLC technology was introduced from the United States and has certain inheritances from American PLC products, but Japan mainly focuses on small PLCs. The United States and Europe are known for medium and large PLCs, while Japan is renowned for small PLCs.

Common PLCs are shown in the table.

Understanding PLC Programming: A Beginner's Guide

Understanding PLC Programming: A Beginner's Guide

Understanding PLC Programming: A Beginner's Guide

2. Functions and Application Areas of PLC

PLC is designed and developed by integrating the advantages of relay contactor control with the flexibility and convenience of computers, which gives PLC many characteristics that other controllers cannot compare with.

1. Functions of PLC

PLC is a general industrial automatic control device developed based on microprocessor technology, integrating computer technology, automatic control technology, and communication technology. It has a series of advantages such as high reliability, small size, strong functionality, simple and flexible program design, and easy maintenance, making it widely used in metallurgy, energy, chemical, transportation, and electric power industries, and becoming one of the three pillars of modern industrial control (PLC, robotics, and CAD/CAM). Based on the characteristics of PLCs, their functional forms can be summarized as follows.

(1) Switch Logic Control

PLC has powerful logical operation capabilities, enabling various simple and complex logic controls. This is the most basic and widespread application area of PLC, replacing traditional relay contactor control.

(2) Analog Control

PLC is equipped with A/D and D/A conversion modules. The A/D module converts analog quantities such as temperature, pressure, flow, and speed from the field into digital quantities, which are processed by the microprocessor in the PLC (the microprocessor can only process digital quantities), and then control; or converted back into analog quantities through the D/A module to control the object being controlled, thus enabling PLC to control analog quantities.

(3) Process Control

Modern medium and large PLCs are generally equipped with PID control modules for closed-loop process control. When a variable in the control process deviates, the PLC can calculate the correct output according to the PID algorithm, thereby controlling and adjusting the production process to keep the variable at the set value. Currently, many small PLCs also have PID control functions.

(4) Timing and Counting Control

PLC has strong timing and counting functions, providing users with dozens, hundreds, or even thousands of timers and counters. The timing and counting values can be set by users when writing user programs or by operators on the industrial site through programming devices, thus achieving timing and counting control. If users need to count high-frequency signals, they can choose high-speed counting modules.

(5) Sequential Control

In industrial control, PLC can use step instruction programming or shift register programming to achieve sequential control.

(6) Data Processing

Modern PLCs can not only perform arithmetic operations, data transfer, sorting, and table lookup, but also data comparison, data conversion, data communication, data display, and printing, giving them strong data processing capabilities.

(7) Communication and Networking

Most modern PLCs adopt communication and networking technologies, with RS-232 or RS-485 interfaces for remote I/O control. Multiple PLCs can network and communicate with each other, and external devices can exchange programs and data with one or more programmable controllers’ signal processing units, such as program transfer, data document transfer, monitoring, and diagnosis. Communication interfaces or communication processors complete program and data transfers according to standard hardware interfaces or proprietary communication protocols.

2. Application Areas of PLC

Currently, PLCs are widely used in various industries such as steel, petroleum, chemical, electric power, building materials, machinery manufacturing, automotive, light textile, transportation, environmental protection, and cultural entertainment, with usage broadly summarized into the following categories.

(1) Switch Logic Control

This is the most basic and widespread application area of PLC, replacing traditional relay circuits to achieve logic control and sequential control; it can be used for controlling a single device or for multi-machine group control and automated assembly lines, such as injection molding machines, printing machines, stapling machines, combined machine tools, grinding machines, packaging production lines, and electroplating assembly lines.

(2) Analog Control

In industrial production processes, many continuously changing quantities, such as temperature, pressure, flow, liquid level, and speed, are analog quantities. To enable PLC to process analog quantities, A/D and D/A conversions must be realized. PLC manufacturers produce matching A/D and D/A conversion modules for analog control.

(3) Motion Control

PLC can be used for controlling circular or linear motions. From the perspective of control device configuration, early PLCs directly connected switch I/O modules to position sensors and actuators, but now specialized motion control modules are generally used to drive stepper or servo motors for single-axis or multi-axis position control. Almost all major PLC manufacturers’ products have motion control functions, widely used in various machinery, machine tools, robots, elevators, etc.

(4) Process Control

Process control refers to the closed-loop control of analog quantities such as temperature, pressure, and flow, with very wide applications in metallurgy, chemical, heat treatment, boiler control, etc. As an industrial control computer, PLC can program various control algorithm programs to complete closed-loop control. PID regulation is a commonly used method in closed-loop control systems, and medium and large PLCs are generally equipped with PID modules; currently, many small PLCs also have this function module. PID processing generally runs a dedicated PID subroutine.

(5) Data Processing

Modern PLCs have functions for mathematical operations (including matrix operations, function operations, logical operations), data transfer, data conversion, sorting, table lookup, and bit operations, allowing for data collection, analysis, and processing. These data can be compared with reference values stored in memory, thus completing specific control operations; they can also be transmitted to other intelligent devices using communication functions or printed and tabulated. Data processing is generally used in large control systems, such as unmanned flexible manufacturing systems; it can also be used in process control systems, such as large control systems in papermaking, metallurgy, and the food industry.

(6) Communication and Networking

PLC communication includes communication between PLCs and communication between PLCs and other intelligent devices. With the development of computer control, factory automation networks have developed rapidly, and PLC manufacturers pay great attention to PLC communication functions, continuously launching their networking systems. Newly produced PLCs have communication interfaces, making communication very convenient.

3. Basic Structure and Working Principle of PLC

As a computer for industrial control, PLC has a structure similar to that of ordinary computers; however, due to different usage scenarios and purposes, there are some structural differences.

1. Hardware Composition of PLC

The basic structural block diagram of the PLC hardware system is as shown in the figure.

In the figure, the PLC host consists of CPU, memory (EPROM, RAM), input/output units, peripheral I/O interfaces, communication interfaces, and power supply. For integrated PLCs, all these components are housed within the same casing. For modular PLCs, each component is independently packaged, called a module, and modules are connected together through a frame and cables. Each part inside the host is connected via power buses, control buses, address buses, and data buses, and certain external devices are equipped according to the actual control objects to form different PLC control systems. Common external devices include programmers, printers, EPROM writers, etc. PLC can be equipped with communication modules to communicate with host computers and other PLCs, forming a distributed control system.

Below, the various components of PLC and their functions are introduced to help users further understand PLC’s control principles and work processes.

(1) CPU

The CPU is the control center of the PLC, coordinating the work under its control in an orderly manner to achieve control over various devices on-site. The CPU consists of a microprocessor and a controller, capable of performing logical and mathematical operations, coordinating the work of various parts within the control system.

The controller’s role is to control all parts of the microprocessor to work systematically. Its basic function is to read instructions from memory and execute them.

(2) Memory

PLC is equipped with two types of memory: system memory and user memory. System memory is used to store system management programs, which users cannot access or modify. User memory is used to store programmed application programs and the status of working data. The part of user memory that stores working data status is also called the data storage area, which includes input/output data image area, timer/counter preset values and current values, and a buffer for storing intermediate results.

The memory of PLC mainly includes the following types.

(1) Read-Only Memory

(2) Programmable Read-Only Memory

(3) Erasable Programmable Read-Only Memory

(4) Electrically Erasable Programmable Read-Only Memory

(5) Random Access Memory

(3) Input/Output (I/O) Modules

① Switch Input Module

Switch input devices include various switches, buttons, sensors, etc. The input types of PLC can generally be DC, AC, and AC/DC. The power supply for the input circuit can be provided externally or, in some cases, from within the PLC.

② Switch Output Module

The output module’s function is to convert the control signals output by the CPU executing user programs into signals that can drive specific devices required on the production site, driving the actions of actuators.

(4) Programmer

The programmer is an important external device for PLC, allowing users to input user programs into the PLC’s user program memory, debug programs, and monitor the execution process. There are three main types of programmers structurally.

(1) Simple Programmer

(2) Graphical Programmer

(3) General Computer Programmer

(5) Power Supply

The power supply unit converts external power (220V AC) into internal working voltage. The externally connected power supply is converted into the working power required by the PLC’s internal circuits (DC 5V, ±12V, 24V) through a dedicated switch-mode power supply within the PLC, providing 24V DC power for external input components (only for input endpoints). The power supply for driving PLC loads is provided by the user.

(6) Peripheral Interface

The peripheral interface circuit is used to connect handheld programmers or other graphical programmers, text displays, and can form the PLC control network through the peripheral interface. PLC can connect to computers via RS-485 interfaces using PC/PPI cables or MPI cards, enabling programming, monitoring, networking, and other functions.

2. Software Composition of PLC

The software of PLC consists of system programs and user programs.

The system program is designed and written by the PLC manufacturer and stored in the PLC’s system memory, which users cannot read, write, or change directly. The system program generally includes system diagnostic programs, input processing programs, compilation programs, information transfer programs, and monitoring programs.

The user program is compiled by users using PLC programming languages according to control requirements. In PLC applications, the most important aspect is to use PLC programming languages to write user programs to achieve control objectives. Since PLCs are specially developed for industrial control, their main users are electrical technicians, and to meet their traditional habits and capabilities, PLC programming languages are relatively simple, easy to understand, and visual compared to computer languages.

1. Graphical Instruction Structure

2. Clear Variable Constants

3. Simplified Program Structure

4. Simplified Application Software Generation Process

5. Enhanced Debugging Methods

3. Basic Working Principle of PLC

The working mode of PLC scanning is mainly divided into three stages: input sampling stage, user program execution stage, and output refresh stage, as shown in the figure.

Understanding PLC Programming: A Beginner's Guide

1. Input Sampling Stage

In the input sampling stage, the PLC reads all input statuses and data in a scanning manner and stores them in the corresponding units in the I/O image area. After the input sampling is complete, it transitions to the user program execution and output refresh stages. In these two stages, even if the input status and data change, the states and data in the corresponding units of the I/O image area will not change. Therefore, if the input is a pulse signal, the width of that pulse must be greater than one scanning period to ensure that the input can be read under any circumstances.

2. User Program Execution Stage

In the user program execution stage, the PLC always scans the user program (ladder diagram) in a top-down order. When scanning each ladder diagram, it first scans the control circuit composed of various contacts on the left side of the ladder diagram, performing logical operations on the control circuit contacts in a left-to-right and top-to-bottom order; then, based on the results of the logical operations, it refreshes the state of the corresponding bit in the system RAM storage area for that logic coil, or refreshes the state of the corresponding bit in the I/O image area for that output coil, or determines whether to execute the special function instructions specified by that ladder diagram. During the user program execution process, only the input points’ states and data in the I/O image area will not change, while other output points and soft devices’ states and data in the I/O image area or system RAM storage area may change, and the results of the program execution for the upper ladder diagrams will affect the lower ladder diagrams that use these coils or data; conversely, the status or data of the refreshed logic coils in the lower ladder diagrams will only affect the upper ladder diagrams in the next scanning period.

3. Output Refresh Stage

After the user program scanning is complete, the PLC enters the output refresh stage. During this period, the CPU refreshes all output latch circuits according to the states and data in the I/O image area, and then drives the corresponding external devices through the output circuits. At this point, the PLC’s actual output occurs.

Input/Output Lag Phenomenon

From the working process of the PLC, the following conclusions can be drawn.

· The logical relationships between input and output signals executed in a scanning manner have inherent lag. The longer the scanning period, the more severe the lag.

· The scanning period includes not only the time occupied by the three main working stages of input sampling, user program execution, and output refresh but also the time occupied by system management operations. Among these, the time taken for program execution is related to the length of the program and the complexity of the instruction operations, while other factors remain relatively stable. The scanning period is generally in the nanosecond range.

· During the nth scan execution of the program, the input data used is based on the sampling value X from the previous scanning period, while the output data is based on the output value Y(n-1) from the last scan and the current output value Yn; the signal sent to the output terminals is the final result Yn after all calculations are executed this time.

· Input/output response lag is related not only to the scanning method but also to the arrangement of program design.

Image and text source from the internet; if there is any infringement, please contact for deletion!

Understanding PLC Programming: A Beginner's Guide

Leave a Comment