In view of the complex and expensive design and manufacture process of the existing PLC, which is not suitable for small batch production and manufacturing, a low-cost and simple PLC is designed to design the hardware structure and debug the system software.
Through practice, it can be used to control mechanical equipment with certain work engineering, to replace contactor and relay control system to improve control reliability.The system composed of the programmable controller can handle 1024 B, 8192 spot signals, and the application prospect is very flexible and extensive.Programmable Logic Controller (PLC) is widely used in industrial field control.At present, most of the PLC on the market is produced by large enterprises with strong technical strength, such as Japan’s [1], Germany, and so on.These manufacturers have rich experience in the production of electronic products and perfect technological chain. They can complete the design, manufacture, sale and training of the hardware, software, host computer development software and supporting equipment of PLC. Even the processor chips inside the PLC are manufactured by the departments responsible for the production of integrated circuits in these manufacturers.These mainstream programmable controllers have perfect functions and high reliability, and the process of design and manufacture is very complex. From the design of hardware circuit to the development of upper computer software is a complex system engineering.
It is necessary for large enterprises to have such conditions. It is difficult for small and medium-sized enterprises to enter the field of PLC design and manufacture.In the current PLC application place, not all places need PLC with complex and perfect functions.At present, the current PLC has not only basic instructions, but also complex functional instructions, fieldbus functions and on-line communication, with a variety of functional modules expansion functions, including some related industrial control equipment, such as touch screen and other connection functions.
This makes the price of PLC very expensive.In many applications, most of these functions are useless, such as controlling the mechanical equipment that is working independently, the working process is not too complex, and simple process control equipment. These devices will use the current perfect function of PLC to make the manufacturing cost rise. The contactor and relay control will result in the decline of the reliability of the products. Complex process will increase development cost and prolong product development cycle.Therefore, it is of certain market value to design a low-cost PLC with only basic logic instructions and simple on-line expansion functions.This low-cost and simple PLC can be used for the control of mechanical equipment with certain work engineering. It can replace the contactor and relay control system to improve the control reliability, and is more convenient than the direct use of single-chip computer control.This kind of PLC design and manufacture process is relatively simple, and can be developed and produced in small and medium-sized enterprises.
This new type of programmable controller adopts modular design.Structurally, the programmable controller has three modules: core module, interface module and field signal module.There are two kinds of field signal module: analog signal module and switching signal module.The three modules are connected by bus to realize structure expansion. From the function point of view, the programmable controller has three functional modules: host, slave and switching signal expander, among which slave has analog signal and switching signal.The three functional modules are connected by cable, and are selected according to the actual use and the number of field signals.The core module is the operation core and communication core of the programmable controller, which plays the role of user program operation and module signal communication.The communication ports on the core module are divided into upper communication ports and lower communication ports.
The upper communication port has three communication modes: double RS 422 communication, double RS 232 communication [2] and RS 485 communication.Through the upper communication interface, it can work on-line with other core modules.Because of the limitation of bus driving ability and signal mirror register capacity, the design can realize online operation of up to 8 hosts.The upper communication port can also be used to connect with the upper computer for downloading and communicating programs.The lower communication port is the SPI bus communication port at TTL level, which is used to connect the interface module.A core module can connect up to 8 interface modules. By using SPI ring data communication, a host can connect 8 extension computers.Because the transmission distance and reliability of TTL level are limited, the main engine and extension, extension and extension must be installed close to each other.The core module of this type of PLC uses STC12C5A32S2 MCU as the controller. This type of MCU is a common 51-Core [3].
It is easy to develop and fast to operate. Every clock cycle is the machine cycle.The single chip computer has large storage space, 32 KB FLASH program memory and 32 KB E2PROM memory, which can be used to store a large number of system programs and user programs respectively.The MCU has two serial communication ports, which can be used to communicate with the host computer and expand the port.The hardware circuit of the core module is shown in Figure 1.Two sets of input terminals are designed. The first group has eight input terminals and the second group has four input terminals. Each input terminal has a common anode.The input terminal converts the switching signal between the terminal and the common terminal into the level signal of the pin of the single chip computer through the photoelectric isolator and the external voltage dividing filter element.There are also two groups of output terminals, eight output terminals and two output terminals, respectively, using relay output, each relay is driven by integrated triode through the pin of single chip computer.The two serial communication ports of SCM are converted into RS 232 signal and RS 485 signal respectively. RS 232 port is used to communicate with host computer or programmer and input user program. RS 485 port is used to connect with other PLC modules and expand the port.
The MCU also connects a three-digit switch to set the physical address of the machine and an I2C bus E2PROM memory to be used in the data memory of the PLC [4].The interface module is used for field signal conversion and transmission, as well as some man-machine interface functions.The interface module has two-way SPI communication interface [5] and field module interface.The bidirectional SPI communication interface can be connected with the core module or other interface module to transmit data to the host computer, and the field module interface can be connected with the analog signal module or the switching signal module.One interface module can be connected with up to four switching signal modules or one analog signal module. The interface module can read data from the field signal module and transmit it to the core module.If there are multiple interface modules connected, there is also an auxiliary communication link between the interface modules, which is a master-slave UART communication mode. It is used for self-detection, data verification and standby data communication between the interface modules.
In addition, the interface module has LED dot matrix for field signal indication.There are two kinds of field signal modules: analog signal module and switching signal module, which are used for field signal conversion.Field signal module is composed of acquisition circuit, photoelectric isolation circuit, amplifier, signal register, etc. It can convert field switching or analog signals into data and read by interface module.Among them, the analog module can only be connected with the interface module alone, while the switching signal module can be expanded, and the switching signal module connected with the interface module can also be connected with up to three switching signal modules.The design of field signal module is quite flexible. Under the premise of signal standard, different field signal modules can design different number of I/O ports or analog channels.The switching signal module designed in this project has 32 I/O points, including 16 input points and 16 output points. The analog module has three analog input channels and three analog output channels.As mentioned above, the expansion mode of the new programmable controller is that a host can be connected with seven extension machines, an extension can be analog extension and a switch extension, and a switch extension can be connected with three other extension machines.Host and host can also be connected, up to 8 hosts can be connected together to form a system.The main computer in the system is the core of operation. Each host has the ability of signal processing, while the extension and extension only have the function of signal conversion and transmission.Therefore, the system composed of the programmable controller has the field signal processing ability of 1 024 B and 8 192 points at most.The extended connection is shown in Figure 2.The content of software design is to design the bottom system program of MCU. The bottom system program can receive the user program sent by the programmer and identify the user program. According to the content of the user program, the state of the input/output port of the PLC is controlled and the corresponding control action is made.User program is written by PLC users according to their own control process. The simplified PLC user program is relatively simple. Only END end, LD start contact, LDI start normal closed contact, OR parallel, ORI parallel normal closed contact, AND series, ANI series normal closed contact, ORB multi-contact parallel, ANB multi-contact series, PUSH stack, POP out stack, SET position, RST reset, OUT output, OUT output, etc. Sixteen basic instructions such as CJ jump and six programming elements such as input relay X, output relay Y, auxiliary relay M, timer T, counter C and data register D are defined as shown in Table 1.These 16 basic instructions are mainly for logic control instructions of switching quantities, which can replace contactor relay system and meet the requirements of most applications.There are four kinds of user program data: instruction, programming element, programming element number and constant [6].As shown in Table 2, each kind of data exists in the form of 1B. The high two bits of bytes are data recognition bits, thermostatic element which represent instructions, programming elements, programming element numbers and constants with 11,10,01,00 respectively. The low six bits of instructions and programming elements represent their serial numbers respectively.
For example, the program code corresponding to the statement LD X0 is 11,000001,10,000,01,000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000, so the maximum number of 64 instructions or programming elements can be supported. The lower 6 bits of numbers and constants are divided into middle 3 bits and low 3 bits. Each 3-bit binary number can represent 1-bit octal number, and every 1 B programming element number or constant can represent 2-bit octal number.The form of user program in single chip memory is instruction, programming element, programming element number and constant.Some of the instructions have no programming elements, such as the stack instruction PUSH, etc. Most of the program statements have no constants, only when the number of programming elements is timer T, counter C, or jump instruction CJ.If there is a programming element, the programming element should be followed by a byte of programming element number. The programming element is addressed by two octal digits in the element number.The constant of 2 B, i.e.
4-bit octal number, should follow the timer T, counter C or jump instruction CJ. The numerical range is 4 096. The maximum operating range of fixed timer and counter is 4 095, and the user program can not exceed 4 096.Figures 3 and 3 show a code comparison of a user program.Among the six programming elements of this type of PLC, the values of input relay X and output relay Y correspond to the state of the port; auxiliary relay M and data register D can save the data in the process of operation, the physical storage area of M is RAM address area of single chip computer, the physical storage area of data register D is E2PROM, and data register D can save data after power failure.The physical storage area of timer T and counter C is RAM and timer/counter of single chip computer. Each T or C takes up 2 RAM bytes to store 2 constants (4-bit octal number). The maximum timing range of timer/counter T is 4 095 time units, and the maximum count value of C is 4 095.A timer/counter in the single chip computer is used as the time base timer of T. The time unit is 10 ms, and the time range of the timer/counter T is 10 ms-40.95 s.Programming elements are usually addressed by two-digit octal numbers, that is, the number of programming elements of 1B. As shown in Figure 4, low-digit octal numbers are bit addresses, while high-digit octal numbers are group addresses. Within a PLC, one programming element can not exceed eight groups, each group has eight, and supports 64 at most.Considering the hardware condition and the operation ability of single chip computer, the number of programming elements of this type of PLC is 6.Due to the limited number of input and output ports of a single PLC, there are only two groups of 12 input ports and 10 output ports, which sometimes can not meet the requirements.Therefore, this type of PLC needs to have a certain expansion ability, through the RS 232 bus or RS 485 bus on the equipment, it can connect multiple PLCs. Each port of the PLC on the bus has a unique address. This address is based on the port group address and bit address of the PLC and the address of the PLC equipment. The device address is a 3-bit set by the 3-bit dial switch on the PLC. Binary number, that is, an octal number, constitutes the third bit of the port address.Every PLC on the bus has to set a unique address by dialing switch. At most, eight PLCs of the same type can be connected through the bus.The software used to analyze the user program is the core part of the PLC system program [7?8].Some also include constants, which will be distinguished and stored in the corresponding areas.Programming element addressing reads the switching amount pointed to by the address of the programming element into the accumulator C of the single chip computer and prepares for logical operation or output.The switching quantities corresponding to various programming elements are stored in different areas: input and output relays X and Y correspond to the ports of MCU, auxiliary relays M correspond to 64 bits of data in the RAM address area of MCU, data memory D corresponds to 64 bits of data in the external E2PROM, and the switching quantities of timers and relays are also stored in the RAM address area. 64 bits of data are used to represent 32 timers and 32 counts respectively.
Switching state of the device.
In this stage, instructions are first analyzed. According to different instructions, they are divided into two situations: one is variable input instructions, including LD, LDI, OR, ORI, AND, ANI, ORB, ANB, PUSH, PRD, POP11; the other is variable output instructions, including SET, RST, OUT, CJ4.For variable input instructions, first of all, addressing, reading the switching quantity corresponding to the programming element into accumulator C, waiting for calculation, and storing the result into accumulator C; for variable output instructions, the switching quantity in accumulator C is first calculated, then addressing the programming element, and sending the result to the address specified by the programming element number.In the operation execution stage, the registers associated with this stage are bit accumulator C and bit data stack area.Among them, only the instructions related to bit accumulator are AND, ANI, OR, ORI, OUT and so on. Their functions are: AND, ANI, OR, ORI and other instructions are logical operations between the switching amount in bit accumulator and the switching amount pointed by programming element, and the result is stored in bit accumulator; OUT instructions output the data in bit accumulator to the address pointed by programming element, and judge the address pointed by programming element as counter. Whether the secondary output produces a descent edge or not, in some cases, subtract 1 from the register corresponding to the counter, and if it is reduced to zero, set the switch value corresponding to the counter; SET and RST instructions determine whether the bit accumulator is 1, and if it is 1, set the switch value pointed to by the programming element to 1 or zero, otherwise the switch value pointed to by the programming element will remain unchanged.Directives related to bit accumulator and bit data stack area are: LD, LDI, ANB, ORB, PUSH, PRD, POP, etc. Their functions are: LD and LDI directives read variables into the accumulator. If LD and LDI directives have existed before and OUT directives have not been seen, the data in the in-situ accumulator will be put into the stack, and then the variables will be read into the accumulator; ANB, ORB will read the switches in the current bit accumulator and the latest data in the stack. Logic operation, the results are stored in the bit accumulator, and the data in the stack is deleted; PUSH, PRD, POP and other instructions are to put, read and output the data in the bit accumulator respectively.The three stages are carried out in a cycle, one instruction cycle per execution, which requires the participation of a program counter.Program counter is a unit designated in the RAM of single chip computer. The value of program counter is added to 1 every cycle, so the value of program counter is the number of instructions that have been executed.
CJ and END are two instructions related to program counter. The number of operations of CJ is a set of constants, the constant value is the jump address.Once the switch value corresponding to CJ is set to 1, the constant is assigned to the program counter, and the program jumps accordingly.END can clear the program counter and make the user program execute circularly.In addition to these three processes, the user program execution program also has interrupt processing program.If the timer T is used in the user program, the timer of the single chip computer is turned on. The timer is timed in 10 ms. When the value of the register corresponding to the timer is reduced to a certain value every 10 ms, the switch value corresponding to the timer is set if it is reduced to zero.After many times of hardware system function analysis and testing and software system experiment and debugging, the final system achieves the following test results, which can be used as a basis for the selection of PLC.According to the difference of fieldbus, the communication distance and speed are shown in Table 4.The time delays of conduction, closure and disconnection are also different for different contacts, as shown in Table 5.This paper completes the test of communication distance, input/output type and transmission rate of various bus of PLC.This research takes bus architecture as the thinking, realizes the design of programmable devices by embedded technology, and forms a kind of industrial field programmable controller based on single chip computer, which can realize centralized management and decentralized control through bus expansion and running unified program. It has the advantages of flexibility, good expansibility and so on, which makes the application prospect of this kind of PLC very good.Now the hardware composition of the system and the design of the underlying control software have been successfully studied. It is necessary to further improve the design of the upper computer software [9].