search
Location: Home>PLC Tech.

Learn PLC programming from scratch

post time:2024-04-10 15:03:29 author:Free Little Bird clicks:1710 【 Size:big middle small

After years of work and research, I found that PLC programming is not very easy for beginners, but it is not easy to go. On the Internet, we know that there is no shortage of textual descriptions, but when we read the whole article, we find that we still don't understand. I hope that this study material with pictures and texts compiled in daily work can give friends a clearer understanding. Of course, we know that PLC learning cannot be an overnight thing, we need to persevere and persist for a long time, the following graphic materials are for friends' reference. 

1. Definition and classification of PLC 

PLC is based on microprocessor, integrating computer technology, automatic control technology and communication technology, using the "natural language" programming for the control process and user, adapting to the industrial environment, simple to understand, easy to operate, high reliability of a new generation of general industrial control device. PLC is a general automatic control device with microprocessor as the core developed on the basis of relay sequence control. 

9999999999_副本.jpg

1. Definition of PLC 

A programmable controller is a digital operational electronic system designed for applications in industrial environments. It uses programmable memory to store and execute operation instructions such as logical operations, sequence control, timing, counting and arithmetic operations, and controls various types of machinery or production processes through digital and analog inputs and outputs. Programmable controllers and related peripheral equipment should be designed according to the principle of easy to form a whole with the industrial control system and easy to expand its functions. 

2. Classification of PLC 

There is a wide range of PLC products with different specifications and performance. PLCs are usually roughly classified according to their different structural forms, differences in functions, and the number of 1/0 points. 

2.1. Classification according to structural form 

According to the structure of PLC, PLC can be divided into two categories: integral and modular. 

(1) Integral PLC 

The integral PLC is to centralize the power supply, CPU, 1/0 interface and other components in a single chassis, as shown in the figure. It has the characteristics of compact structure, small size and low price. Small PLCs generally adopt this monolithic structure. The integral PLC is composed of a basic unit (also known as a host) and an expansion unit with different 1/0 points, including CPU, 1/0 interface, expansion port connected to 1/0 expansion unit, and interface connected to programmer or EPROM writer. The expansion unit only has 1/0 and power supplies, but no CPU. The base unit and the extension unit are generally connected by a flat cable. Integral PLCs can generally be equipped with special function units, such as analog units, position control units, etc., to expand their functions.

 (2) Modular PLC Modular 

PLC makes each component of PLC into several separate modules, such as CPU module, 1/0 module, power supply module (some are included in CPU module) and various functional modules. The modular PLC consists of a frame or substrate and various modules, which are mounted on the sockets of the frame or substrate, as shown in the figure. This modular PLC is characterized by flexible configuration, the option of different scales of systems as needed, and easy assembly for easy expansion and maintenance. Large and medium-sized PLCs generally adopt modular structure. 

plc03.jpg

There are also PLCs that combine monolithic and modular characteristics to form the so-called stacked PLC. The CPU, power supply, 1/0 interface, etc. of stacked PLCs are also independent modules, but they are connected by cables, and each module can be stacked layer by layer. In this way, the system can be configured flexibly and compactly. 

2.2. Classification by function 

According to the different functions of PLC, PLC can be divided into three categories: low-end, mid-range and high-end. 

(1) Low-grade PLC 

Low-end PLC has basic functions such as logic operation, timing, counting, shifting, self- diagnosis, monitoring, etc., and can also have a small number of analog input/output, arithmetic operation, data transmission and comparison and communication functions, mainly used for logic control, sequence control or small number of analog control stand- alone control systems. 

(2) Mid-range PLC 

In addition to the functions of low-end PLC, the mid-range PLC also has strong analog input/output, arithmetic operations, data transmission and comparison, data system conversion, remote 1/0, subprograms and communication networking functions. Some can also add interrupt control, PID control and other functions, suitable for complex control systems. 

(3) High-grade PLC 

In addition to the functions of mid-range PLC, high-end PLC also adds symbolic arithmetic, matrix operations, bit logic operations, square root operations and other special function functions, tabulation and table transmission functions. High-end PLCs have stronger communication and networking capabilities, which can be used for large-scale process control or to form a distributed network control system to achieve factory automation. 

