As a type of industrial control computer, PLCs have a similar structure to ordinary computers; however, due to different usage scenarios and purposes, there are some differences in their structure.
1. Hardware components of a PLC
The basic structure of a PLC hardware system is as follows:
A PLC's main unit consists of a CPU, memory (EPROM, RAM), input/output units, peripheral I/O interfaces, communication interfaces, and a power supply. For an integrated PLC, all these components are housed in the same casing. For a modular PLC, each component is independently packaged, called a module, and these modules are connected together via a rack and cables. All parts within the main unit are connected via power buses, control buses, address buses, and data buses. Depending on the needs of the controlled object, various external devices are added to form different PLC control systems. Commonly used external devices include programmers, printers, and EPROM writers. A PLC can be configured with a communication module to communicate with a host computer and other PLCs, forming a distributed PLC control system.
The following sections introduce the components of a PLC and their functions to help users further understand the control principles and working process of a PLC.
CPU
The CPU is the control center of the PLC. Under the control of the CPU, the PLC works in an orderly and coordinated manner to control various devices in the field. The CPU consists of a microprocessor and a controller. It 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 various components of the entire microprocessor to work in an orderly manner. Its basic function is to read instructions from memory and execute instructions.
memory
PLCs are equipped with two types of memory: system memory and user memory. System memory stores the system management program, and users cannot access or modify its contents. User memory stores the programmed application programs and operating data status. The user memory section storing operating data status is also called the data storage area, and it includes an input/output data image area, a data area for timer/counter presets and current values, and a buffer for storing intermediate results.
The main types of PLC memory include the following.
(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
Input/output (I/O) modules
① Switch input module
Digital input devices include various switches, buttons, sensors, etc. PLC input types typically include DC, AC, and AC/DC. The power supply for the input circuits can be externally supplied, or sometimes internally provided by the PLC.
② Switch output module
The function of the output module is to convert the TTL level control signals output by the CPU when executing the user program into signals required in the production site to drive specific equipment and thus drive the actuator.
Programmer
A programmer is an important external device for a PLC. It allows users to load their programs into the PLC's user program memory, debug the program, and monitor its execution. Programmers can be structurally classified into three types.
(1) Simple programmer
(2) Graphical programmer
(3) General-purpose computer programmer
power supply
The power supply unit converts external power (220V AC) into the internal operating voltage. External power supplies are converted from AC/DC to the operating voltage (DC 5V, ±12V, 24V) required by the PLC's internal circuitry via a dedicated switching voltage regulator within the PLC. It also provides 24V DC power to external input components (such as proximity switches) (for input terminals only). The power supply driving the PLC load is provided by the user.
Peripheral Interface
The peripheral interface circuit is used to connect handheld programmers or other graphical programmers and text displays, and can form a control network for the PLC through the peripheral interface. The PLC uses a PC/PPI cable or MPI card to connect to a computer through an RS-485 interface, which can realize programming, monitoring, networking and other functions.
2. PLC Software Components
The software of a 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. Users cannot directly read, write, or modify it. The system program generally includes system diagnostic programs, input processing programs, compilers, information transmission programs, and monitoring programs.
A PLC user program is a program written by the user using the PLC's programming language according to control requirements. In PLC applications, the most important aspect is writing the user program using the PLC's programming language to achieve the control objectives. Since PLCs are devices specifically developed for industrial control, their primary users are electrical technicians. To accommodate their traditional habits and proficiency, the main programming language for PLCs is a specialized language that is relatively simpler, easier to understand, and more intuitive than computer languages.
1. Graphical instruction structure
2. Explicit variable constants
3. Simplified program structure
4. Simplify the application software generation process
5. Strengthen debugging methods
Basic working principle of PLC
The PLC scanning process mainly consists of three stages: the input sampling stage, the user program execution stage, and the output refresh stage.
1. Input sampling stage
During the input sampling phase, the PLC sequentially reads all input states and data in a scanning manner and stores them in the corresponding units of the I/O image area. After input sampling is completed, the process transitions to the user program execution and output refresh phases. During these two phases, even if the input states 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 the pulse signal must be greater than one scan cycle to ensure that the input can be read under any circumstances.
2. User program execution phase
During the user program execution phase, the PLC always scans the user program (ladder diagram) sequentially from top to bottom. When scanning each ladder diagram, it first scans the control circuit formed by the contacts on the left side of the ladder diagram, performing logical operations on the control circuit in a left-to-right, top-to-bottom order. Then, based on the result of the logical operation, 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 instruction specified by that ladder diagram. That is, during user program execution, only the state and data of input points in the I/O image area remain unchanged, while the state and data of other output points and soft devices in the I/O image area or system RAM storage area may change. Furthermore, the program execution result of the ladder diagram above will affect any ladder diagram below that uses those coils or data; conversely, the refreshed state or data of the logic coils in a lower ladder diagram will only affect the ladder diagram above it in the next scan cycle.
3. Output refresh phase
After the user program scan is complete, the PLC enters the output refresh phase. During this period, the CPU refreshes all output latch circuits according to the corresponding states and data in the I/O image area, and then drives the corresponding peripherals through the output circuits. This is when the PLC actually outputs data.
Input/output lag
From the working process of a PLC, we can summarize the following conclusions:
When a program is executed in a scanning manner, there is a lag in the logical relationship between its input/output signals.
The longer the scan cycle, the more severe the lag. The scan cycle includes the time spent in the three main working stages: input sampling, user program execution, and output refresh, as well as the time spent on system management operations. The program execution time is related to the program length and the complexity of the instructions, while other aspects remain relatively constant. Scan cycles are typically in the nanosecond range.
• When executing the program for the nth scan, the input data is the scan value X from the sampling phase of this scan cycle. The output data includes the output value Y(n-1) from the previous scan and the output value Yn from the current scan. The signal sent to the output terminal is the final result Yn after all the operations are performed.
Input/output response lag is not only related to the scanning method, but also to the program design.