This paper designs a new scheme of developing controller based on MCU to realize the separation of core driver and logic operation and control. Usually, the intelligent controller based on single-chip computer has been solidified. After the development, its function is basically finalized. It can only be applied to specific design goals. It is also very difficult to change the control scheme on site if necessary. Aiming at this short board, we design a new scheme based on MCU to develop controller, which separates the core drive from logic operation and control, and realizes logic programming with concise ladder diagram language. This scheme not only extends the application scope of the controller, but also reduces the difficulty of debugging on site, and controls the change of the scheme by modifying the ladder.
Graphic logic can be solved. MCU should have the characteristics: enough capacity of erasable flash program memory, support IAP function.
Most MCU chips now support user self-programming IAP function, such as Atmega128, STM32F3, STM32F4 series can meet the requirements. Firstly, the flash memory of MCU is divided into three parts. One part stores Boot Loader program to realize IAP function, the other part stores MCU kernel program, and the rest is used to store user program. Kernel programs are mainly hardware drivers and code interfaces and algorithms between user programs.
User program is to use ladder diagram editing tool to form sequence control logic, compare rules and data output direction. Kernel program periodically scans the internal and external device memory mapping address, and calls user area logic operation, and outputs the results to the device in the form of data and message volume, thus completing the control scheme of user logic. How to realize hardware driver and communication of MCU is beyond the scope of this topic.
This paper focuses on how to implement ladder diagram compiler software and MCU to implement ladder diagram control logic. The editing components of ladder diagram mainly include simple components such as normal open contacts, normal closed contacts, relays and other functional components such as timing and comparison. The values of Mclass are 0: DI, 1: DO, 2: timer, 3: counter (C), 4: internal relay (M), 5: data register (D), 6: message input (MI), 7: message output (MO).
The ladder diagram is drawn according to the above agreement, as shown in Figure 1. Ladder diagram language describes the energy flow of a logical network from left to right. The logical operation of elements is always “and” operation with the operation on the left side, and the branch is always “or” operation with the result on the left side. When the branch node is scanned one by one, the result of operation is first pressed into the stack.
The scan temporarily abandons the component on the right side of the branch node, and then proceeds to the next line scan, such as branch, and continue. The stack is scanned until there is no branch, the result and the stack top “or” operation are performed, the stack top node connection type is judged, and the next step is to go out of the stack or scan. If there is a right branch of the stack node, the right component is scanned, and the logical operation is performed until the end of the line flag node is scanned, and the stack top node is determined.
The result of calculation is assigned to the final node element, so the element located at the end marker must be the output element. If there is an interruption or incompleteness of the start and end signs of the energy tide during the scanning process, it is considered that the trapezoidal chart compilation failed.
Oprate corresponds to logical operations, 1 represents exclusive or, 2 represents exclusive or, 4 represents assignment, 5 represents stack, 6 represents stack update, 7 represents timer operation, 9: timer overflow processing, 10: counter operation, 11: calculator overflow processing, 12: bit operation, 13: register value comparison. Then a variable length array of Tprodata type is defined, and the results of the above ladder diagram scanning and compiling sequence are stored in the variable length array. Finally, the data is formatted in Intel Hex format to output the file and stored in the magnetic hard disk. MCU has the function of self-programming (IAP). It downloads the result file of ladder diagram compilation (Intel Hex format) to the register partition of MCU user program. Because the register partition of user program can be erased by IAP alone, so that the operation logic of controller can be modified. By modifying the ladder diagram, the control logic and the kernel program can be divided by compiling and downloading. Leave. In the MCU core program, a set of component memory mapping is defined firstly. The size of the array is the same as that of the element array in the ladder diagram, and it keeps corresponding to the element type in the ladder diagram editing tool. Here, it is defined as U16 opdate [255].
In order to deal with ladder diagram user logic, several interface functions are established in the MCU kernel program, as shown in Figure 2. The details of data processing have been clarified in the implementation of interface functions. ReadDI (), checkprodata (), OutDO () functions are executed in the MCU core loop. ReadDI () reads the logical state of the input port into the mapping area. Communication control word and message input call interrupt processing function through interrupt interface to store data into corresponding memory mapping address, check prodata () reads and processes user logic sequentially, and transmits logical operation and comparison results to corresponding output mapping memory address. OutDO () function will output the result output controller in the output mapping address. The output end of the system. The interaction mechanism between them is clearer through Figure 3.
In this paper, thermostatic element an intelligent controller based on single chip microcomputer is designed to separate the kernel program from the user control logic. The control logic is compiled and downloaded by ladder editing tool, and the change of control objective can be realized only by modifying ladder logic. This design scheme has been successfully applied to the environmental monitoring and alarm of the East Suburb and Antai Transformers of Jiangsu Yancheng Power Supply Company, and different control objectives of intelligent drainage.