2.3. Classification by 1/0 points 

According to the number of 1/0 points of PLC, PLC can be divided into three categories: small, medium and large. 

(1) Small PLC The small PLC has less than 256 1/0 points, a single CPU and an 8-bit or 16-bit processor, and a user memory capacity of less than 4KB. For example: Mitsubishi FXOS series. 

(2) Medium-sized PLC 

The 1/0 points of the medium-sized PLC are 25+2048, with dual CPUs and user memory 

(3) Large PLC

Large PLCs have more than 2048 1/0 points, multiple CPUs, 16-bit or 32-bit processors,

and user memory capacity of 8-16KB.

In the world, PLC products can be divided into three major genres according to geography, one is American products, one is European products, and one is Japanese products. PLC technology in the United States and Europe is independently researched and developed in isolation from each other, so there are obvious differences between PLC products in the United States and Europe. Japan's PLC technology was introduced by the United States, and there is a certain inheritance of American PLC products, but Japan's main products are positioned in small PLCs. The United States and Europe are known for large and medium-sized PLCs, while Japan is known for small PLCs. 

Common PLCs are shown in the table. 

2. In the entry-level learning of PLC programming, it is necessary for me to know a little about its functions and application fields 

PLC is designed, manufactured and developed based on the advantages of relay contactor control and the advantages of computer flexibility and convenience, which makes PLC have many characteristics that other controllers cannot match. 

1. PLC function 

PLC is a general industrial automatic control device developed by microprocessor as the core, integrating computer technology, automatic control technology and communication technology, with a series of advantages such as high reliability, small size, strong function, simple program design, flexible and universal and convenient maintenance, so it has a wide range of applications in metallurgy, energy, chemical industry, transportation, electric power and other fields, and has become one of the three pillars of modern industrial control (PLC, robot and CAD/CAM). According to the characteristics of PLC, its functional forms can be summarized into the following types. 

(1) Switching volume logic control 

PLCs have powerful logic computing capabilities and can achieve various simple and complex logic controls. This is the most basic and widest application area of PLC, which replaces the control of traditional relay contactors. 

(2) Analog control 

The PLC is equipped with A/D and D/A conversion modules. The A/D module can convert the analog quantities such as temperature, pressure, flow, and speed on site into digital quantities, and then process them through the microprocessor in the PLC (the microprocessor can only process digital quantities), and then control them. Or it can be converted into an analog quantity by the D/A module, and then the controlled object can be controlled, so that the PLC can control the analog quantity. 

(3) Process control 

Modern large and medium-sized PLCs are generally equipped with PID control modules, which can carry out closed-loop process control. When a variable deviates in the control process, the PLC can calculate the correct output according to the PID algorithm, and then control and adjust the production process to keep the variable at the set value. At present, many small PLCs also have PID control function. 

(4) Timing and counting control 

PLC has strong timing and counting functions, and it can provide users with tens or even hundreds or thousands of timers and counters. The timing time and counting value 

can be set arbitrarily by the user when writing the user program, or by the operator through the programmer at the industrial site, so as to realize the control of timing and counting. If users need to count signals with higher frequencies, they can choose a high-speed counting module.

 (5) Sequence control 

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

(6) Data processing 

Modern PLCs can not only perform arithmetic operations, data transmission, sorting and table lookup, but also perform data comparison, data conversion, data communication, data display and printing, etc., which has strong data processing capabilities. 

(7) Communication and networking 

Most modern PLCs use communication and network technology, and have RS-232 or RS-485 interfaces for remote 1/0 control. Multiple PLCs can be networked and communicated with each other, and programs and data can be exchanged between external devices and the signal processing units of one or more programmable controllers, such as program transfer, data document transfer, monitoring, and diagnostics. The communication interface or communication processor completes the transfer of programs and data according to standard hardware interfaces or proprietary communication protocols. 

2. Application fields of PLC 

At present, PLC has been widely used in various industries such as steel, petroleum, chemical, electric power, building materials, machinery manufacturing, automobile, light textile, transportation, environmental protection and cultural entertainment at home and abroad, and the use can be roughly summarized into the following categories. 

(1) Logical control of switching quantity 

This is the most basic and widest application field of PLC, which replaces the traditional relay circuit and realizes logic control and sequence control; It can be used for the control of a single equipment, as well as for multi-machine group control and automated assembly lines, such as injection molding machines, printing machines, stapling machinery, combined machine tools, grinding machines, packaging production lines and electroplating lines. 

(2) Analog control 

In the industrial production process, there are many continuously changing quantities such as temperature, pressure, flow, liquid level and velocity that are analog quantities. In 

order for the PLC to process analog quantities, it is necessary to realize A/D conversion and D/A conversion between analog and digital quantities. PLC manufacturers produce matching A/D and D/A conversion modules, so that PLC can be used for analog control. 

(3) Motion control 

PLC can be used for the control of circular motion or linear motion. In terms of control mechanism configuration, in the early days, it was directly used to connect position sensors and actuators with switching volume 1/0 modules, but now special motion control modules are generally used, which can drive single-axis or multi-axis position control modules of stepper motors or servo motors. Almost all the products of the world's major PLC manufacturers have motion control functions, which are widely used in various machinery, machine tools, robots, elevators and other occasions. 

(4) Process control 

Process control refers to the closed-loop control of analog quantities such as temperature, pressure, and flow, and has a wide range of applications in metallurgy, chemical industry, heat treatment, boiler control, etc. As an industrial control computer, PLC can program various control algorithms to complete closed-loop control. PID adjustment is a more commonly used adjustment method in general closed-loop control systems, large and medium-sized PLCs have PID modules, and many small PLCs also have this function module. PID processing is generally the operation of a dedicated PID subroutine. 

(5) Data processing 

Modern PLC has functions such as mathematical operations (including matrix operations, function operations, logic operations), data transmission, data conversion, sorting, table search and bit operation, and can complete data collection, analysis and processing. These data can be compared with the reference values stored in the memory to complete certain control operations; It can also be transmitted to other smart devices using communication functions or printed tabulation. Data processing is generally used in large- scale control systems, such as unmanned flexible manufacturing systems; It can also be used in process control systems, such as some large control systems in papermaking, metallurgy, and food industries. 

(6) Communication and networking 

PLC communication includes communication between PLCs and communication between PLCs and other intelligent devices. With the development of computer control, the factory automation network has developed rapidly, and PLC manufacturers have attached great importance to the communication function of PLC and have launched their own network systems. Newly produced PLCs all have communication interfaces, which are very convenient to communicate. They have launched their own network systems. Newly 

produced PLCs all have communication interfaces, which are very convenient to communicate. 

3. The basic structure and working principle of PLC 

As an industrial control computer, PLC has a similar structure to ordinary computers. However, due to different usage occasions and purposes, there are some differences in structure. 

1. Hardware composition of PLC 

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

In the figure, the host of the PLC consists of a CPU, memory (EPROM, RAM), input/output unit, peripheral 1/0 interface, communication interface and power supply. For monolithic PLCs, these components are all in the same enclosure. In the case of modular PLCs, each component is individually packaged, called a module, and each module is connected together by a rack and cables. Each part of the host is connected by power bus, control bus, address bus and data bus, and is equipped with certain external devices according to the needs of the actual control object to form different PLC control systems. Commonly used external devices include programmers, printers, EPROM writers, etc. PLC can be configured with communication modules to communicate with host computers and other PLCs to form a distributed control system of PLC. 

The following introduces the components and functions of PLC, so that users can further understand the control principle and working process of PLC. 

(1) CPU 

The CPU is the control center of the PLC, which coordinates its work in an orderly manner under the control of the CPU, so as to realize the control of various devices on site. The CPU is composed of a microprocessor and a controller, which can perform logical and mathematical operations and coordinate the work of various parts within the control system. 

The role of the controller is to control the orderly work of the various parts of the entire microprocessor, and its basic function is to read and execute instructions from memory. 

(2) Memory 

PLCs are equipped with two types of memory, namely system memory and user memory. System memory is used to store system managers, and users cannot access or modify the contents of this part of the memory. User memory is used to store the state of the compiled application and work data. The portion of user memory that houses the state of working data, also known as the data store, includes the input/output data image area, the data area of timer/counter presets and current values, and the buffer that stores 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 (1/0) module

(1) Switching input module

The input equipment is various switches, buttons, sensors, etc., and the input types of PLC can usually be DC, AC and AC DC. The power supply of the input circuit can be supplied externally or internally by the PLC.

(2) Switching output module

The function of the output module is to convert the control signal of the TTL level output by the CPU execution user program into the signal required by the production site to drive the signal of a specific device to drive the action of the actuator.

(4) Programmer

The programmer is an important external device of the PLC, which can be used to feed the user program into the user program memory of the PLC, debug the program, and monitor the execution process of the program. Programmers can be divided into the following three types in terms of structure.

(1) Simple programmer

(2) Graphical programmer

(3) General computer programmer

(5) Power supply

The power supply unit converts the external power supply (220V AC power supply) into an internal operating voltage. The externally connected power supply converts the AC/DC power supply into the working power supply (DC 5V, ± 12V, 24V) required by the PLC's internal circuit through a dedicated switching regulated power supply equipped inside the PLC, and provides a 24V DC power supply (for input endpoint only) for external input components (such as proximity switches). The power supply to drive the PLC load is provided by the user.

(6) Peripheral interface

The peripheral interface circuit is used to connect the handheld programmer or other graphic programmer, text display, and can form a PLC control network through the peripheral interface. PLC uses PC/PPI cable or MPl card to connect to the computer through the RS485 interface, which can realize programming, monitoring, networking and other functions.

2. PLC software composition

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 system memory of the PLC, and the user cannot read, write and change it directly. System programs generally include system diagnostic programs, input processing programs, compilation programs, information transmission programs, and monitoring programs.

The user program of PLC is a program prepared by the user according to the control requirements using the programming language of the PLC. In PLC applications, the most important thing is to use PLC programming language to write user programs to achieve control purposes. Since PLC is a device specially developed for industrial control, its main users are the majority of electrical technicians, in order to meet their traditional habits and mastery ability, the main programming language of PLC adopts a special language that is relatively simpler, easier to understand, and more vivid than computer language.

1. Graph instruction structure

2. Clear variable constants

3. Simplified program structure

4. Simplify the application software generation process

5. Strengthen debugging methods 

 链接plc.jpg

3. The basic working principle of PLC 

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

1. Enter the sampling stage 

During the input sampling phase, the PLC reads all input states and data in a scanned manner and stores them in the corresponding units in the 1/0 mirroring area. After the input sampling is completed, it is transferred to the user program execution and output refresh stages. In both phases, the state and data of the corresponding cells in the 1/0 mirroring area do not change even if the input state and data change. Therefore, if the input is a pulse signal, the width of the pulse signal must be greater than one sweep period to ensure that the input is read in any case. 

2. User program execution stage 

During the user program execution phase, the PLC always scans the user program (ladder chart) sequentially in top-down order. When scanning each ladder diagram, the control line composed of each contact on the left side of the ladder diagram is always scanned first, and the control line composed of contacts is logically calculated in the order of left and right, first up and then down; Then, according to the results of the logic operation, the state of the corresponding bit of the logic coil in the system RAM storage is refreshed, or the state of the corresponding bit of the output coil in the 1/0 mirroring area, or whether to execute the special function instruction specified in the ladder diagram. That is, during the execution of the user program, only the state and data of the input points in the 1/0 mirroring area will not change, while the status and data of other output points and software devices in the 1/0 mirroring area or system RAM storage area may change, and the ladder chart on the top, the program execution result will work on the ladder diagram that uses these coils or data in the bottom row. In contrast, the ladder chart below has the status or data of the logic coil being refreshed only until the next scan cycle to work on the ladder chart above it. 

3. Output refresh stage 

When the user program is scanned, the PLC enters the output refresh stage. During this period, the CPU refreshes all output latching circuits according to the corresponding state and data in the 1/0 projection area, and then drives the corresponding peripherals through the output circuit. At this time, it is the real output of the PLC. 

Input/output lag 

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

The program is executed in a scanning way, and there is a theoretical lag in the logical relationship between the input/output signals. The longer the scan cycle, the worse the lag. 

The scanning cycle includes the time occupied by the three main work stages: input sampling stage, user program execution stage, and output refresh stage, as well as the time occupied by system management operations. Among them, the time of program execution is related to the length of the program and the complexity of the instruction operation, and the rest is basically unchanged. The scan cycle is generally in the millisecond range. 

When executing the program for the nth scan, the input data based on the scan value X in the sampling stage in the scan cycle is the output value of the previous scan Y(n-l), and the output value of this time is Yn; The signal sent to the output terminal is the final result Yn after performing all the operations this time. 

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

Through the above PLC programming introductory knowledge, we may find that this knowledge may not be as difficult as we think, but the premise may require us to have some foundation, if the foundation is weak or there is no foundation friends do not need to be discouraged, as long as it is easy to find a learning method, let's communicate more. 

More
Reward
Related

Gear reducer analysis introduction

Gear reducer analysis introduction
Gear reducer is a common mechanical transmission device widely used in various industrial fields. It realizes the reduction of motor output speed and the increase of torque through the meshing transmission of gears, so as to meet the different needs of mechanical equipment for speed and torque. This...

Mechanical and electrical equipment maintenance-observing smelling Questions touching

Mechanical and electrical equipment maintenance-observing smelling Questions touching
Mechanical and electrical maintenance of equipment(looking listening Questionstouching) - that is, it is equivalent to seeing a doctor for equipment, people will get sick if they eat grains for a long time, and the same is true for equipment, and the equipment will also get sick and paralyzed...

(2) 1 - Xiao Zhang was blocked

(2) 1 - Xiao Zhang was blocked
In the summer of more than two thousand years, Xiao Zhang graduated from university, with full of enthusiasm and infinite longing for the mechanical and electrical industry, and resolutely joined a well-known mechanical and electrical equipment manufacturing company. He has been obsessed with variou...

What is the data structure in PLC programming?

What is the data structure in PLC programming?
In the process of PLC programming, if there is a lot of data, we have to use some complex data types to improve our efficiency, so what are the complex data types? How do we use them? ......First of all, let's know what they mean. Arrays are composed of the same type of data, which can be...

What is the meaning of the CPU mode selector switch in PLC?

What is the meaning of the CPU mode selector switch in PLC?
What are the mode selection switches on the CPU panel in PLC? Here is an example of a panel that shows the full functionality of the CPU318-2:Mode selector switchAs shown in the figure above, the following is an explanation of each one:1. RUN-P position: it belongs to the running programming positio...

PLC programming instructions are self-locking

PLC programming instructions are self-locking
Where to start learning the many PLC programming instructions? Welcome to continue reading this section: PLC programming instructions for self-locking.When you start to get involved in PLC, you will find that there are so many PLC programming instructions, and you will be a little dizzy...

New energy vehicle reducer

New energy vehicle reducer
With the increasing awareness of environmental protection and the rapid development of science and technology, new energy vehicles have gradually become the new favorite of the automobile market. As a key component in the power system of new energy vehicles, reducers play an important role in improv...

(2) At the critical moment, Xiao Zhang was taken away

(2) At the critical moment, Xiao Zhang was taken away
In the face of this hard-won job opportunity, Xiao Zhang is full of enthusiasm and expectation, and goes all out to devote himself to his work every day. His master is a person with rich experience and a high level in the industry, which makes Xiao Zhang full of respect and admiration. However, as t...

Application and development of PLC technology in smart home

Application and development of PLC technology in smart home
随着科技的不断进步,智能家居已经成为了现代家庭生活的重要组成部分。智能家居系统能够实现对家居设备的智能化控制,提升居住的舒适度和便利性。在智能家居的实现过程中,PLC技术(电力线载波通信技术)发挥了重要作用。本文将探讨PLC技术在智能家居中的应用及其发展前景。一、PLC技术概述PLC技术是一种利用电力线作为传输...

PLC programming introductory illustration

PLC programming introductory illustration
PLC is based on microprocessor, integrating computer technology, automatic control technology and communication technology, using user-oriented "natural language" programming for the control process, adapting to the industrial environment, simple to understand, convenient to operate,...
返回顶部